fnkbz
fnkbz

Reputation: 1219

JAXB - How to set xmlns and prefix in child tag only

I'm using JAXB to generate a soap xml request. The current xml output that i want is this

<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:rgw="http:/blablablablabla.org" 
xmlns:typ="http://blablablablabla.org/bla/bla">

<soapenv:Header>

  <wsse:Security 
  soapenv:mustUnderstand="1" 
  xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
  xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">

       <wsse:UsernameToken wsu:Id="testToken-13">
        <wsse:Username>blbalbalL</wsse:Username>
        <wsse:Password 
        Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">1234r</wsse:Password>
     </wsse:UsernameToken>
  </wsse:Security>
 </soapenv:Header>
<soapenv:Body>
</soapenv:Body>
</soapenv:Envelope>

Until now i have generate the Envelope and Header tag but i have trouble with the Security tag.

My problem is if i try to set the xmlns to package-info.class the prefix is correct but the xmlns:wsse="blbalbla" and the xmlns:wsu="http://balbla.com" going to the root element(envelope) and not into the security tag. Here is the output that i get:

<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:rgw="http://gr/gsis/rgwsalldata/RgWsAllData.wsdl" 
xmlns:typ="http://gr/gsis/rgwsalldata/RgWsAllData.wsdl/types/" 
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<soapenv:Header>
    <wsse:Security/>
</soapenv:Header>
<soapenv:Body/>

As you can see in the desire xml output the xmlns:wsse and xmlns:wsu namespaces are at the security tag. how can i these xmlns to security tag? and how can the UsernameToken tag should build?

package-info.class

@XmlSchema(
    namespace = "http://schemas.xmlsoap.org/soap/envelope/",
    xmlns = { @XmlNs(prefix="soapenv", namespaceURI="http://schemas.xmlsoap.org/soap/envelope/"),
              @XmlNs(prefix="rgw", namespaceURI="http://blabalbalbal.org"),
              @XmlNs(prefix="typ", namespaceURI="blablaba/types/"),
              @XmlNs(prefix="wsse", namespaceURI="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"),
              @XmlNs(prefix="wsu", namespaceURI="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd")},
    elementFormDefault = XmlNsForm.QUALIFIED)

package broker.jaxb.xmlrequest;

import javax.xml.bind.annotation.*;

Upvotes: 0

Views: 2920

Answers (1)

Zielu
Zielu

Reputation: 8562

You can use @XmlType(namespace="http://docs.oasis-open.org/wss") (or XMLRoot) on top of Security class instead of declaring the namespace in package-info it should bring the namespace down to the Security tag.

As mentioned in the comment both documents are equivalent xml, so first test if the soap message works as it is. No point in reproducing the exact format if the other side can read this one as well (any decent modern WS framework will do).

Upvotes: 1

Related Questions