axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Barry <pauljbar...@gmail.com>
Subject change soapenv / get rid of ns1,ns2,...
Date Sat, 25 Jun 2005 17:44:57 GMT
I am trying to use the axis classes to construct a SOAP message to
build a web services client for a 3rd party app.  I need to construct
a message like this:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
        <CMSAuthentication xmlns="http://www.centra.com/CWS">
            <username>admin</username>
            <password>admin</password>
            <Domain/>
        </CMSAuthentication>
    </soap:Header>
    <soap:Body>
        <FindUser xmlns="http://www.centra.com/CWS">
            <user version="3.0" loginName="test"/>
        </FindUser>
    </soap:Body>
</soap:Envelope>

Here is my code:

        SOAPEnvelope env = new SOAPEnvelope();
        
        SOAPHeaderElement header = 
            new SOAPHeaderElement(new
QName("http://www.centra.com/CWS", "CMSAuthentication",""));
        
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.newDocument();
        Element username = doc.createElement("username");
        username.appendChild(doc.createTextNode("admin"));
        
        header.addChildElement(new SOAPHeaderElement(username));

        doc = builder.newDocument();
        Element password = doc.createElement("password");
        password.appendChild(doc.createTextNode("admin"));        
        header.addChildElement(new SOAPHeaderElement(password));

        doc = builder.newDocument();
        Element domain = doc.createElement("Domain");
        header.addChildElement(new SOAPHeaderElement(domain));
        
        env.addHeader(header);
        
        SOAPBodyElement body = new SOAPBodyElement(
            new QName("http://www.centra.com/CWS","FindUser",""));

        doc = builder.newDocument();
        Element user = doc.createElement("user");
        user.setAttribute("version","3.0");
        user.setAttribute("loginName","test");
        body.addChildElement(new SOAPBodyElement(user));        
        
        env.addBodyElement(body);

This unfortunately produces:

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soapenv:Header>
  <ns1:CMSAuthentication
soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"
soapenv:mustUnderstand="0" xmlns:ns1="http://www.centra.com/CWS">
   <username soapenv:actor="" soapenv:mustUnderstand="0">admin</username>
   <password soapenv:actor="" soapenv:mustUnderstand="0">admin</password>
   <Domain soapenv:actor="" soapenv:mustUnderstand="0"/>
  </ns1:CMSAuthentication>
 </soapenv:Header>
 <soapenv:Body>
  <ns2:FindUser xmlns:ns2="http://www.centra.com/CWS">
   <user loginName="test" version="3.0"/>
  </ns2:FindUser>
 </soapenv:Body>
</soapenv:Envelope>

This doesn't work with the 3rd party app.  The two reasons are:

1.  The prefix is "soapenv", but the 3rd party app expects it to be "soap".

2.  For each element in the header and body there is a prefix, they
are "ns1" and "ns2".  The 3rd party app expects there to be no prefix.

I'm sure the Axis-produces SOAP message is compliant and validate,
unfortunately the 3rd party app doesn't like it and I need to find a
way to work around it.  For #2, I would think passing in a QName with
the prefix defined as "" should result in no prefix for those
elements.  Is there a way I can make this happen?  Also, is there any
way, other than hacking SOAPConstants, to get it to user "soap"
instead of "soapenv"?  If I can get Axis to output a SOAP message like
this following one, then it works fine with the 3rd party app:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soap:Header>
  <CMSAuthentication
soap:actor="http://schemas.xmlsoap.org/soap/actor/next"
soap:mustUnderstand="0" xmlns="http://www.centra.com/CWS">
   <username soap:actor="" soap:mustUnderstand="0">admin</username>
   <password soap:actor="" soap:mustUnderstand="0">admin</password>
   <Domain soap:actor="" soap:mustUnderstand="0"/>
  </CMSAuthentication>
 </soap:Header>
 <soap:Body>
  <FindUser xmlns="http://www.centra.com/CWS">
   <user loginName="test" version="3.0"/>
  </FindUser>
 </soap:Body>
</soap:Envelope>

Thanks in advance,

Paul

Mime
View raw message