Kerberos with websphere NPE - websphere

I am trying to setup Kerberos web authentication on Websphere (8.5.5). I have done my setup but when i try to access the login url i get the following NPE
com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[Initializer]: java.lang.NullPointerException
at net.sourceforge.spnego.SpnegoFilterConfig.doClientModule(SpnegoFilterConfig.java:179)
at net.sourceforge.spnego.SpnegoFilterConfig.<init>(SpnegoFilterConfig.java:138)
at net.sourceforge.spnego.SpnegoFilterConfig.getInstance(SpnegoFilterConfig.java:314)
at net.sourceforge.spnego.SpnegoHttpFilter.init(SpnegoHttpFilter.java:193)
I don't understand the error, or how to fix it.
Thanks
UPDATE
<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_1431678248278" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>warname_war</display-name>
<description>ApplicationDescription</description>
<!--Servlets-->
<servlet>
<servlet-name>Initializer</servlet-name>
<servlet-class>com.package.subpackage.Initializer</servlet-class>
<init-param>
<param-name>initFile</param-name>
<param-value>/WEB-INF/conf/init.xml</param-value>
</init-param>
<init-param>
<param-name>initModule</param-name>
<param-value>/WEB-INF/conf/init-module.xml</param-value>
</init-param>
<init-param>
<param-name>initAuthentication</param-name>
<param-value>/WEB-INF/conf/init-authentication.xml</param-value>
</init-param>
<init-param>
<param-name>WindowOnSuccessCloseTimeout</param-name>
<param-value>500</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>CreateSecurityDb</servlet-name>
<servlet-class>com.package.subpackage.CreateSecurityDatabaseServlet</servlet-class>
<init-param>
<param-name>initFile</param-name>
<param-value>/WEB-INF/conf/init.xml</param-value>
</init-param>
<init-param>
<param-name>initAuthentication</param-name>
<param-value>/WEB-INF/conf/init-authentication.xml</param-value>
</init-param>
<init-param>
<param-name>sqlScriptsFolder</param-name>
<param-value>/sql</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>Data Service</servlet-name>
<servlet-class>com.package.subpackage.web.webmethod.DataServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>Logger</servlet-name>
<servlet-class>com.package.subpackage.context.DataServletImpl</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>Status</servlet-name>
<servlet-class>com.package.subpackage.healthcheck.HealthCheckServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<!--Servlet mappings-->
<servlet-mapping>
<servlet-name>Data Service</servlet-name>
<url-pattern>/dataService/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Initializer</servlet-name>
<url-pattern>/main</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Logger</servlet-name>
<url-pattern>/logger</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Status</servlet-name>
<url-pattern>/status</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CreateSecurityDb</servlet-name>
<url-pattern>/createSecurityDatabase</url-pattern>
</servlet-mapping>
<!--Filters-->
<filter>
<filter-name>LoginFormFilter</filter-name>
<filter-class>com.package.otherpackage.authentication.UnifiedLoginFilter</filter-class>
<init-param>
<param-name>factoryName</param-name>
<param-value>SSOAuthenticator</param-value>
</init-param>
<init-param>
<param-name>servletType</param-name>
<param-value>webHtml</param-value>
</init-param>
<init-param>
<param-name>useCaching</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter>
<filter-name>LogoutFilter</filter-name>
<filter-class>com.package.otherpackage.authentication.impl.logic.filter.UnifiedLogoutFilter</filter-class>
<init-param>
<param-name>factoryName</param-name>
<param-value>SSOAuthenticator</param-value>
</init-param>
</filter>
<filter>
<filter-name>ResourceFilter</filter-name>
<filter-class>com.package.subpackage.utils.ResourceFilter</filter-class>
</filter>
<filter>
<filter-name>InitDbConFilter</filter-name>
<filter-class>com.package.subpackage.webmethod.InitDbConnectionFilter</filter-class>
</filter>
<!--Filter Mappings-->
<filter-mapping>
<filter-name>InitDbConFilter</filter-name>
<servlet-name>Initializer</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>LoginFormFilter</filter-name>
<servlet-name>Initializer</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>InitDbConFilter</filter-name>
<servlet-name>Data Service</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>LoginFormFilter</filter-name>
<servlet-name>Data Service</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>LoginFormFilter</filter-name>
<url-pattern>/index.html</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>LogoutFilter</filter-name>
<servlet-name>Initializer</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>ResourceFilter</filter-name>
<url-pattern>/plugins/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>ResourceFilter</filter-name>
<url-pattern>/lib/atf/*</url-pattern>
</filter-mapping>
<!--location to prevent users from listing some resources-->
<welcome-file-list>
<welcome-file>/main</welcome-file>
</welcome-file-list>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<listener>
<listener-class>com.package.subpackage.context.TCSessionListener</listener-class>
</listener>
<application-policy name="spnego-client">
This is my web.xml file

The reason i was getting the NPE is that by default websphere uses the wsjaas.conf file. You can change this by editing a system launch properties file /AppServer/properties/systemlaunch/base/.systemlaunch.properties.
There you have configured the java.security.auth.login.config
In the default wsjaas.conf there was a missing entry ("spnego-client") that the spnego API expects.

Related

Spring mvc sessionRegistry returns empty list of principals

In order to change the authorities for authenticated users I need to retrieve all of these users, so I used SessionRegistry as shown in this link.
But the sessionRegistry.getAllPrincipals() method returns an empty list.
The configuration of my project is as follows :
Web.xml :
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>loyfeey</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</context-param>
<!-- <context-param> <param-name>contextConfigLocation</param-name> <param-value>com.mkyong.web.config</param-value>
</context-param> -->
<listener>
<listener-class>
org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>throwExceptionIfNoHandlerFound</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<error-page>
<location>/errors</location>
</error-page>
<session-config>
<session-timeout>30</session-timeout>
<cookie-config>
<!-- if true then browser script won't be able to access the cookie -->
<http-only>false</http-only>
<!--!if true then the cookie will be sent only over HTTPS connection -->
<secure>false</secure>
</cookie-config>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
</web-app>
WebSecurityConfigurerAdapter
#Configuration
#EnableWebSecurity
#Transactional
#Service
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
#Autowired
private CompteDetailsService compteDetailsService;
#Autowired
private IMatcherService matcherDetailsService;
#Autowired
private CustomLogoutSuccessHandler logoutSuccessHandler;
#Bean
public SessionRegistry sessionRegistry() {
return new SessionRegistryImpl();
}
#Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
#Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(compteDetailsService).passwordEncoder(passwordEncoder());
}
#Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.authorizeRequests().antMatchers(/*some paths*/).permitAll();
http.authorizeRequests().antMatchers("/**").access("hasRole('ROLE_ADMIN')");
List<Matcher> matchers = matcherDetailsService.getMatchersConfig();
for (Matcher matcher : matchers) {
http.authorizeRequests()//
.antMatchers("/" + matcher.getPath())//
.hasAnyAuthority(matcher.getPermission().toString());
}
http.authorizeRequests().anyRequest().denyAll();
http.authorizeRequests().and().formLogin()
.loginProcessingUrl("/login")
.loginPage("/")
.defaultSuccessUrl("/authentification/successful")
.failureUrl("/?error=true")
.usernameParameter("login")
.passwordParameter("password");
http.authorizeRequests().and().logout()
.logoutUrl("/authentification/logout")
.logoutSuccessUrl("/");
.logoutSuccessHandler(logoutSuccessHandler);
http.authorizeRequests().and().exceptionHandling().accessDeniedPage("/authentification/accessDenied");
SessionRegistry sr = sessionRegistry();
http.sessionManagement().maximumSessions(1).sessionRegistry(sessionRegistry());
}
}
If anyone can help me find out what I'm missing
Thanks to #M. Denium for his answer, I separated spring-servlet.xml into two files : spring-context.xml and spring-servlet.xml as it is shown below :
Web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>loyfeey</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-context.xml</param-value>
</context-param>
<!-- <context-param> <param-name>contextConfigLocation</param-name> <param-value>com.mkyong.web.config</param-value>
</context-param> -->
<listener>
<listener-class>
org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<error-page>
<location>/errors</location>
</error-page>
<session-config>
<session-timeout>30</session-timeout>
<cookie-config>
<!-- if true then browser script won't be able to access the cookie -->
<http-only>false</http-only>
<!--!if true then the cookie will be sent only over HTTPS connection -->
<secure>false</secure>
</cookie-config>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
</web-app>

Primefaces Mobile p:fileupload upload method not called

I am working on a web application for mobile devices where a user can upload a file (image) on several occasions.
Since I am using the Primefaces mobile renderkit, I have to use Primefaces' simple p:fileuploadwithout ajax.
The Problem:
When I want to upload an Image I can select the file (components are rendered correctly) and then hit the "Upload" button. After I hit "Upload", the page refreshes but myBean.saveImage() is never called. myBean.fileUploadController.setFile isn't called either. I don't get any error messages in the Netbeans console and neither in Chromes JS Console.
So far I tried to use the native HTTP Servlet Upload which is supported by primefaces since version 5.0 and the old commons.fileupload way - same result.
I followed this great guide to troubleshoot p:fileuploadbut I still get the same result after doing everything suggested in the guide.
I created a fileuploadtest.xhtml page to test the upload functionality which looks like this:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:pm="http://primefaces.org/mobile">
<f:view renderKitId="PRIMEFACES_MOBILE" />
<h:head>
</h:head>
<h:body>
<pm:page>
<pm:header title="Title"></pm:header>
<pm:content>
<h:form enctype="multipart/form-data">
<p:fileUpload value="#{myBean.fileUploadController.file}" mode="simple"/>
<p:commandButton value="Upload" ajax="false" action="#{myBean.saveImage}"/>
</h:form>
</pm:content>
<pm:footer title="Footer"></pm:footer>
</pm:page>
</h:body>
</html>
Here is my bean and my FileUploadController class:
MyBean.java:
#Component
#Scope("session")
#Named
public class MyBean implements Serializable {
#Autowired(required = true)
private FileUploadController fileUploadController;
//Bunch of unrelated methods
public void saveImage() {
this.fileUploadController.upload();
//some more code after upload() is complete
}
//getters&setters
}
FileUploadController.java:
#Component
#Scope("session")
public class FileUploadController {
private UploadedFile file;
public boolean upload() {
if (file != null) {
//upload here
return true;
} else {
return false;
}
}
public UploadedFile getFile() {
return file;
}
public void setFile(UploadedFile file) {
this.file = file;
}
}
Here is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<description>Webflow Archetype</description>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/spring/applicationContext.xml,/WEB-INF/config/web-application-config.xml
</param-value>
</context-param>
<!-- Causes Facelets to refresh templates during development -->
<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>1</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.sendPoweredByHeader</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>cupertino</param-value>
</context-param>
<context-param>
<param-name>primefaces.FONT_AWESOME</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>Define partial state saving as true/false.</description>
<param-name>javax.faces.PARTIAL_STATE_SAVING_METHOD</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
<param-value>true</param-value>
</context-param>
<!-- Custom MarqueeComponent -->
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/marquee-taglib.xml</param-value>
</context-param>
<context-param>
<param-name>BootsFaces_USETHEME</param-name>
<param-value>true</param-value>
</context-param>
<filter>
<filter-name>charEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>charEncodingFilter</filter-name>
<url-pattern>/ *</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Allows Jetty to serve Faces applications -->
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/ *</url-pattern>
</filter-mapping>
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>commons</param-value>
</context-param>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<session-config>
<session-timeout>180</session-timeout>
<cookie-config>
<secure>true</secure>
</cookie-config>
</session-config>
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value/>
</init-param>
<load-on-startup>2</load-on-startup>
<multipart-config>
<max-file-size>10485760</max-file-size>
<max-request-size>20971520</max-request-size>
<file-size-threshold>5242880</file-size-threshold>
</multipart-config>
</servlet>
<!-- Map all /spring requests to the Dispatcher Servlet for handling -->
<servlet>
<servlet-name>Jersey Spring Servlet</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>at.managementpartners.icosysmobile.rest</param-value>
</init-param>
</servlet>
<!-- <servlet>
<servlet-name>GetClientHostnameServlet</servlet-name>
<servlet-class>at.managementpartners.icosysmobile.web.util.GetClientHostnameServlet</servlet-class>
</servlet> -->
<servlet>
<servlet-name>FileServlet</servlet-name>
<servlet-class>at.managementpartners.icosysmobile.web.util.FileServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/spring/ *</url-pattern>
</servlet-mapping>
<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<multipart-config>
<max-file-size>10485760</max-file-size>
<max-request-size>20971520</max-request-size>
<file-size-threshold>5242880</file-size-threshold>
</multipart-config>
</servlet>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/javax.faces.resource/ *</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/ *</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/do/ *</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<!--servlet>
<servlet-name>Primefaces Resource Servlet</servlet-name>
<servlet-class>
org.primefaces.resource.ResourceServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Primefaces Resource Servlet</servlet-name>
<url-pattern>/primefaces_resource/ *</url-pattern>
</servlet-mapping-->
<!-- Welcome files -->
<servlet-mapping>
<servlet-name>Jersey Spring Servlet</servlet-name>
<url-pattern>/rest</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Jersey Spring Servlet</servlet-name>
<url-pattern>/rest/ *</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FileServlet</servlet-name>
<url-pattern>/files/ *</url-pattern>
</servlet-mapping>
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<trim-directive-whitespaces>false</trim-directive-whitespaces>
</jsp-property-group>
</jsp-config>
</web-app>
I configured this web.xml to work with commons.fileupload and not with the HTTP Servlet native Upload functionality.
Please note that I had to seperate ´/*´ with a space (´/ *´) so that the rest of my code wouldn't get formatted as a comment. (If there is a smarter way to do this please don't hesitate to tell me)
My web application relies on the following technologies/libraries:
JSF 2.2.9
HTTP Servlet 3.0.1
Spring MVC
Spring Webflow
Primefaces 6.0 with <f:view renderKitId="PRIMEFACES_MOBILE" />
Omnifaces 1.5
Bootsfaces 0.8.1
Netbeans as IDE
For testing and debugging purposes I deploy the app to Jetty 8.1.5 via Netbeans.
However I tried deploying the app to a Tomcat server as well with the same result.
Please forgive the long post, I just wanted to include everything that seemed remotely useful. If you need anything else please let me know.
Thank you very much in advance.
EDIT:
It appears that my problem does not have anything to do directly with p:fileupload but rather with my p:commandButtons not invoking any action event at all, when I disable ajax. To test this, I added the ajax="false" attribute to one of my comandButtons on another page. As soon as I added it, my commandButton stopped working and it just refreshed the site but never handled the event specified in the action attribute. Does anyone have an idea why my commandbuttons stop working with ajax="false"?
Edit2
I posted a new question since I discovered that the problem is related to something slightly different

Javascript and css files getting 404 error on my jsp page after using #PathVariable

For some reason when I changed the mapping of my jsp in my spring controller to use a path variable none of the javascript or the css files will load. I can't find any other examples on the net of this happening. I'm guessing it's some mapping issue in my web.xml but I don' really know.
Here is my controller code..
#RequestMapping(value = "common/taskSummary/{taskInstanceId}.do", method=RequestMethod.GET)
public ModelAndView taskSummary(
#PathVariable("taskInstanceId") int taskInstanceId) {
// Get user from Spring security
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
ModelAndView modelAndView = new ModelAndView("taskSummary");
modelAndView.addObject("username", user.getUsername());
return modelAndView;
}
Here is my web.xml...
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml
/WEB-INF/spring-security.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<resource-ref>
<description>ArcFlashMap DB Connection</description>
<res-ref-name>jdbc/AFM_DB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<servlet>
<servlet-name>LoadResourcesServlet</servlet-name>
<servlet-class>ie.premiumpower.services.reports.common.LoadResourcesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.json</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
And here is the errors I'm getting on firebugs console...
Figured it out.
I had been mapping my css and js files using href="../css/style.css"
but this needed to be changed to href="../../css/style.css". Adding the extra "../".

Spring deployed war file on tomcat not displaying pages

Hi i created a maven project for spring.After i created project the final product is .war file.
Then i upload it with using tomcat manager.But i cannot access or show page...!!
it gives me following error
web.xml
<!-- Reads request input using UTF-8 encoding -->
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-context-data.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-context-web.xml,
/WEB-INF/spring-context-data.xml,
/WEB-INF/spring-security.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-context-web.xml,
/WEB-INF/spring-context-data.xml,
/WEB-INF/spring-security.xml
</param-value>
</context-param>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<!-- <servlet>
<servlet-name>RealEstate</servlet-name>
<servlet-class>com.Servlet1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RealEstate</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> -->
<!-- Handles all requests into the application -->
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-context-web.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>methodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>methodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
pom.xml
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<url>http://localhost:8080/manager/html</url>
<server>tomcat7</server>
<path>/RealEstate</path>
</configuration>
</plugin>
controller
#RequestMapping("/home")
public String getHomePage() {
return "/index";
}
You url pattern doesnt serve your home request; remove star from it like below :
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/</url-pattern>
</filter-mapping>
With this url pattern works with every url. Do it for other url patterns as well.
You should post the dispatch servlet xml configuration file (spring-context-web.xml). There you should configure the view resolver like this:
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
<property name="order" value="2" />
</bean>

Primefaces fileUpload not work, FileUploadFilter call twice

I'm doing a Web application using Spring 3.1.0.RELEASE, JSF 2.x, JPA 2 with Hibernate Provider. The application run on Tomcat 6.35.
I use PrettyFaces 3.3.2 for friendly URL and Spring security 3.1.0.RELEASE.
I use Primefaces 3.1 and I try to use the fileupload component of Primefaces. Sadly its doesn't work.
I have the good dependencies in my pom.xml
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.1</version>
</dependency><dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
</dependency>
My web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<!-- Use this definition if using a Java EE 6 container This also stops Eclipse
from complaining that 3.0 is not a valid version <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> -->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<!-- Theme pour prime -->
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>glass-x</param-value>
</context-param>
<!-- The definition of the Root Spring Container shared by all Servlets
and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/applicationContext.xml
/WEB-INF/spring/security-app-context.xml
</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEVELOPMENT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<!-- jboss-el -->
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
</context-param>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>51200</param-value>
</init-param>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>/tmp/primefacesFileupload</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<url-pattern>/*</url-pattern>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ASYNC</dispatcher>
</filter-mapping>
<!-- Filter for setting all the requests and responses to UTF-8 encoding-->
<filter>
<filter-name>spring-encoding-filter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>spring-encoding-filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Localisation -->
<filter>
<filter-name>localizationFilter</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>localizationFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Pretty faces -->
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- place constraints on a single user's ability to log in to your application -->
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/app/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/spring/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/primefaces_resource/*</url-pattern>
</servlet-mapping>
<resource-ref>
<res-ref-name>jsf/ProjectStage</res-ref-name>
<res-type>java.lang.String</res-type>
<jndi-name>javax.faces.PROJECT_STAGE</jndi-name>
</resource-ref>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
In the view I try the following:
<h:form enctype="multipart/form-data" id="testFileupload">
<pou:fieldset legend="Upload de fichiers">
<pou:messages showDetail="true"/>
<pou:fileUpload id="fileUploadInputTest" fileUploadListener="#{siteFormManager.handleFileUpload}" auto="true" dragDropSupport="false"/>
</pou:fieldset>
</h:form>
Or
<h:form enctype="multipart/form-data">
<pou:messages showDetail="true"/>
<pou:fileUpload value="#{siteFormManager.file}" mode="simple"/>
<pou:commandButton value="Submit" ajax="false" actionListener="#{siteFormManager.upload}" action="#{siteFormManager.uploadAction}"/>
</h:form>
In my bean
#Component
#Scope(value = "request")
public class SiteFormManager {
private static final Logger logger = LoggerFactory.getLogger(SiteFormManager.class);
/**
* Le file to upload
*/
private UploadedFile file;
public void handleFileUpload(FileUploadEvent event) {
final UploadedFile lfile = event.getFile();
logger.debug("SiteFormManager::handleFileUpload {} --> File equals {}", event, lfile);
}
public void handleFileUpload() {
logger.debug("SiteFormManager::handleFileUpload without params");
}
public String uploadAction() {
logger.debug("SiteFormManager::uploadAction --> File equals {}", file);
return null;
}
public UploadedFile getFile() {
return file;
}
public void setFile(UploadedFile file) {
this.file = file;
}
}
The problem is that the file in my bean is always null! I have try in Tomcat 7 and nothing change.
I have try the fileUpload component of Richfaces and it's work, but I wont include the two components libraries to avoid conflicts.
I have debug my application on Netbeans 7 and insert a breakpoint on FileUploadFilter::doFilter. I have notice that the doFilter is called twice. The first time the MultipartRequest is well created, parsing the inputs of the form and detect the file.
But the second time the request seems to be consume and nothing is fill in the MultipartRequest. The Primefaces FileUploadRenderer use the second MultipartRequest and so no file is present in that one.
Is it normal that the FileUploadFilter is called twice ? How make the fileUpload component work ?
SOLUTION
I have only change the web.xml, added the ASYNC in the prettyfaces filter and remove all the
dispatchers in fileupload filter.
The final web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Use this definition if using a Java EE 6 container This also stops Eclipse
from complaining that 3.0 is not a valid version <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> -->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<!-- Theme pour prime -->
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>glass-x</param-value>
</context-param>
<!-- The definition of the Root Spring Container shared by all Servlets
and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/applicationContext.xml
/WEB-INF/spring/security-app-context.xml
</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEVELOPMENT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<!-- jboss-el -->
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
</context-param>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>51200</param-value>
</init-param>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>/tmp/primefacesFileupload</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<url-pattern>/*</url-pattern>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<!-- Filter for setting all the requests and responses to UTF-8 encoding-->
<filter>
<filter-name>spring-encoding-filter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>spring-encoding-filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Localisation -->
<filter>
<filter-name>localizationFilter</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>localizationFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Pretty faces -->
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
<dispatcher>ASYNC</dispatcher>
</filter-mapping>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- place constraints on a single user's ability to log in to your application -->
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/app/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/spring/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/primefaces_resource/*</url-pattern>
</servlet-mapping>
<resource-ref>
<res-ref-name>jsf/ProjectStage</res-ref-name>
<res-type>java.lang.String</res-type>
<jndi-name>javax.faces.PROJECT_STAGE</jndi-name>
</resource-ref>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
Thanks you.
I believe you need to add the ASYNC dispatcher to your PrettyFaces filter mapping:
<!-- Pretty faces -->
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
<dispatcher>ASYNC</dispatcher>
</filter-mapping>
The PrimeFaces upload component uses ASYNC uploads if I am not mistaken.

Resources