Skip to main content

What I found during struggling for REST on GlassFish

Posted by iasandcb on October 10, 2006 at 9:51 PM PDT

Maybe I need to post these issues to GF or JAX-WS projects, but would like to share first with this blog.

I simply wanted to demonstrate a service exposed as both SOAP and REST.

1. Firstly, I started with GlassFish V2 M2 with JAX-WS 2.1M1. I declared a service with @WebServiceProvider as a servlet (and a servlet mappping for that as well), and unfortunately GF recognized it as a plain servlet, so any request toward the service failed. A possible workaround is using a JAX-WS descriptor (sun-jaxws.xml) in order for GlassFish to detect the service. In my opinion, this issue should be fixed.

2. Once I worked around issue #1, I viewed the admin console page and there was no entry in "Web Services" category.

3. When I browsed my web application on the admin console, "General" tab showed me a servlet that I didn't register on web.xml. Intererestingly, the name of the servlet is exactly the same as the fully qualifed class name of the @WebServiceProvider service.

4. I tried to test "restful" sample in JAX-WS 2.1, and (unfortunately again) failed to execute "ant run", which actually ran a client for a RESTful service via Dispatch. The client-side error message is:

run:
[java] Invoking Restful GET Request with query string ?num1=30&num2=20
[java] Exception in thread "main" java.lang.NullPointerException
[java] at com.sun.xml.ws.client.dispatch.SourceDispatch.toReturnValue(SourceDispatch.java:67)
[java] at com.sun.xml.ws.client.dispatch.SourceDispatch.toReturnValue(SourceDispatch.java:54)
[java] at com.sun.xml.ws.client.dispatch.DispatchImpl.doInvoke(DispatchImpl.java:180)
[java] at com.sun.xml.ws.client.dispatch.DispatchImpl.invoke(DispatchImpl.java:184)
[java] at restful.client.DispatchAddNumbersClient.main(Unknown Source)
[java] Java Result: 1

On the other hand, the server-side error is:
Query String = null
PathInfo = null
javax.xml.ws.http.HTTPException
at restful.server.AddNumbersImpl.invoke(Unknown Source)
at restful.server.AddNumbersImpl.invoke(Unknown Source)
at com.sun.xml.ws.api.server.InstanceResolver$1.invokeProvider(InstanceResolver.java:132)
at com.sun.xml.ws.server.provider.ProviderInvokerPipe.process(ProviderInvokerPipe.java:62)
at com.sun.xml.ws.server.WSEndpointImpl$1.process(WSEndpointImpl.java:156)
at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:156)
at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:238)
at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:97)
at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:161)
at com.sun.xml.ws.transport.http.servlet.WSServlet.doPost(WSServlet.java:49)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:278)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:556)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:246)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:185)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586)
at com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:556)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:619)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.processNonBlocked(DefaultProcessorTask.java:550)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:780)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:326)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:251)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:205)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
at com.sun.enterprise.web.connector.grizzly.WorkerThreadImpl.run(WorkerThreadImpl.java:103)

"ant run-url" worked fine. Just out of curiousity, I opened the same URLs on a firefox web browser as "run-url" client called but met the following server-side error:

The log message is null.
java.lang.NullPointerException
at com.sun.xml.ws.encoding.XMLHTTPBindingCodec.compareStrings(XMLHTTPBindingCodec.java:227)
at com.sun.xml.ws.encoding.XMLHTTPBindingCodec.isMultipartRelated(XMLHTTPBindingCodec.java:210)
at com.sun.xml.ws.encoding.XMLHTTPBindingCodec.decode(XMLHTTPBindingCodec.java:180)
at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:154)
at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:238)
at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:97)
at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:124)
at com.sun.xml.ws.transport.http.servlet.WSServlet.doGet(WSServlet.java:56)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:278)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:556)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:246)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:185)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586)
at com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:586)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:556)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:619)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.processNonBlocked(DefaultProcessorTask.java:550)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:780)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:326)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:251)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:205)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
at com.sun.enterprise.web.connector.grizzly.WorkerThreadImpl.run(WorkerThreadImpl.java:103)

It seems that when you request through a browser, Content-Type request header is not set. Probably JAX-WS should check out first whether the header string is not null. This problem is not shown in JAX-WS 2.0.1, which is built in GF V2 M1.

OK, nothing is perfect, so I'm looking forward to any progress for that :-)