I'm trying to send some entity to ejb based web service. Here is my 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()));
}
}
And here is entity:
package ejbserviceclient;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class ExCourse {
int id;
}
But there is 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
The JAXBContext class provides the client's entry point to the JAXB API. It provides an abstraction for managing the XML/Java binding information necessary to implement the JAXB binding framework operations: unmarshal, marshal and validate.
When a top level class or an enum type is annotated with the @XmlRootElement annotation, then its value is represented as XML element in an XML document. This annotation can be used with the following annotations: XmlType , XmlEnum , XmlAccessorType , XmlAccessorOrder .
A javax.xml.bind.MarshalException error may occur when a null object is used as an argument to a java.util.List parameter on a JAX-WS web method.
Annotation Type XmlSeeAlsoInstructs JAXB to also bind other classes when binding this class. Java makes it impractical/impossible to list all sub-classes of a given class. This often gets in a way of JAXB users, as it JAXB cannot automatically list up the classes that need to be known to JAXBContext .
It looks like you have not initialized your JAXBContext
correctly. You need to inform it of all possible @XmlRootElement
class names that could potentially be parsed.
Thus you need to change
JAXBContext context = JAXBContext.newInstance(EjbServiceClient.class)
to
JAXBContext context = JAXBContext.newInstance(ejbserviceclient.ExCourse.class)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With