Web Flow view resolver problems - spring-webflow

I have a sample application with web flows in a number of jars (extensions) and the configuration is loaded from the classpath this works fine. But I'm struggling with the view resolver configuration that will load the JSP's from the same location as the flow definitions on the classpath?
so I have the following folder structure on the classpath
MEAT-INF/config-webflow/ext1/ flow definition and JSP's for flow extension 1 are here
The web flow configuration works fine as I set this as flow-builder-services="flowBuilderServices" base-path="classpath*:/META-INF/config-webflow">
But as yet I can not come up with a view resolver configuration to load the JSP's
Any ideas?

I had the same problem. I discovered that you get the desired behaviour by NOT setting the normal Spring MVC 'viewResolver' bean on the MvcViewFactoryCreator.
<flow-builder-services id="flowBuilderServices" view-factory-creator="viewFactoryCreator" development="true" />
<beans:bean id="viewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator" />

Related

Spring Security Oauth2 XML Configuration in Detail

I want to use the xml configuration file for registering clients for OAUTH2 in my web application. I know that there exist support for xml tags using the client-registrations tag
However I want to register the client registration repository as a bean. So that it is extensible, something like this:
<beans:bean id="clientRegistrationRepository" class="org.springframework.security.oauth2.client.registration.ClientRegistrationRepository">
<beans:constructor-arg index="0" ref="clientRegistration"/>
</beans:bean>
... more tags expanding clientRegistration
However this does not work. Does any one know how we can do this ?

Spring mvc resources not loading on first run

I m developing a spring web application .
I have put all my resources folder in webcontent folder and configured it in my dispatcher.xml
<mvc:resources location="/asset/" mapping="/asset/**" />
I have configured my startup page as following
<mvc:view-controller path="/" view-name="Framework/start"/>
My application is running fine and all the resources are also loading but not on the first run. Means when I deploy my application on tomcat7 and hit the url for the first time the css are not loaded also my href which is mapped to a controller is also not working but once I am logged in and logout everything works fine.
After lots of effort i concluded that the problem was not with the resource path but the problem was due to the interceptor . The authentication interceptor that i have added was called multiple times due to the request to the resources and as there was no session created till that time it was returning false.
Hence i exclude any calls to resources folder from the interceptor in the following way-
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**"/>
<mvc:exclude-mapping path="/asset/**"/>
<bean class="com.model.AuthenticationInterceptor" />
</mvc:interceptor>
</mvc:interceptors>
Also one imp thing mvc:exclude-mapping is added from spring 3.2 onwards so one need add the schema "http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"

Deactivate Jetty's default 404 error handler

I want to provide a custom 404 error page in my Spring 3.1 web application, but I cannot deactivate Jetty 8's default 404 error page.
Jetty 8, out of the box, provides a default 404 error page:
when visiting a Jetty-hosted website, and providing a URL path that is not handled by any servlet (e.g. by visiting http://www.example.com/nonexisting ), Jetty responses with its own default HTML error page:
HTTP ERROR 404
Problem accessing /nonexisting. Reason:
Not Found
Powered by Jetty://
To replace this default behavior,
I've removed the DefaultHandler from my Jetty XML file,
I've edited my web.xml to include both Servlet 2.5 and Servlet 3.0 error handler locations pointing to /error,
I've set up a dedicated #Controller for handling the request to /error,
but my website still returns Jetty's own default HTML error page.
Jetty 8's official documentation talks about setting up a "custom error pages", but the suggestions there say
to configure a custom Jetty error handler (I don't want to do this, I want to do it inside my own Spring #Controller as mentioned above)
to create a "catch all context and create a "root" web app mapped to the / URI." (I don't want to do this as inside my web.xml I have already mapped Spring MVC's DispatcherServlet to /.
How can I turn off Jetty's default error handler and have the error handling be done as pointed out above?
The solution to my problem was to add a custom org.eclipse.jetty.server.handler.ErrorHandler.
If a user doesn't explicitly specify some ErrorHandler, the Jetty server instance seems to register a default ErrorHandler.
As outlined on https://www.eclipse.org/jetty/documentation/jetty-9/index.html#custom-error-pages, to register a custom ErrorHandler, you can follow the following steps.
Implement some org.eclipse.jetty.server.handler.ErrorHandler subclass, e.g. com.example.CustomErrorHandler.
Make this subclass available to your Eclipse server instance, e.g. by bundling CustomErrorHandler in a jar file and then copying that jar file into the ${jetty.base}/lib/ext directory.
Configure your Jetty server instance to have this custom ErrorHandler registered as a bean:
file jetty.xml:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
"http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- more configuration -->
<Call name="addBean">
<Arg>
<New class="com.example.CustomErrorHandler">
<Set name="server"><Ref refid="Server" /></Set>
</New>
</Arg>
</Call>
</Configure>
Here's how to define custom error pages -
http://wiki.eclipse.org/Jetty/Howto/Custom_Error_Pages

make .html default view spring mvc

Have a sample app and created a
view/HelloWorld.html
page. From my controller, I return the following
public String home(Locale locale, Model model) {
return "HelloWorld";
}
In debug mode I get this warning/error:
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/HelloWorld/WEB-INF/views/HelloWorld.html] in DispatcherServlet with name 'appServlet'
contents of my src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC #Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by #Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".html" />
</beans:bean>
If I rename the .html to .jsp and change above to .jsp then things work fine.
The flow that the servlet container goes through for this request is the following:
First the DispatcherServlet is invoked by the Servlet Container.
The DispatcherServlet finds a mapping which maps to the home method of your Controller and the home method returns a view name "HelloWorld"
Now the DispatcherServlet uses a View Resolver (your InternalResourceViewResolver) to find the View to render the model through, since the name is "HelloWorld", this maps to the /WEB-INF/view/HelloWorld.html view.
Now essentially a call is made to RequestDispatcher.forward("/WEB-INF/views/HelloWorld.html",....
The Servlet container at this point tries to find the servlet which can handle /WEB-INF/views/HellowWorld.html uri - if it had been a .jsp there is a JSPServlet registered which can handle rendering the jsp, however for *.html there is no servlet registered, so the call ends up with the "default servlet", which is registered with a servlet-mapping of / which probably your DispatcherServlet is.
Now the Dispatcher servlet does not find a controller to handle request for /WEB-INF/views/HelloWorld.html and hence the message that you are seeing
If you want this kind of a extension to be handled by the servlet container, say tomcat, you can register *.html extension to be handled by JSPServlet and then it should work cleanly. Or return forward:/resources/HelloWorld.html which will be considered a static file relative to your resources folder.
There's a lot of difference between html and jsp. Java server pages are compiled into Java ‘servlets’. It may call beans and enterprise beans, such as Java Beans components and Enterprise Java Beans components, to execute processing on the server. So, having such JSP technology could be a key component in high-level architecture for web-based applications.

Access JAX-RS using Flex

I have a JAX-RS (Rest) web service, that only enables access through SSL.
If I try to acces it though IE feeding the according parameters, I get the correct response.
Now using Flex's HTTPService component like this:
<s:HTTPService id="httpsService"
url="https://myIp:myHTTPSPort/JAXRS/jaxrs/GetText"
resultFormat="text"
result="httpsService_resultHandler(event)"
fault="httpsService_faultHandler(event)">
<s:request>
<text>My Text</text>
</s:request>
</s:HTTPService>
The fault event is started with the "HTTP request error" faultstring.
I already added this crossdomain file to the WEB-INF folder of the web service project:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="flexApplicationIp" secure="true"/>
</cross-domain-policy>
...but as you might have guessed didn't work.
I have a self generated HTTPS certificate on the host of my web service, so I dont'k know if I need to add it on Flex somewhere.
Any ideas?
at least, crossdomain.xml should be placed in root of your war file, because it has to be accessible by flash plugin. according to specification, contents of WEB-INF is NOT directly accessible by clients.
Just added the certificate following the steps mentioned here and voilá... Got it working

Resources