Return-Path: Delivered-To: apmail-ws-axis-user-archive@www.apache.org Received: (qmail 41811 invoked from network); 11 Jul 2005 00:58:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 11 Jul 2005 00:58:04 -0000 Received: (qmail 32167 invoked by uid 500); 11 Jul 2005 00:57:54 -0000 Delivered-To: apmail-ws-axis-user-archive@ws.apache.org Received: (qmail 32158 invoked by uid 500); 11 Jul 2005 00:57:54 -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 32145 invoked by uid 99); 11 Jul 2005 00:57:54 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 10 Jul 2005 17:57:54 -0700 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=DATE_IN_PAST_06_12 X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [66.163.12.83] (HELO tesla.cogentlogic.com) (66.163.12.83) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 10 Jul 2005 17:57:52 -0700 Received: from THESIGER ([10.0.0.12]) by tesla.cogentlogic.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2656.59) id 3L6WA30F; Sun, 10 Jul 2005 20:39:32 -0400 Message-ID: <001901c5854f$22935a40$0c00000a@thesiger> From: "Jeff" To: References: <25D454F3DBD1AF46A718F761CB11ABE102F5C1AF@nycmrmt1.corp.pbwan.net> Subject: Re: Passing an xml string as a parameter Date: Sun, 10 Jul 2005 08:58:57 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N There seems to be some confusion over string-literal in Axis or perhaps it's just that no-one's explained it in a while! Schemas are not a necessary prerequisite for using XML but to promote interoperability between disparate systems, a schema is invaluable. Many people mistakenly believe that schemas are used only for validation. In reality, they are hardly ever used for validation. First of all, in fully debugged systems, validation is not useful. Secondly, schemas often provide content, e.g. default values, that is needed during parsing. In short, you should have a schema. By definition, all XML documents have one and only one root element. Although schemas don't ever specify root elements, users of any given schema will, nonetheless, be well aware of which elements are used as root elements (or which element is used as a root element). When declaring an input and an output parameter for document-literal style web service, we can specify root elements: The element of the WSDL file defines the XML Schema which is just a regular XML Schema; it can span several documents and namespaces by import/include/redefine, for instance. WSDL2Java can take a WSDL file like this and generate a data model, as I describe earlier. Consequently, it is possible to use document-literal web services, using Axis data models, in the usual way. To read an XML document in client code that handles a response or server code that handles a request, you could use, (in addition to or instead of the data mode idiom): org.apache.axis.client.Call call = stub.m_call; org.apache.axis.MessageContext mc = call.getMessageContext(); org.apache.axis.Message m = mc.getCurrentMessage(); org.apache.axis.message.SOAPEnvelope envelope = m.getSOAPEnvelope(); org.apache.axis.message.SOAPBodyElement body = envelope.getFirstBody(); if (body instanceof org.apache.axis.message.SOAPFault) thrown new Exception((org.apache.axis.message.SOAPFault)body).getFaultString(); else try { java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); m.writeTo(baos); baos.flush(); baos.close(); // specify encoding according to that known to be used at the origin // e.g. "UTF-8" or "ISO-8859-1" String streXML = baos.toString(strEncoding); // now, use streXML // ... } catch (Exception except) { except.printStackTrace(); throw except; } Jeff Lawson ----- Original Message ----- From: "Miller, Janet" To: Sent: Sunday, July 10, 2005 2:38 PM Subject: RE: Passing an xml string as a parameter Thank you for this explanation, Ann. This clears things up alot!! Jan -----Original Message----- From: Anne Thomas Manes [mailto:atmanes@gmail.com] Sent: Saturday, July 09, 2005 10:38 AM To: axis-user@ws.apache.org Subject: Re: Passing an xml string as a parameter Janet, If the element is defined as a string, then Axis will map the return message to a string, and then your application will need to parse the XML programmatically. Axis will not be able to map the string to objects for you. This approach works, but it's not a good practice. Essentially, the XML repsonse is treated like an opaque string, and you can't rely on your middleware to do things like validation or automatic XML-to-object mapping. If you have any influence at all on the design of the other company's service, you should encourage them to send the XML as XML (in which the schema of the message is defined in the WSDL) and not as an opaque string. I would hope that this other company provides the schema of the XML string to you separately. In that case, you could use something like Castor or JAXB within your application to map the returned string into objects. But that function would have to be performed by your application code, and not by Axis. Regards, Anne On 7/8/05, Rajesh Nair wrote: > I would be surprised if there is something like that. How is WSDL2Java > in Axis gonna know how to map your xml to your java objects, since it > wont have any information about your schema. I would suggest look for > another open source tool called XMLBeans also from Apache to do the > mapping. Hope that helps a bit. > > -Rajesh > > -----Original Message----- > From: Miller, Janet [mailto:MillerJa@pbworld.com] > Sent: Friday, July 08, 2005 5:37 PM > To: axis-user@ws.apache.org > Subject: RE: Passing an xml string as a parameter > > Yes, that's exactly what I thought and I did already go through the > Axis user guide and read that section. I was proceeding to write the > code to parse the xml String myself, but someone posted something that > indicated that Axis would do the parsing for you and generate the > appropriate class. > > If anyone knows more about this, please let us know. > > Thanks, Jan > > -----Original Message----- > From: Rajesh Nair [mailto:rnair@ptpusa.com] > Sent: Friday, July 08, 2005 5:33 PM > To: axis-user@ws.apache.org > Subject: RE: Passing an xml string as a parameter > > > I think there's some confusion here. I think the classes created by > WSDL2Java are correct and doesn't generate any of the binding classes > because the parameter to the method and return value are > java.lang.String objects. The java.lang.String objects are by default > mapped to the corresponding SOAP/XML types in Axis, which is in > accordance to the JAX-RPC specification. U can also go through - > > http://ws.apache.org/axis/java/user-guide.html#ServiceStylesRPCDocumen > tW > rappedAndMessage > > > for more information on service styles and > > http://ws.apache.org/axis/java/user-guide.html#XMLJavaDataMappingInAxi > s > > for Java Data Mapping in Axis. > > Hope that helps. > > -Rajesh > > -----Original Message----- > From: Miller, Janet [mailto:MillerJa@pbworld.com] > Sent: Friday, July 08, 2005 5:22 PM > To: axis-user@ws.apache.org > Subject: RE: Passing an xml string as a parameter > > Yes, my return value is of type java.lang.String and the original wsdl > indicates document/literal. Jeff, in an earlier post indicated that > Axis is able to generate and parse the XML for you. Are you sure I > have to parse myself? > > Jan > > -----Original Message----- > From: Rajesh Nair [mailto:rnair@ptpusa.com] > Sent: Friday, July 08, 2005 5:20 PM > To: axis-user@ws.apache.org > Subject: RE: Passing an xml string as a parameter > > > Hi Janet, > If I am not wrong you are getting an xml string. That is u are > getting a return value of type java.lang.String. Correct me if I am > wrong here. If this is the case, then U will have to parse that string > and accordingly generate your objects. > > -Rajesh > > -----Original Message----- > From: Miller, Janet [mailto:MillerJa@pbworld.com] > Sent: Friday, July 08, 2005 5:16 PM > To: axis-user@ws.apache.org > Subject: RE: Passing an xml string as a parameter > > I've already used wsdl2java to create a web service from a remote wsdl > file that I've received. My web service is working and I have a > client that is succesfully accessing it and retrieving data. But how > would wsdl2java know my schema definition? It didn't generate a class > that represents the data model. It just generated 6 java files: > TZCService, TZCServiceLocator, TZCServiceSoap, TZCServiceSoapImpl, > TZCServiceSoapSkeleton, and TZCServiceSoapStub. There is nothing that > contains the xml return document elements. Do I need to put an xsd > file somewhere? In my xml namespace or target namespace? > > If someone could provide some step-by-step process on how to do this, > I would GREATLY appreciate it. > > Jan > > -----Original Message----- > From: Jeff [mailto:jeff@cogentlogic.com] > Sent: Friday, July 08, 2005 3:33 AM > To: axis-user@ws.apache.org > Subject: Re: Passing an xml string as a parameter > > > Don't feel foolish, we are not born knowing this stuff! > > Start with a WSDL document then the WSDL2Java tool (part of Axis) can > be used to generate a data model in the form of classes with > persistence methods (serialization/deserialization). Consequently, > Axis is able to generate and parse the XML for you. Alternatively or > additionally, if you like, you can handle the SOAP payload as a > document. Documents have the advantage of being something more > tangible than mere parameters. Originators can sign documents, for > instance. Documents can be stored in a variety of places, e.g. a > search engine or a database. > > > Jeff > > > ----- Original Message ----- > From: "Miller, Janet" > To: > Sent: Friday, July 08, 2005 2:52 PM > Subject: RE: Passing an xml string as a parameter > > > Yup, I'm a newbie and feel foolish now, but I need to ask some more > questions about this. I've looked at the Axis user guide and some > other sites and I'm still confused about how to map the returned xml > document to a Java object. How do you do this? Will Axis do this > automatically for me or do I have to parse the returned xml string > myself? > > Thanks for your help, > Jan > > -----Original Message----- > From: Jeff [mailto:jeff@cogentlogic.com] > Sent: Friday, July 08, 2005 2:17 AM > To: axis-user@ws.apache.org > Subject: Re: Passing an xml string as a parameter > > > Find out about document-literal, Jan. > > > > ----- Original Message ----- > From: "Miller, Janet" > To: > Sent: Friday, July 08, 2005 2:14 PM > Subject: Passing an xml string as a parameter > > > I was just wondering if anyone had any thoughts on this. I am going > to access another company's web service and the input parameter to the > web service is an xml string that represents a query request for data. > The response that I get back is also an xml string. So, instead of > passing multiple parameters, we are just passing on xml string > parameter. So I guess the soap packet would be xml within xml which > seems kind of odd. > > I guess it will probably work, but is this an ok way to do things? > Just curious about people's thoughts on something like this. > > Thanks, > > Jan > >