web-dev-qa-db-fra.com

Aucune de ses super classes n'est connue dans ce contexte

J'essaie d'envoyer une entité au service Web basé sur ejb. Voici mon code client de service Web:

package ejbserviceclient;

import Java.net.MalformedURLException;
import Java.net.URL;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;

public class EjbServiceClient {

  public static void main(String[] args) throws MalformedURLException, JAXBException {

    JAXBContext context = JAXBContext.newInstance(EjbServiceClient.class);


    URL url = new URL("http://ipsedin:8080/WebServiceBeanService/WebServiceBean?wsdl");
    QName serviceName = new QName(
            "http://ejb.rpt.softcomputer.com/",
            "WebServiceBeanService");
    QName portName = new QName(
            "http://ejb.rpt.softcomputer.com/",
            "WebServiceBeanPort");

    Service service = Service.create(url, serviceName);
    Echo ejbService = service.getPort(portName, Echo.class);

    System.out.println(ejbService.echo("lololo"));
    System.out.println(ejbService.processExCourse(new ExCourse()));

  }
}

Et voici l'entité:

package ejbserviceclient;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class ExCourse {

int id;

}

Mais il y a une exception:

Exception in thread "main" javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException
 - with linked exception:
[javax.xml.bind.JAXBException: class ejbserviceclient.ExCourse nor any of its super class is known to this context.]
    at com.Sun.xml.internal.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.Java:318)
    at com.Sun.xml.internal.ws.message.AbstractMessageImpl.writeTo(AbstractMessageImpl.Java:131)
    at com.Sun.xml.internal.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.Java:98)
    at com.Sun.xml.internal.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.Java:249)
    at com.Sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.Java:144)
    at com.Sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.Java:83)
    at com.Sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.Java:78)
    at com.Sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.Java:587)
    at com.Sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.Java:546)
    at com.Sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.Java:531)
    at com.Sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.Java:428)
    at com.Sun.xml.internal.ws.client.Stub.process(Stub.Java:211)
    at com.Sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.Java:124)
    at com.Sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.Java:98)
    at com.Sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.Java:78)
    at com.Sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.Java:107)
    at $Proxy19.processExCourse(Unknown Source)
    at ejbserviceclient.EjbServiceClient.main(EjbServiceClient.Java:30)
Caused by: javax.xml.bind.MarshalException
 - with linked exception:
[javax.xml.bind.JAXBException: class ejbserviceclient.ExCourse nor any of its super class is known to this context.]
    at com.Sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.Java:268)
    at com.Sun.xml.internal.bind.v2.runtime.BridgeImpl.marshal(BridgeImpl.Java:89)
    at com.Sun.xml.internal.bind.api.Bridge.marshal(Bridge.Java:130)
    at com.Sun.xml.internal.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.Java:310)
    ... 17 more
Caused by: javax.xml.bind.JAXBException: class ejbserviceclient.ExCourse nor any of its super class is known to this context.
    at com.Sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.Java:214)
    at com.Sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.Java:229)
    at com.Sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.Java:621)
    at com.Sun.xml.internal.bind.v2.runtime.BridgeImpl.marshal(BridgeImpl.Java:136)
    at com.Sun.xml.internal.bind.v2.runtime.CompositeStructureBeanInfo.serializeBody(CompositeStructureBeanInfo.Java:96)
    at com.Sun.xml.internal.bind.v2.runtime.CompositeStructureBeanInfo.serializeBody(CompositeStructureBeanInfo.Java:44)
    at com.Sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.Java:664)
    at com.Sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.Java:263)
    ... 20 more
Caused by: javax.xml.bind.JAXBException: class ejbserviceclient.ExCourse nor any of its super class is known to this context.
    at com.Sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.Java:554)
    at com.Sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.Java:616)
    ... 25 more
Java Result: 1
15
johnny-b-goode

Il semble que vous n'ayez pas correctement initialisé votre JAXBContext. Vous devez l'informer de tous les possibles @XmlRootElement noms de classe qui pourraient être analysés.

Vous devez donc changer

JAXBContext context = JAXBContext.newInstance(EjbServiceClient.class)

à

JAXBContext context = JAXBContext.newInstance(ejbserviceclient.ExCourse.class)
35
Brant Olsen