Page 1 of 1

REST API NPE error

Posted: Wed Dec 10, 2014 12:07 pm
by peternorrhall
Hi,

I am trying to enable the REST Api by adding the generated
/WEB-INF/applicationContext-rest-api.xml
above
/WEB-INF/applicationContext-security.xml
in web.xml where the RESTApiServlet is declared by default

<servlet>
<servlet-name>RESTApiServlet</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>org.codehaus.jackson.jaxrs</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>RESTApiServlet</servlet-name>
<url-pattern>/api/v1/*</url-pattern>
</servlet-mapping>

When I try to call /api/v1/catalog/search/products?q=sauce for example I get HTTP 500 and the following stack trace

java.lang.NullPointerException
at com.sun.jersey.spi.container.ContainerRequest.&lt;init>(ContainerRequest.java:188)
at com.sun.jersey.spi.container.servlet.WebComponent.createRequest(WebComponent.java:446)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:380)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:643)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1331)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.broadleafcommerce.core.web.order.security.CartStateFilter.doFilter(CartStateFilter.java:86)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
...

I am using 3.1.8-GA

What have I missed?

Best regards,
Peter

Re: REST API NPE error

Posted: Thu Dec 11, 2014 12:01 am
by phillipuniverse
What about on other API methods? Same result or this happens just on that one?

Re: REST API NPE error

Posted: Thu Dec 11, 2014 10:31 am
by peternorrhall
Hi,
and thanks for trying to help me.

I managed to solve it myself and it was a dependency clash error.

I found out that the first time after startup I had a different stacktrace where I got

java.lang.NoSuchMethodError: com.sun.jersey.core.reflection.ReflectionHelper.getOsgiRegistryInstance()Lcom/sun/jersey/core/osgi/OsgiRegistry;
at com.sun.jersey.spi.scanning.AnnotationScannerListener$AnnotatedClassVisitor.getClassForName(AnnotationScannerListener.java:217)
at com.sun.jersey.spi.scanning.AnnotationScannerListener$AnnotatedClassVisitor.visitEnd(AnnotationScannerListener.java:186)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
...

The reason I got that is that have a dependency to jersey-client 1.8 in the customization I have made to the site project. jersey-client 1.8 uses jersey-core 1.8 for the default profile while the Demo (and Broadleaf I guess) uses 1.17.1 of jersey-core.
So, I excplicitely set a dependency to jersey-core 1.17.1 in the site/pom.xml and now it works like a charm.

I really like how well the demo is packaged and described and Broadleaf in general. Well done! I hope I can contribute to the project.

Thanks
/Peter

Re: REST API NPE error

Posted: Fri Dec 12, 2014 3:34 pm
by bpolster
You just did!

Thanks for reporting back on what you found and how you worked around it.