Kohsuke Kawaguchi wrote:
>>I am looking for two methods that convert back and forth between a JAXB
>>generated binding object and a javax.xml.soap.SOAPElement.
>>
>>Please share your code if you have done this already.
>>
>>
>
>I never tried it by myself, but like George pointed out, SOAPElement is
>just a dom. So the following code:
>
>
> SOAPElement parent = ...;
>
> marshaller.marshal( yourJaxbObject, new DOMResult(parent) );
>
>should marshal the JAXB object under the specified SOAP parent element.
>
>
Thanks Kohsuke.
I think what JAX-RPC expects is to marshal to a SOAPElement and not
under a parent element.
I have done the following two methods though they are not yet tested. I
will post final version once I am done testing.
Feel free to critique.
public SOAPElement getSOAPElementFromBindingObject(Object obj)
throws OMARException {
SOAPElement soapElem = null;
try {
DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.marshal( obj, doc );
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage msg = mf.createMessage();
SOAPBody body = msg.getSOAPBody();
soapElem = body.addDocument(doc);
}
catch (Exception e) {
throw new OMARException(e);
}
return soapElem;
}
public Object getBindingObjectFromSOAPElement(SOAPElement soapElem)
throws OMARException {
Object obj = null;
try {
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
obj = unmarshaller.unmarshal(soapElem);
}
catch (Exception e) {
throw new OMARException(e);
}
return obj;
}
--
Farrukh
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net