marshal/wrap xml in SOAP envelope
<p>I have an existing xml payload that I have to wrap with a soap envelope, currently I am trying to build soap envelope from java classes with annotations. it is marshaled to xml with JAXB within the message service.</p>

<p>the current issues I have with using the annotations is 
1. xml namespace assigning to soap envelope and not as attribute in child element (MQRequest element). 
2. how to assign xsi to complex element (Transport element).</p>

<pre><code>&lt;SOAP-ENV:Envelope xmlns:SOAPENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;SOAP-ENV:Body&gt;
    &lt;MQRequest xmlns="http://group.com/abc/wsdl/ABCService"&gt;
    &lt;requestHeader xmlns=""&gt;
            &lt;ns1:ESBRequestId xmlns:ns1="http://group.com/abc/schema/Header" /&gt;
            &lt;ns2:ClientAudit xmlns:ns2="http://group.com/abc/schema/Header"&gt;
                &lt;ns2:ClientApplication&gt;&lt;/ns2:ClientApplication&gt;
                &lt;ns2:ClientReferenceId&gt;&lt;/ns2:ClientReferenceId&gt;
                &lt;ns2:RequestDateTime&gt;&lt;/ns2:RequestDateTime&gt;
            &lt;/ns2:ClientAudit&gt;
            &lt;ns3:Transport xmlns:ns3="http://group.com/abc/schema/Header"
                xsi:type="ns3:MQTransport"&gt;
                &lt;ns3:QueueManager /&gt;
                &lt;ns3:ResponseQueueName /&gt;
                &lt;ns3:MessageFormat&gt;&lt;/ns3:MessageFormat&gt;
                &lt;ns3:MQMessageId /&gt;
                &lt;ns3:TimeToLive&gt;&lt;/ns3:TimeToLive&gt;
            &lt;/ns3:Transport&gt;
            &lt;ns4:Operation xmlns:ns4="http://group.com/abc/schema/Header"&gt;
                &lt;ns4:ServiceName&gt;&lt;/ns4:ServiceName&gt;
                &lt;ns4:InterfaceName&gt;&lt;/ns4:InterfaceName&gt;
                &lt;ns4:OperationName&gt;&lt;/ns4:OperationName&gt;
            &lt;/ns4:Operation&gt;
        &lt;/requestHeader&gt;
        &lt;Msg xmlns=""&gt;&lt;/Msg&gt;
</code></pre>

<p>here is what I am currently able to replicate.</p>

<pre><code>&lt;SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"   xmlns:ns0="http://group.com/abc/wsdl/ABCService" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
&lt;SOAP-ENV:Body&gt;
    &lt;MQRequest&gt;
        &lt;requestHeader&gt;
            &lt;ESBRequestId/&gt;
            &lt;ClientAudit&gt;
                &lt;ClientApplication&gt;&lt;/ClientApplication&gt;
                &lt;ClientReferenceId&gt;&lt;/ClientReferenceId&gt;
                &lt;RequestDateTime&gt;&lt;/RequestDateTime&gt;
            &lt;/ClientAudit&gt;
            &lt;Transport&gt;
                &lt;QueueManager/&gt;
                &lt;ResponseQueueName/&gt;
                &lt;MessageFormat&gt;&lt;/MessageFormat&gt;
                &lt;MQMessageId/&gt;
                &lt;TimeToLive&gt;&lt;/TimeToLive&gt;
            &lt;/Transport&gt;
            &lt;Operation&gt;
                &lt;ServiceName&gt;&lt;/ServiceName&gt;
                &lt;InterfaceName&gt;&lt;/InterfaceName&gt;
                &lt;OperationName&gt;&lt;/OperationName&gt;
            &lt;/Operation&gt;
        &lt;/requestHeader&gt;
        &lt;Msg&gt;
        &lt;/Msg&gt;
    &lt;/MQRequest&gt;
&lt;/SOAP-ENV:Body&gt;
&lt;/SOAP-ENV:Envelope&gt;
</code></pre>

<p>as you can see the namespace for MQRequest is being pushed to the envelope. Java code is as follows.</p>

<pre><code>@XmlRootElement(name = "Envelope")
public class SoapEnvelope implements RequestMessage {

  @XmlElement(name = "Body")
  private SoapBody soapBody;

  public SoapEnvelope(SoapBody soapBody) {
    this.soapBody = soapBody;
  }

  public SoapEnvelope() {
  }
}
</code></pre>

<p>Im using @xmlSchema with the envelope class, which I have put in a seperate package to the other request elements.</p>

<pre><code>@XmlSchema(
    namespace = "http://schemas.xmlsoap.org/soap/envelope/",
    elementFormDefault = XmlNsForm.QUALIFIED,
    xmlns = {
        @XmlNs(prefix="SOAP-ENV", namespaceURI="http://schemas.xmlsoap.org/soap/envelope/"),
        @XmlNs(prefix="xsi", namespaceURI="http://www.w3.org/2001/XMLSchema-instance"),
        @XmlNs(prefix="xsd", namespaceURI="http://www.w3.org/2001/XMLSchema")
    }
)

@XmlRootElement(name = "Body")
public class SoapBody {

  @XmlElement(name = "MQRequest")
  AbcRequest abcRequest;

  public SoapBody(AbcRequest abcRequest) {
    this.abcRequest = abcRequest;
  }

  public SoapBody() {
  }
}

@XmlRootElement(name = "MQRequest")
@XmlType(namespace="http://group.com/abc/wsdl/ABCService")
public class AbcRequest implements RequestMessage {

  @XmlElement(name = "requestHeader")
  private AbcRequestHeader header;

  @XmlElement(name = "Msg")
  private MsgPayload msgPayload;

  public AbcRequest() {

  }
}
</code></pre>

<p>I have tried playing around using package-info and @xmlSchema but get similar results. I also have the same issue when assigning the header namespace (<a href="http://group.com/abc/schema/Header" rel="nofollow">http://group.com/abc/schema/Header</a>) in requestHeader it propagates to envelope and assigns "ns0:" to all the elements instead of ns1,ns2, etc.</p>

<p>the second issue that i mentioned relates to the following.</p>

<pre><code>&lt;ns3:Transport xmlns:ns3="http://group.com/abc/schema/Header"
                    xsi:type="ns3:MQTransport"&gt;
</code></pre>

<p>Im just not sure how to go about getting the xsi:type attribute assigned? I have read this <a href="http://blog.bdoughan.com/2010/11/jaxb-and-inheritance-using-xsitype.html" rel="nofollow">http://blog.bdoughan.com/2010/11/jaxb-and-inheritance-using-xsitype.html</a>, but not sure if right approach?</p>

<p>Happy to provide any further information.
Thanks for any help.</p>