Return-Path: Delivered-To: apmail-ws-axis-user-archive@www.apache.org Received: (qmail 30848 invoked from network); 25 Jun 2005 19:06:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 25 Jun 2005 19:06:53 -0000 Received: (qmail 65893 invoked by uid 500); 25 Jun 2005 19:06:46 -0000 Delivered-To: apmail-ws-axis-user-archive@ws.apache.org Received: (qmail 65071 invoked by uid 500); 25 Jun 2005 19:06:43 -0000 Mailing-List: contact axis-user-help@ws.apache.org; run by ezmlm Precedence: bulk Reply-To: axis-user@ws.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list axis-user@ws.apache.org Received: (qmail 65057 invoked by uid 99); 25 Jun 2005 19:06:43 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 25 Jun 2005 12:06:43 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=RCVD_BY_IP X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of pauljbarry3@gmail.com designates 64.233.162.202 as permitted sender) Received: from [64.233.162.202] (HELO zproxy.gmail.com) (64.233.162.202) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 25 Jun 2005 12:06:43 -0700 Received: by zproxy.gmail.com with SMTP id k1so63772nzf for ; Sat, 25 Jun 2005 12:06:40 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=K0h9ixRyKXZSBl9gR61nXOi8EOCJhirkiPLArTr71vV9iWiDTIPnJd9QtyX3so3xSGIwJ+s6d746YWdSuWeFhGph+3IJG/9oAHFmqmFRgExKfMWjd1DPIrkbsonMl12584EzQFJkD53dP6EiXO9/wzPLmxFcChPiT8u+0zEVYrs= Received: by 10.36.41.11 with SMTP id o11mr2303808nzo; Sat, 25 Jun 2005 12:06:40 -0700 (PDT) Received: by 10.36.32.6 with HTTP; Sat, 25 Jun 2005 12:06:40 -0700 (PDT) Message-ID: Date: Sat, 25 Jun 2005 15:06:40 -0400 From: Paul Barry Reply-To: Paul Barry To: axis-user@ws.apache.org Subject: Re: change soapenv / get rid of ns1,ns2,... In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N I can get what I need building the SOAP XML message with JDOM first and then wrapping it in a SOAPEnvelope object like this: import java.io.ByteArrayInputStream; import org.apache.axis.message.SOAPEnvelope; import org.jdom.Document; import org.jdom.Element; import org.jdom.Namespace; import org.jdom.output.Format; import org.jdom.output.XMLOutputter; public class Test { public static void main(String[] args) throws Exception { new Test(); } =20 public Test() throws Exception { Document doc =3D new Document(); =20 Element env =3D new Element("Envelope","soap","http://schemas.xmlsoap.org/soap/envelope/"); env.addNamespaceDeclaration(Namespace.getNamespace("xsi","http:= //www.w3.org/2001/XMLSchema-instance")); env.addNamespaceDeclaration(Namespace.getNamespace("xsd","http:= //www.w3.org/2001/XMLSchema")); doc.setRootElement(env); =20 Element header =3D new Element("Header",env.getNamespace()); env.addContent(header); =20 Element cmsAuthentication =3D new Element("CMSAuthentication","http://www.centra.com/CWS"); header.addContent(cmsAuthentication); =20 Element username =3D new Element("username",cmsAuthentication.getNamespace()); username.setText("admin"); cmsAuthentication.addContent(username); =20 Element password =3D new Element("password",cmsAuthentication.getNamespace()); password.setText("admin"); cmsAuthentication.addContent(password); =20 =20 Element domain =3D new Element("Domain",cmsAuthentication.getNamespace()); cmsAuthentication.addContent(domain); =20 =20 Element body =3D new Element("Body",env.getNamespace()); env.addContent(body); =20 Element findUser =3D new Element("FindUser","http://www.centra.com/CWS"); body.addContent(findUser); =20 =20 Element user =3D new Element("user",findUser.getNamespace()); user.setAttribute("version","3.0"); user.setAttribute("loginName","pbarry"); findUser.addContent(user); =20 XMLOutputter xmlOut =3D new XMLOutputter(); xmlOut.setFormat(Format.getPrettyFormat()); SOAPEnvelope soapEnv =3D new SOAPEnvelope(new ByteArrayInputStream(xmlOut.outputString(doc).getBytes())); System.out.println(soapEnv); =20 } } Is there an easier way to do this? On 6/25/05, Paul Barry wrote: > 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: >=20 > > xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema" > xmlns:soap=3D"http://schemas.xmlsoap.org/soap/envelope/"> > > > admin > admin > > > > > > > > > >=20 > Here is my code: >=20 > SOAPEnvelope env =3D new SOAPEnvelope(); >=20 > SOAPHeaderElement header =3D > new SOAPHeaderElement(new > QName("http://www.centra.com/CWS", "CMSAuthentication","")); >=20 > DocumentBuilder builder =3D factory.newDocumentBuilder(); > Document doc =3D builder.newDocument(); > Element username =3D doc.createElement("username"); > username.appendChild(doc.createTextNode("admin")); >=20 > header.addChildElement(new SOAPHeaderElement(username)); >=20 > doc =3D builder.newDocument(); > Element password =3D doc.createElement("password"); > password.appendChild(doc.createTextNode("admin")); > header.addChildElement(new SOAPHeaderElement(password)); >=20 > doc =3D builder.newDocument(); > Element domain =3D doc.createElement("Domain"); > header.addChildElement(new SOAPHeaderElement(domain)); >=20 > env.addHeader(header); >=20 > SOAPBodyElement body =3D new SOAPBodyElement( > new QName("http://www.centra.com/CWS","FindUser","")); >=20 > doc =3D builder.newDocument(); > Element user =3D doc.createElement("user"); > user.setAttribute("version","3.0"); > user.setAttribute("loginName","test"); > body.addChildElement(new SOAPBodyElement(user)); >=20 > env.addBodyElement(body); >=20 > This unfortunately produces: >=20 > xmlns:soapenv=3D"http://schemas.xmlsoap.org/soap/envelope/" > xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema" > xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance"> > > soapenv:actor=3D"http://schemas.xmlsoap.org/soap/actor/next" > soapenv:mustUnderstand=3D"0" xmlns:ns1=3D"http://www.centra.com/CWS"> > admin > admin > > > > > > > > > >=20 > This doesn't work with the 3rd party app. The two reasons are: >=20 > 1. The prefix is "soapenv", but the 3rd party app expects it to be "soap= ". >=20 > 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. >=20 > 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: >=20 > xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema" > xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance"> > > soap:actor=3D"http://schemas.xmlsoap.org/soap/actor/next" > soap:mustUnderstand=3D"0" xmlns=3D"http://www.centra.com/CWS"> > admin > admin > > > > > > > > > >=20 > Thanks in advance, >=20 > Paul >