5 Replies Latest reply on May 16, 2013 2:44 PM by Sean Murphy

    JaxRS Exception. Null URI Fragment.

    Jerson Viveros Newbie

      I have a problem. I'm trying to implement a REST full webservice with jersey:

       

           @POST

          @Consumes({"application/xml", "application/json"})

          public Response createCustomer(Customer customer) {

              Response respuesta;

              try {

                  long customerId = persist(customer);

                  URI uri = URI.create("/" + customerId);

                  Response.ResponseBuilder builder = Response.created(uri);

                  respuesta = builder.build();

              } catch (Exception e) {

                e.printStackTrace();

                throw new WebApplicationException(e,

                        Response.Status.INTERNAL_SERVER_ERROR);

              }

             

              System.out.println("Respuesta status: "+respuesta.getStatus());

              URI locationUri = (URI)respuesta.getMetadata().getFirst(HttpHeaders.LOCATION);

              System.out.println("Respuesta fragment: "+locationUri.getRawFragment());

       

              return respuesta;

       

          }

       

      When I invoke the method throught a client, the service execute without any problem the method and the customer is persist, the response generate is OK with status 201. But after return  throw an Exception and the response I got in my client is status 500.

      I think that problem can be that fragment of the URI is null and for that reason throw a NullPointerException. What can i do?

       

      13:06:03,973 SEVERE [com.sun.jersey.server.impl.application.WebApplicationImpl] (http--127.0.0.1-8080-1) The RuntimeException could not be mapped to a response, re-throwing to the HTTP container: java.lang.NullPointerException

                at org.jboss.resteasy.util.PathHelper.replaceEnclosedCurlyBraces(PathHelper.java:53)

                at org.jboss.resteasy.util.Encode.savePathParams(Encode.java:277)

                at org.jboss.resteasy.util.Encode.encodeValue(Encode.java:303)

                at org.jboss.resteasy.util.Encode.encodeFragment(Encode.java:182)

                at org.jboss.resteasy.specimpl.UriBuilderImpl.fragment(UriBuilderImpl.java:329)

                at com.sun.jersey.spi.container.ContainerResponse.setHeaders(ContainerResponse.java:646) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.spi.container.ContainerResponse.setResponse(ContainerResponse.java:542) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:207) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699) [jersey-server-1.8.jar:1.8]

                at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.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.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.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.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_15]

       

       

      13:06:03,984 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/JaxRSE2].[ServletAdaptor]] (http--127.0.0.1-8080-1) Servlet.service() para servlet ServletAdaptor lanzó excepción: java.lang.NullPointerException

                at org.jboss.resteasy.util.PathHelper.replaceEnclosedCurlyBraces(PathHelper.java:53)

                at org.jboss.resteasy.util.Encode.savePathParams(Encode.java:277)

                at org.jboss.resteasy.util.Encode.encodeValue(Encode.java:303)

                at org.jboss.resteasy.util.Encode.encodeFragment(Encode.java:182)

                at org.jboss.resteasy.specimpl.UriBuilderImpl.fragment(UriBuilderImpl.java:329)

                at com.sun.jersey.spi.container.ContainerResponse.setHeaders(ContainerResponse.java:646) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.spi.container.ContainerResponse.setResponse(ContainerResponse.java:542) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:207) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) [jersey-server-1.8.jar:1.8]

                at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699) [jersey-server-1.8.jar:1.8]

                at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.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.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.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.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_15]

       

       

      Investigating i get to know taht the problem is that the response