Skip to main content

JAXB & WebServices

7 replies [Last post]
ibsscott
Offline
Joined: 2005-07-19
Points: 0

I'm using JAXB 2.0ea. I have built a web service that is expecting an XML document as an attachment. I have built a client and I'm trying to find a clever way to Marshal my JAXB object into a javax.xml.transform.Source so my web service can receive it as an attachment. Unfortunately I have not succeeded yet. I can certainly do it when my web service accepts a String as a parameter, but I was worried about how large the String is allowed to be so I am trying to switch to using attachments instead. I could really use some advice. I thought I could do it like this, but I got the error shown below:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
m.setProperty("com.sun.xml.bind.xmlDeclaration",Boolean.FALSE);
m.marshal(retrievePersonDocument, doc);
Source source = new DOMSource(doc);
Source result = endpoint.getPerson(source);

- Exception:

AxisFault

faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException

faultSubcode:

faultString: java.io.IOException: javax.xml.transform.Source implementation not supported: javax.xml.transform.dom.DOMSource.

faultActor:

faultNode:

faultDetail:

{http://xml.apache.org/axis/}stackTrace:java.io.IOException: javax.xml.transform.Source implementation not supported: javax.xml.transform.dom.DOMSource.

at org.apache.axis.encoding.ser.SourceDataHandlerSerializer.serialize(SourceDataHandlerSerializer.java:49)

at org.apache.axis.encoding.SerializationContext.serializeActual(SerializationContext.java:1426)

etc.....

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ibsscott
Offline
Joined: 2005-07-19
Points: 0

Well, that didn't work out too well.

javax.xml.transform.Source implementation not supported: javax.xml.bind.util.JAXBSource.

What in the world does Axis support?? I'm using JBoss's built in Axis. It was really easy to implement the JAXB but how can I use it?

kohsuke
Offline
Joined: 2003-06-09
Points: 0

JAXBSource is actually a SAXSource. So sounds like you just found at it neither supports DOMSource nor SAXSource. That just leaves StreamSource.

If you find out what Axis actually supports, please let us know!

kohsuke
Offline
Joined: 2003-06-09
Points: 0

You'd be surprised how easy it is!
[code]
import javax.xml.bind.util.JAXBSource;
Source src = new JAXBSource(context,jaxbObject);
[/code]
This is also very efficient, as it doesn't involve in the format conversion. When AXIS writes this as an attachment, JAXB objects should go straight to the attachment without going through String or DOM or anything.

The fact that AXIS doesn't support DOMSource is an AXIS' problem.

ibsscott
Offline
Joined: 2005-07-19
Points: 0

Thanks for the tip. I'm going to try it out. Would JAXBSource be more efficient than using a document/literal web service?

DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
m.marshal(retrievePersonDocument, doc);
SOAPBodyElement docElement = soapBody.addDocument(doc);
etc

I was playing with this in the meantime. Also, I am having trouble generating a wsdl for this SEI,

public org.w3c.dom.Element getPerson(org.w3c.dom.Element element) throws java.rmi.RemoteException;

I can't figure out how to get wscompile to generate xs:anyType such as





It keeps generating a complexType for org.w3c.dom.Element:

















I've tried these options:

fork="true"
define="true"
features="documentliteral,nodatabinding,wsi"
base="."
debug="true"
verbose="true"
config="config.xml"
mapping="jaxrpc-mapping.xml"
>

kohsuke
Offline
Joined: 2003-06-09
Points: 0

JAXBSource is definitely more efficient than:
[code]
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
m.marshal(retrievePersonDocument, doc);
SOAPBodyElement docElement = soapBody.addDocument(doc);
[/code]
Using JAXBSource, you are doing just one conversion. "JAXB objects -> wire"
Using the above code, you are doing two conversions "JAXB objects -> DOM -> wire".
It depends on your DOM implementation, but the former is usually considerably faster. And besides, it's much easier to write.

ibsscott
Offline
Joined: 2005-07-19
Points: 0

I was actually wondering if it would be faster on the server side to have a documentliteral as opposed to an attachment.

I tried using StreamSource. I'm sure there is a more elegant way to create it but this is how I did it:

JAXBContext jc = JAXBContext.newInstance("com.fifalmonk.jaxb");
Marshaller m = jc.createMarshaller();
Unmarshaller u = jc.createUnmarshaller();
StringWriter sw = new StringWriter();
m.marshal(retrievePersonDocument, sw);
StringReader sr = new StringReader(sw.toString());
Source source = new StreamSource(sr);

//Source source = new JAXBSource(jc, retrievePersonDocument);
source=endpoint.getPerson(source);
Object o = u.unmarshal(source);
m.marshal(o, System.out);

I got a new error this time. I can't tell if it is objecting to StreamSource or something else:

14:43:17,484 ERROR [RPCInvocation] java.lang.ClassCastException: org.jboss.axis.
message.SOAPBodyElementAxisImpl
java.lang.ClassCastException: org.jboss.axis.message.SOAPBodyElementAxisImpl
at org.jboss.axis.encoding.ser.JAFDataHandlerDeserializer.startElement(J
AFDataHandlerDeserializer.java:121)
at org.jboss.axis.encoding.ser.SourceDataHandlerDeserializer.startElemen
t(SourceDataHandlerDeserializer.java:82)
at org.jboss.axis.encoding.DeserializationContextImpl.startElement(Deser
ializationContextImpl.java:1182)
at org.jboss.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.jav
a:244)
at org.jboss.axis.message.SOAPElementAxisImpl.publishToHandler(SOAPEleme
ntAxisImpl.java:1386)
at org.jboss.axis.message.RPCElement.deserialize(RPCElement.java:262)
at org.jboss.axis.message.RPCElement.getParams(RPCElement.java:396)
at org.jboss.axis.providers.java.RPCInvocation.prepareFromRequestEnvelop
e(RPCInvocation.java:235)
at org.jboss.axis.providers.java.RPCProvider.processMessage(RPCProvider.
java:103)
at org.jboss.axis.providers.java.JavaProvider.invoke(JavaProvider.java:3
58)
at org.jboss.axis.strategies.InvocationStrategy.visit(InvocationStrategy
.java:73)
at org.jboss.axis.SimpleChain.doVisiting(SimpleChain.java:160)
at org.jboss.axis.SimpleChain.invoke(SimpleChain.java:123)
at org.jboss.axis.handlers.soap.SOAPService.invoke(SOAPService.java:560)

at org.jboss.webservice.server.ServerEngine.invokeInternal(ServerEngine.
java:200)
at org.jboss.webservice.server.ServerEngine.invoke(ServerEngine.java:89)

at org.jboss.axis.transport.http.AxisServlet.doPost(AxisServlet.java:905
)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.jboss.axis.transport.http.AxisServletBase.service(AxisServletBase
.java:370)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
lter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:178)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrinc
ipalValve.java:39)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
yAssociationValve.java:153)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
e.java:59)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWor
kerThread.java:112)
at java.lang.Thread.run(Thread.java:595)
14:43:17,504 ERROR [ServerEngine] Server error: AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Client
faultSubcode:
faultString: org.jboss.axis.message.SOAPBodyElementAxisImpl
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace: java.lang.ClassCastException: o
rg.jboss.axis.message.SOAPBodyElementAxisImpl
at org.jboss.axis.encoding.ser.JAFDataHandlerDeserializer.startElement(J
AFDataHandlerDeserializer.java:121)
at org.jboss.axis.encoding.ser.SourceDataHandlerDeserializer.startElemen
t(SourceDataHandlerDeserializer.java:82)
at org.jboss.axis.encoding.DeserializationContextImpl.startElement(Deser
ializationContextImpl.java:1182)
at org.jboss.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.jav
a:244)
at org.jboss.axis.message.SOAPElementAxisImpl.publishToHandler(SOAPEleme
ntAxisImpl.java:1386)
at org.jboss.axis.message.RPCElement.deserialize(RPCElement.java:262)
at org.jboss.axis.message.RPCElement.getParams(RPCElement.java:396)
at org.jboss.axis.providers.java.RPCInvocation.prepareFromRequestEnvelop
e(RPCInvocation.java:235)
at org.jboss.axis.providers.java.RPCProvider.processMessage(RPCProvider.
java:103)
at org.jboss.axis.providers.java.JavaProvider.invoke(JavaProvider.java:3
58)
at org.jboss.axis.strategies.InvocationStrategy.visit(InvocationStrategy
.java:73)
at org.jboss.axis.SimpleChain.doVisiting(SimpleChain.java:160)
at org.jboss.axis.SimpleChain.invoke(SimpleChain.java:123)
at org.jboss.axis.handlers.soap.SOAPService.invoke(SOAPService.java:560)

at org.jboss.webservice.server.ServerEngine.invokeInternal(ServerEngine.
java:200)
at org.jboss.webservice.server.ServerEngine.invoke(ServerEngine.java:89)

at org.jboss.axis.transport.http.AxisServlet.doPost(AxisServlet.java:905
)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.jboss.axis.transport.http.AxisServletBase.service(AxisServletBase
.java:370)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
lter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:178)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrinc
ipalValve.java:39)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
yAssociationValve.java:153)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
e.java:59)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWor
kerThread.java:112)
at java.lang.Thread.run(Thread.java:595)

{http://xml.apache.org/axis/}isRuntimeException: true

14:43:17,504 INFO [AxisServlet] java.lang.ClassCastException: org.jboss.axis.me
ssage.SOAPBodyElementAxisImpl

kohsuke
Offline
Joined: 2003-06-09
Points: 0

One thing for sure is that the error is coming from JBoss or Axis. I think you need to ask them.