Java EE javax.xml.bind.MarshalException

时间:2010-05-09 01:38:27

标签: web-services jsf java-ee jaxb jax-ws

我收到javax.xml.bind.MarshalException错误。我从我的Web服务发送List到支持bean,我有这个错误。

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)

这是我的代码:

支持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";
}

web服务

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;
}

2 个答案:

答案 0 :(得分:1)

我认为这个问题在某种程度上与JAX-WS and type substitution问题有关(在java.net论坛上有很多关于这个问题的帖子,例如this onethis one)。简而言之,JAXB无法封送在创建JAXBContext时未明确引用的类,这是Cantable的情况。

我不是100%确定这会解决问题,但您可以尝试在网络服务中使用参数化List而不是原始类型:

public List<Cantable> candDetails(int pollEvent) {
   ...
}

答案 1 :(得分:1)

关于Pascal的响应,对于Web服务端的类似问题,参数化列表没有解决问题,但@XmlSeeAlso注释也解决了。

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

谢谢Pascal!