ezy
ezy

Reputation: 59

Jersey Service + PrettyFaces conflicting

My application has a RESTFul web service running

<servlet>
    <servlet-name>jersey-servlet</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>org.okkam.sameauthor.api</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>jersey-servlet</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

Also PrettyFaces does some URL rewriting, with the following rules (from pretty-config.xml config file)

<url-mapping id="home">
    <pattern value="/" />
    <view-id value="/index.xhtml" />
</url-mapping>

<url-mapping id="demo">
    <pattern value="/demo" />
    <view-id value="/demo.xhtml" />
</url-mapping>

<url-mapping id="notfound">
    <pattern value="/notfound" />
    <view-id value="/notfound.xhtml" />
</url-mapping>

<url-mapping id="stop">
    <pattern value="/stop" />
    <view-id value="/stop.xhtml" />
</url-mapping>

Notice that the rules are not applied to the /rest/ path, however this isn't working. When reaching from my browser the rest path the following exception is thrown:

    SEVERE: Servlet.service() for servlet [jersey-servlet] in context with path [/sameauthor] threw exception [Servlet execution threw an exception] with root cause
java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
  at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119)
   at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:662)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
   at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
   at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:205)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
   at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
   at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
   at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
   at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
   at java.lang.Thread.run(Thread.java:745)

Reading the exception I guess the filter is applied also to all the other paths, and Jersey seems to dislike it. How should I solve this conflict?

Upvotes: 1

Views: 1104

Answers (1)

chkal
chkal

Reputation: 5668

If you have a closer look at the exception you will see this:

java.lang.AbstractMethodError:
 javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;

This looks like a classpath issue. Possible reasons are:

  • You have the JAX-RS API in you WAR and are deploying it to an Java EE server. You should remove the API from your WAR or change the scope to provided.
  • You have multiple versions of the JAX-RS API on your classpath and are deploying to a plain servlet container like Tomcat or Jetty.

I hope this helps.

Upvotes: 3

Related Questions