Java spring webflow. Tomcat can't find view file - java

I have big problem. When i do apply to web flow by id, it goes into it but later view state returns 404 Error. Flow xml file is in jar. Jar file is loaded on execution, but i cant understand why cannot find path to view file.

If tomcat cannot find a view file the view is not there. So, check where is it. Take a look on error message. It will help. And fix you project structure. This behavior can be controlled by InternalResourceViewResolver. Here is the configuration fragment I took from application I am working on.
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>

Related

Spring MVC can't find jspx-files in WEB-INF folder after jetty upgrade

I'm using Jetty for development testing of my applications, through an embedded jetty-starter which is run in IntelliJ IDEA. I would like to upgrade from 8.0.4.v20111024 to 9.4.0.v20161208, but I'm having some trouble with my jspx files. I also updated jsp and jstl dependencies.
As per the standard Spring MVC way of doing things, my jspx files are kept in the src\main\webapp\WEB-INF folder.
After the upgrade, the files from this folder can't be found, trying to access them leads to a 404.
I have an index.jspx in my src\main\webapp folder, and this is accessed just fine. When trying to access a jspx within the WEB-INF folder, it gives a 404, and then fails to find my 404.jspx, also located in the WEB-INF-folder, and defined as an error-page in web.xml. When I move 404.jspx to the webapp-folder, and change error-page mapping to
<error-page>
<error-code>404</error-code>
<location>/jspx/404.jspx</location>
</error-page>
it works. Similarly, if my controller is set up to return a jspx in the WEB-INF-folder, it fails, but if I change my setup to
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/jspx/" />
<property name="suffix" value=".jspx" />
</bean>
by removing WEB-INF/from the prefix and move my jspx, it works.
I'm not really sure where to start looking, whether the problem is Jetty, Spring MVC or jsp/jstl. Any suggestions?
Turned out to only occur with symlinked files.
The way of allowing symbolic links/aliases was changed, from
context.getInitParams().put("org.eclipse.jetty.servlet.Default.aliases", "true");
to
context.addAliasCheck(new AllowSymLinkAliasChecker());
Where context is a WebAppContext.

How to externalize properties file for web application(war)?

I have developed a webapplication which is having jsp and java code. Right now I have placed all the key-value into a env/lifecycle specific properties file (like conf-dev.properties,conf-stg.properties,conf-prod.properties).
I want to externalize these properties file so that it can be placed outside of war(without effecting the war).
right now war file is tightly coupled with properties file. if i have to modify any thing i have to build and make war and deploy.
I have very limited access on deployment server machine (only have access for one folder where i can put my configuration files) & deployment process is handled by CI(jenkin & automated script).
I explored on internet and came to know that we can achieve this using spring, would like to know what is the best way to achieve this?
As you are using Spring I suppose you already use PropertyPlaceholderConfigurer. If not you should ;)
The location of a property file can be anything that can be resolved as spring Resource. This includes classpath, servletcontext and also file references as URIs (file:///... For absolute paths)
https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.html
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="${config.file.location}" />
</bean>
If I understand your question, then you can use Class.getResourceAsStream(String) the linked Javadoc says (in part)
This method delegates to this object's class loader. If this object was loaded by the bootstrap class loader, the method delegates to ClassLoader.getSystemResourceAsStream(java.lang.String).
The better way to externalize env specific properties is to use "user.home" or "user.dir".
Thanks #Martin F..
Resolved:This is the final one i used and its working fine in dev,stage Env.
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="false"/>
<property name="order" value="1"/>
<property name="locations">
<list>
<value>classpath:conf-${cisco.life}.properties</value>
<value>file:///${openshift.home}/data/conf-${cisco.life}.properties</value>
<value>file:${openshift.home}/data/conf-${cisco.life}.properties</value>
</list>
</property>
</bean>.
and i used script action hook in openshift to set the lifecycle on system level.
appname=echo $OPENSHIFT_APP_NAME
case "$appname" in
*dev)export JAVA_OPTS_EXT="${JAVA_OPTS_EXT} -Dcisco.life=dev";
echo "setting up env life dev for " $appname
;;
*stage)export JAVA_OPTS_EXT="${JAVA_OPTS_EXT} -Dcisco.life=stg;
echo "setting up env life as stg for " $appname.

Spring MVC - Localisation - javax.servlet.jsp.JspTagException: No message found under code 'welcome_page.title' for locale 'en'

I did scan through similar posts of properties file not being found and Spring MVC throwing the below error.
javax.servlet.jsp.JspTagException: No message found under code 'welcome_page.title' for locale 'en'.
Below is the ResourceBundle definition. Earlier, I had just used classpath:messages, but based on comments here, I changed it to WEB-INF/classes/messages
<beans:bean id="localisedMessages"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<beans:property name="basename" value="WEB-INF/classes/messages" />
<beans:property name="defaultEncoding" value="UTF-8"/>
</beans:bean>
I double checked and found out that in the WAR file (which is made by STC) the property files messages.properties and messages_ml.properties file are present in WEB-INF/classes folder.
What more needs to be done here? I have put debug statements in the controller class which gets called, and the debug statements are visible. So looks like the controller is also getting invoked.

Spring Integration get FTP files recursively with outbound-gateway

I'm trying to get all files within a directory structure of 3 levels deep.
For example:
- the image a.jpg exists in a folder /images/12/34/
- the image b.jpg exists in a folder /images/56/78
I've tried the outbound-gateway like stated in :
https://github.com/spring-projects/spring-integration-samples/blob/master/basic/ftp/src/test/resources/META-INF/spring/integration/FtpOutboundGatewaySample-context.xml and http://forum.spring.io/forum/spring-projects/integration/104612-inbound-ftp-polling-sub-directories?p=604430#post604430
My configuration :
<bean id="ftpSessionFactory"
class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
<property name="host" value="127.0.0.1"/>
<property name="port" value="21"/>
<property name="username" value="Administrator"/>
<property name="password" value="SgtSpeedy1"/>
<property name="fileType" value="2"/>
<property name="clientMode" value="2" />
</bean>
<int-ftp:outbound-gateway id="gatewayLS"
cache-sessions="false"
session-factory="ftpSessionFactory"
request-channel="inbound"
command="ls"
command-options=""
expression="'/images/*/*'"
reply-channel="toSplitter"/>
<int:channel id="toSplitter" />
<int-stream:stdout-channel-adapter channel="toSplitter" append-newline="true"/>
I've omitted the splitter and just print everything out for testing purposes.
When testing, I do not get any file.
I've tried setting the folder to /images/* and then it returns all images under the 'images' folder but not recursively as stated in the links provided. So folders /12/34 and /56/78 aren't taken into account.
I cannot see what I'm missing. Can anyone help?
P.S. I'm working on Spring Integration 2.2.6 without the option to upgrade to 4.0.2 (newest), because I'm using a framework. Otherwise I'd use the -R option for the gateway!
I just tested with foo/foo/bar/qux.txt and foo/foo/baz/fiz.txt with
<int-ftp:outbound-gateway id="gatewayLS"
session-factory="ftpSessionFactory"
request-channel="inbound"
command="ls"
command-options="-1"
expression="'foo/*/*'"
reply-channel="toSplitter"/>
and it worked fine; as expected...
11:34:55.983 DEBUG [main] ...[Payload ArrayList content=[fiz.txt, qux.txt]]...
(I added the -1 option to just get the filename).
This was using linux ftpd on the server side.
Are you sure the files are in /images and not images? (Or is the user chrooted so / is his home)?

Apache Tiles + White spaces in folder path

I'm currently working on a project involving Apache Tiles, but ran into the following problem. The project folder has (a or multiple) white space(s) in the path name.
C:\Users\MyUsername\Documents\Dropbox\Subfolder\My Projects\GymApp
Now, to my surprise, when I use Apache Tiles it tries to load the tile-definition.xml from the following location:
C:\Users\MyUsername\Documents\Dropbox\Subfolder\My%20Projects\GymApp\src\main\webapp\WEB-INF\configurations\tile-definition.xml
So the problem lies in the part where tool X tries to convert all white spaces to %20 (URL encoding), where tool X being: Windows, Java, Tomcat, Spring or Apache Tiles. Because of this Apache Tiles cannot load the file, since the file does not exist (if I try to open the URL in Windows explorer it gives me the error that the file does not exist, same thing shows up in the console log of my IDE).
As for my question, is it possible to have an Apache Tiles project running in a folder which contains white spaces? If so, how is this done?
Note*: If I change the folder name of My Projects to My_Projects the project runs without any errors, so I know that the folder path is at fault here.
-- Edit --
I use this code to configure the tilesConfigurer
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView" />
</bean>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions" value="/WEB-INF/configurations/tiles.xml" />
</bean>
-- Edit 2 --
This is what my IDE log shows:
DEBUG BaseLocaleUrlDefinitionDAO:154 - File Resource file:/C:/Users/MyUsername/Documents/Dropbox/Subfolder/My%20Projects/GymApp/src/main/webapp/WEB-INF/configurations/tiles.xml at file:/C:/Users/MyUsername/Documents/Dropbox/Subfolder/My%20Projects/GymApp/src/main/webapp/WEB-INF/configurations/tiles.xml not found, continue
DEBUG BaseLocaleUrlDefinitionDAO:154 - File Resource file:/C:/Users/MyUsername/Documents/Dropbox/Subfolder/My%20Projects/GymApp/src/main/webapp/WEB-INF/configurations/tiles_en.xml at file:/C:/Users/MyUsername/Documents/Dropbox/Subfolder/My%20Projects/GymApp/src/main/webapp/WEB-INF/configurations/tiles_en.xml not found, continue
DEBUG TestDispatcherServlet:938 - Could not complete request
javax.servlet.ServletException: Could not resolve view with name 'home' in servlet with name ''
Do you use context-relative paths when specifying your tilesConfigurer bean? Because if you do that, it shouldn't matter if your project folder contains spaces.
I have the following code in my dispatcher-servlet.xml:
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView" />
</bean>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles/config/template-definitions.xml</value>
<value>/WEB-INF/tiles/config/page-definitions.xml</value>
</list>
</property>
</bean>
...and even if my project folder contains a space, Tiles still finds the definition-xml.
I know that this is an old thread but it wasn't marked as solved and I had a similar problem and maybe this will help other people.
With the Tomcat parallel deploy when you add ##2 to specify the war version, that will be expanded into a folder with the same(including the # chars) and those are escaped to %23 which had the same result - tiles.xml couldn't be loaded.
To solve this I override the URLApplicationResource class, and in both constructors instead of
file = new File(url.getPath());
I used
file = new File(url.toURI());

Categories

Resources