Nick Russler
Nick Russler

Reputation: 4688

Weird JSF PrettyFaces Exception

Hi i get an exception from time to time (can't reproduce) and don't know what to do..

Here is the stacktrace:

java.lang.NumberFormatException.forInputString 13:46:52,015 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[atlasvirtualdomain].[/].[Faces Servlet]] (http--0.0.0.0-8040-399) Servlet.service() for servlet Faces Servlet threw exception: java.lang.NumberFormatException: For input string: "+O.undefined"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) [rt.jar:1.7.0_07]
    at java.lang.Integer.parseInt(Integer.java:492) [rt.jar:1.7.0_07]
    at java.lang.Integer.valueOf(Integer.java:582) [rt.jar:1.7.0_07]
    at javax.faces.convert.IntegerConverter.getAsObject(IntegerConverter.java:116) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
    at com.ocpsoft.pretty.faces.beans.ParameterInjector.injectPathParams(ParameterInjector.java:85) [prettyfaces-jsf2-3.3.3.jar:]
    at com.ocpsoft.pretty.faces.beans.ParameterInjector.injectParameters(ParameterInjector.java:54) [prettyfaces-jsf2-3.3.3.jar:]
    at com.ocpsoft.pretty.faces.event.PrettyPhaseListener.afterPhase(PrettyPhaseListener.java:102) [prettyfaces-jsf2-3.3.3.jar:]
    at com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:189) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:107) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at org.apache.myfaces.extensions.cdi.jsf2.impl.listener.phase.CodiLifecycleWrapper.execute(CodiLifecycleWrapper.java:95) [myfaces-extcdi-bundle-jsf20-1.0.5.jar:1.0.5]
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:82) [classes:]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at utils.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:32) [classes:]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145) [prettyfaces-jsf2-3.3.3.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at utils.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:32) [classes:]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:840) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:622) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:560) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:488) [jbossweb-7.0.13.Final.jar:]
    at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:137) [prettyfaces-jsf2-3.3.3.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at utils.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:32) [classes:]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.web.rewrite.RewriteValve.invoke(RewriteValve.java:466) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
    at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_07]

I Guess somehow prettyfaces is involved in this:

at com.ocpsoft.pretty.faces.beans.ParameterInjector.injectPathParams(ParameterInjector.java:85) [prettyfaces-jsf2-3.3.3.jar:]
at com.ocpsoft.pretty.faces.beans.ParameterInjector.injectParameters(ParameterInjector.java:54) [prettyfaces-jsf2-3.3.3.jar:]
at com.ocpsoft.pretty.faces.event.PrettyPhaseListener.afterPhase(PrettyPhaseListener.java:102) [prettyfaces-jsf2-3.3.3.jar:]

I use:

Edit:

I somehow managed to fix it (see my answer), but i dont understand how my fix works ...

Sometimes this url is called (after all cookies were deleted or never existed):

http://.../firsat/655/something/;jsessionid=uNCQNxYxmmuQak6bcfpfZTG-.undefined

Why did the jsessionid get confused with my prettytime rule ? idk ...

Upvotes: 0

Views: 793

Answers (2)

Nick Russler
Nick Russler

Reputation: 4688

The bug was to use "id" as name for a url parameter:

  <url-mapping id="articleedit2"> 
      <pattern value="/duzenle/#{id: articleEdit.article_id}/" /> 
      <view-id value="/faces/article_edit.xhtml" />
      <action>#{articleEdit.initForEdit()}</action>
  </url-mapping>

And then redirecting to id with java (Pseudocode: Redirect('something?id=123')). Somehow the jsessionid got mixed in this param then ...

The fix was to rename it to something other than id :)

edit: i got the bug again ... still don't know what triggers it

Upvotes: 0

chkal
chkal

Reputation: 5668

It will be very difficult to tell you what exactly is going wrong there, but I can help you to understand at which point in time it happens.

The PrettyFaces phase listener kicks in after the RESTORE_VIEW phase. At this stage PrettyFaces processes all query and path parameters. As the error happens during ParameterInjector.injectPathParams(), the problem is related to some path parameter.

Before the injection happens, PrettyFaces checks the type of the bean property to which the parameter is bound. PrettyFaces then checks if JSF has any converter registered for that type. According to the stacktrace the field seems to be an Integer because PrettyFaces calls the IntegerConverter. The converter is used to convert the value of the path parameter from the URL (which is a String) to the target type (which is an int).

The exception says, that the input string +O.undefined cannot be converted to an integer. So it looks like this string is part of the requested URL.

Take a look at this example. Let's assume you have a mapping like this:

<url-mapping id="userDetails">
  <pattern value="/user/#{userBean.id}" />
  <view-id value="/faces/user-details.jsf" /> 
</url-mapping>

If for some reason someone requests the URL /user/+O.undefined, you would get exactly this exception. So I think you will have to find the reason why this is happening. Perhaps you will find a clue in the access logs?!?

BTW: You can also use regular expressions to make sure a mapping is only processed if the path parameter matches a certain expression. Something like this:

<url-mapping id="userDetails">
  <pattern value="/user/#{ /[0-9]+/ userBean.id }" />
  <view-id value="/faces/user-details.jsf" /> 
</url-mapping>

See this chapter in the PrettyFaces documentation for details.

Upvotes: 3

Related Questions