users@jaxb.java.net

Re: marshalling using custom SOAP bindings

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Mon, 30 Jul 2007 13:46:49 -0700

jesse crossley wrote:
> however, i cannot find the proper way to add objects to the SOAP envelope's
> body's list of anies, since the list is a List<Element>, and my other
> generated binding objects don't extend Element. i tried to use the
> Marshaller.getNode() method to get a (hopefully castable) Node representing
> the object i wanted to add to the List of anyies, but that failed:

You can marshal objects to DOM by using one of the marshal methods, then
attach that to the body of the SOAP envelope.

You can also create JAXBContext in such a way that you can assign JAXB
objects as-is and have one marshalling process convert them all to the
full SOAP envelope infoset. See
https://jaxb.dev.java.net/guide/Mapping_of__xs_any___.html

>
> Exception in thread "main" java.lang.UnsupportedOperationException
> at
> javax.xml.bind.helpers.AbstractMarshallerImpl.getNode(AbstractMarshallerImpl.java:124)
> at
> mil.cfn.uswdss.mdi.binding.subscription.SubscriptionWriter.createEnvelope(SubscriptionWriter.java:63)
> at
> mil.cfn.uswdss.mdi.binding.subscription.SubscriptionWriter.main(SubscriptionWriter.java:353)
>
>
> can anyone shed some light on my situation? code snippets are below, and i
> can certainly try to explain things more fully if need be.
>
> thanks,
> jdc
>
>
> public static final Envelope createEnvelope(
> final AddEventListener addEventListener) {
> final Envelope returnable = soapOF.createEnvelope();
> try {
> final Node addEventListenerNode = getMarshaller().getNode(
> addEventListener);
> // PENDING(jdc): gotta make sure this is a safe cast..
>
> returnable.getBody().getAnies().add((Element)addEventListenerNode);
>
> } catch (final JAXBException jaxbe) {
> getClassLog().error("Failed...", jaxbe);
> }
> return returnable;
> }
>
> private static final String CONTEXT =
> "org.xmlsoap.schemas.soap.envelope:" +
> "peoiws5.mdiapps.soap.ws.shws.types";
>
> private static JAXBContext context;
>
> static {
> // initialize the JAXBContext
> try {
> context = JAXBContext.newInstance(CONTEXT);
>
> if (getClassLog().isTraceEnabled()) {
> getClassLog().trace("our context is " + context.toString());
> }
> } catch (final JAXBException jaxbe) {
> getClassLog().error("Failed to initialize the JAXBContext.",
> jaxbe);
> }
> }


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com