users@glassfish.java.net

RESTful Web Service with Provider - Bug?

From: <marklists_at_javector.com>
Date: Wed, 05 Jul 2006 22:40:16 -0600

I'm using GlassFish b42 / SJSAS90. Am having trouble deploying a
RESTful Web Service using the Provider<Source>. I keep getting a
ClassCastException thrown by the JAXWSEndpointImpl. Here is a snip of
the stack trace from the server.log.

java.lang.ClassCastException:
com.sun.xml.ws.handler.XMLHandlerContext$SHDXMLMessageContext
        at
com.sun.enterprise.webservice.monitoring.JAXWSEndpointImpl.processRequest(JAXWSEndpointImpl.java:50)
        at
com.sun.xml.ws.protocol.xml.server.XMLMessageDispatcher.receive(XMLMessageDispatcher.java:110)
        at com.sun.xml.ws.server.Tie.handle(Tie.java:88)
        at com.sun.enterprise.webservice.JAXWSServlet.doPost(JAXWSServlet.java:191)
        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(ApplicationFilterCh


I suspect that deploying a Provider<Source> with an
HTTPBinding.HTTP_BINDING is broken. I can't find the b42 source, and
the b43 source doesn't have a class case at line 50 (but it does have
an instanceof) - so I'm stumped about what exactly is causing the
error. It seems like maybe a problem related to casting shared XML
context to SOAP vs. XML/HTTP.

Here is the WebServiceProvider. Note that there must be a
wsdlLocation and other attributes that should not be necessary (see
IssueTracker - issue #661). But, anyway it deploys.

@WebServiceProvider(serviceName="GetNewOrdersProviderPortService",

     portName="GetNewOrdersProviderPortServicePort",

     targetNamespace="http://bogus.com",

     wsdlLocation="WEB-INF/wsdl/bogus.wsdl")

     @BindingType(value=HTTPBinding.HTTP_BINDING)

     public class GetNewOrdersProvider implements Provider<Source> {



   public Source invoke(Source xml) {

     System.out.println("entered GetNewOrderProvider");

     OrderManager om = new OrderManager();

     try {

       return om.getNewOrders();

     } catch (Throwable t) {

       t.printStackTrace();

       throw new HTTPException(500);

     }

   }


Here is the client that I'm using to test the service:

public class GetNewOrdersPost {



   public static void main(String[] args) throws Exception {

     if (args.length != 1) {

       System.err.println

       ("Usage: java GetNewOrdersPost <Web Service URL>");

       System.exit(1);

     }

     QName svcQName = new QName("http://bogus.com",
"GetNewOrdersProviderPortService");

     QName portQName = new QName("http://bogus.com",
"GetNewOrdersProviderPortService");

     Service svc = Service.create(svcQName);

     svc.addPort(portQName, HTTPBinding.HTTP_BINDING, args[0]);

     Dispatch<Source> dis =

       svc.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD);

     Source result = dis.invoke(new StreamSource(new
StringReader("<bogus/>")));

     try {

       TransformerFactory.newInstance().newTransformer()

       .transform(result, new StreamResult(System.out));

     } catch (Exception e) {

       throw new IOException(e.getMessage());

     }

   }



}

I have to post some XML (<bogus/>) because HTTP GET isn't supported.
The output from the client is:

<?xml version="1.0" encoding="UTF-8"?><err>Internal Server Error</err>