1

I am getting javax.xml.bind.MarshalException error. I am sending List from my webservice to the backingbean and I have this error.

WARNING: invocation error on ejb endpoint Login_webservice at /Login_webserviceService/Login_webservice : javax.xml.bind.MarshalException
 - with linked exception:
[javax.xml.bind.JAXBException: class JPA.Cantable nor any of its super class is known to this context.]
javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException
 - with linked exception:
[javax.xml.bind.JAXBException: class JPA.Cantable nor any of its super class is known to this context.]
        at com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:325)
        at com.sun.xml.ws.message.AbstractMessageImpl.writeTo(AbstractMessageImpl.java:142)
        at com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:109)
        at com.sun.xml.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.java:278)
        at com.sun.xml.ws.transport.http.HttpAdapter.encodePacket(HttpAdapter.java:380)
        at com.sun.xml.ws.transport.http.HttpAdapter.access$100(HttpAdapter.java:92)
        at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:525)
        at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:285)
        at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:143)
        at org.glassfish.webservices.Ejb3MessageDispatcher.handlePost(Ejb3MessageDispatcher.java:116)
        at org.glassfish.webservices.Ejb3MessageDispatcher.invoke(Ejb3MessageDispatcher.java:87)
        at org.glassfish.webservices.EjbWebServiceServlet.dispatchToEjbEndpoint(EjbWebServiceServlet.java:196)
        at org.glassfish.webservices.EjbWebServiceServlet.service(EjbWebServiceServlet.java:127)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

Here is my code:

Backing bean

@WebServiceRef(wsdlLocation = "http://localhost:26565/Login_webserviceService/Login_webservice?WSDL")
public String login() {
    System.out.println("Login Phase entered");
    int result = 0;
    List list;
    List finalList = null;
    try {
        Weblogin.LoginWebserviceService service = new Weblogin.LoginWebserviceService();
        Weblogin.LoginWebservice port = service.getLoginWebservicePort();
        result = port.login(voterID, password);
        Weblogin.LoginWebservice port1 = service.getLoginWebservicePort();
        list = port1.candDetails(1);
        finalList = list;
        this.setList(finalList);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (result == 1)
        return "polling";
    else
        return "login";
}

Webservice

public List candDetails(int pollEvent) {
    List resultList = null;
    List finalList = null;
    try {
        if (pollEvent == 1) {
            resultList = em.createNamedQuery("Cantable.findAll").getResultList();
            finalList = resultList;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return resultList;
}
1
  • Please update your question to include the entire stacktrace (formatted!!). Check the right column box for formatting rules. Just select code block and then press 010101 button in toolbar or Ctrl+K key. Commented May 9, 2010 at 1:52

2 Answers 2

1

I think that the issue is somehow related to the JAX-WS and type substitution problem (there are plenty of thread about this problem on the java.net forums e.g. this one or this one). In a nutshell, JAXB is not able to marshal classes that are not referenced explicitly when the JAXBContext is created, which is the case for Cantable here.

I'm not 100% sure this will solve the problem but could you try to use a parametrized List instead of a raw type in your webservice:

public List<Cantable> candDetails(int pollEvent) {
   ...
}
Sign up to request clarification or add additional context in comments.

Comments

1

Following up on Pascal's response, for a similar issue on the web service side, the parameterized list did not solve the problem but the @XmlSeeAlso annotation did.

@XmlSeeAlso({Cantable.class,Zot.class})
@WebService()
@Stateless()
public class Login {

Thanks Pascal!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.