Problems with Webservices in Netbeans and how to solve them

Ok, rather than give a tutorial on web services – because there are some around, I thought I would solve one of the mysterious problems that can occur when you are creating these services.

Netbeans is AMAZING at creating web services, the tools are incredibly rich.

But this error dogged me. I had one or two web services that worked and others that didn’t. To set up my service I had set up some inner classes

public static class dtaData {
private String Name;
private String date;
private String sid;
}

then created a web services that returned a LIST of those objects:-

    @WebMethod(operationName = "Data")
    public List Data() {
        List result=new ArrayList();
       for (int i=0;i<20;++i) {
        dtaData DataObject=new dtaData ();
       DataObject.sid=""+i;
       result.add(Result);
     }

        
        return result;
    }
  

And it falls over with this error when you test the webserver. HOWEVER The problem is caused because there is no web service DIRECTLY returning the dtaData class. The solution is to create a web service that returns null but has dtaData as the returning Object.

e.g.

    @WebMethod(operationName = "testData")
    public dtaData testData() {
           return null;

    }
   

These errors are given when the problem occurs:-

On the glassfish server

Caused by: javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException
 - with linked exception:
[javax.xml.bind.JAXBException: class PHJ.Agenda$ICDB_Agenda_data nor any of its super class is known to this context.]
        at com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:322)
        at com.sun.xml.ws.message.AbstractMessageImpl.writeTo(AbstractMessageImpl.java:142)
        at com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:108)
        at com.sun.xml.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.java:258)
        at com.sun.xml.ws.transport.http.HttpAdapter.encodePacket(HttpAdapter.java:320)
        at com.sun.xml.ws.transport.http.HttpAdapter.access$100(HttpAdapter.java:93)
        at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:454)

On the web service test return:


Exceptions details : java.lang.reflect.InvocationTargetException


javax.servlet.ServletException: java.lang.reflect.InvocationTargetException at com.sun.enterprise.webservice.monitoring.WebServiceTesterServlet.doPost(WebServiceTesterServlet.java:345) at com.sun.enterprise.webservice.monitoring.WebServiceTesterServlet.invoke(WebServiceTesterServlet.java:121) at com.sun.enterprise.webservice.JAXWSServlet.doPost(JAXWSServlet.java:165) at javax.servlet.http.HttpServlet.service(HttpServlet.java:738) at javax.servlet.http.HttpServlet.service(HttpServlet.java:831) at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317) at org.apache.catalina.core.Ap

Advertisements

About Paul C

I am a Senior Java programmer/Web Technologies, Play in a band called Mandolin Monday, I have a cat and I live on a boat.

Posted on October 1, 2008, in Netbeans and tagged , , , , , . Bookmark the permalink. 2 Comments.

  1. A better solution using generics:
    @WebMethod(operationName = “Data”)
    public List Data() {
    List result=new ArrayList();
    for (int i=0;i<20;++i) {
    dtaData DataObject=new dtaData ();
    DataObject.sid=””+i;
    result.add(DataObject);
    }
    Thus wsimport can generate the dtaData class.. Your workaround is a good solution when inheritance is required and parent or child classes are not explicitly returned in a webservice.

  2. Yes agreed thanks for that one Daniel.

    Incidentally this was a very interesting project, I had to get the data to Italy with specifications they wrote for their database. They had one database, I had 36.

    So everytime they requested a web service my system had to scan 36 different schemata in a SQL SERVER 2005. I used my JTDS driver and a special class to make it look to the other end that it was one database. Lucikly the Primary keys in the databases were all UUID’s so we didn’t have a problem with multple clients for instance with the same IDs.

    Paul.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: