19 Stimmen

Auch die Superklasse ist in diesem Zusammenhang nicht bekannt

Ich versuche, einige Entität zu Ejb-basierten Webdienst zu senden. Hier ist mein Web-Service-Client-Code:

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()));

  }
}

Und hier ist Entität:

package ejbserviceclient;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class ExCourse {

int id;

}

Aber es gibt eine Ausnahme:

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

43voto

Brant Olsen Punkte 5579

Es sieht so aus, als hätten Sie Ihre Software nicht initialisiert. JAXBContext richtig. Sie müssen sie über alle Möglichkeiten informieren @XmlRootElement Klassennamen, die potenziell geparst werden können.

Daher müssen Sie Folgendes ändern

JAXBContext context = JAXBContext.newInstance(EjbServiceClient.class)

zu

JAXBContext context = JAXBContext.newInstance(ejbserviceclient.ExCourse.class)

CodeJaeger.com

CodeJaeger ist eine Gemeinschaft für Programmierer, die täglich Hilfe erhalten..
Wir haben viele Inhalte, und Sie können auch Ihre eigenen Fragen stellen oder die Fragen anderer Leute lösen.

Powered by:

X