Thanks Scott...
It is really of great help...
Nishant
Scott Nichol
<snicholnews@scottn To: [EMAIL PROTECTED]
ichol.com> cc: (bcc: Nishant Awasthi)
Subject: Re: XML response in SOAP
message ???
08/21/2002 05:20 PM
Please respond to
soap-dev
It turns out that Apache SOAP does un-escape strings on the client side.
Here's the test service I wrote:
public class XMLString {
public String get() {
return
"<?xml version=\"1.0\"?>\n" +
"<foo>\n" +
" <bar>This is data</bar>\n" +
"</foo>";
}
}
The test client is:
import java.io.*;
import java.util.*;
import java.net.*;
import org.w3c.dom.*;
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.encoding.*;
import org.apache.soap.encoding.soapenc.*;
import org.apache.soap.rpc.*;
/**
*/
public class GetXMLString {
public static void main(String[] args) throws Exception {
if (args.length != 1
&& (args.length != 2 || !args[0].startsWith("-"))) {
System.err.println("Usage:");
System.err.println(" java " + GetXMLString.class.getName() +
" [-encodingStyleURI] SOAP-router-URL");
System.exit(1);
}
// Process the arguments.
int offset = 2 - args.length;
String encodingStyleURI = args.length == 2
? args[0].substring(1)
: Constants.NS_URI_SOAP_ENC;
URL url = new URL(args[1 - offset]);
SOAPMappingRegistry smr = new SOAPMappingRegistry();
// Build the call.
Call call = new Call();
call.setSOAPMappingRegistry(smr);
call.setTargetObjectURI("urn:XMLString");
call.setMethodName("get");
call.setEncodingStyleURI(encodingStyleURI);
Vector params = new Vector();
call.setParams(params);
// Invoke the call.
Response resp;
try {
resp = call.invoke(url, "");
} catch (SOAPException e) {
System.err.println("Caught SOAPException (" +
e.getFaultCode() + "): " +
e.getMessage());
return;
}
// Check the response.
if (!resp.generatedFault()) {
Parameter ret = resp.getReturnValue();
Object value = ret.getValue();
System.out.println(value != null ? "\n" + value : "I don't know.");
} else {
Fault fault = resp.getFault();
System.err.println("Generated fault: " + fault);
}
}
}
The request as captured by TcpTunnelGui is:
POST /soap/servlet/rpcrouter HTTP/1.0
Host: localhost:81
Content-Type: text/xml; charset=utf-8
Content-Length: 392
SOAPAction: ""
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:get xmlns:ns1="urn:XMLString"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
</ns1:get>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The response is:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: 551
Date: Wed, 21 Aug 2002 21:08:46 GMT
Server: Apache Tomcat/4.0.1 (HTTP/1.1 Connector)
Set-Cookie: JSESSIONID=55E1B280E482A453B0C1627104E72850;Path=/soap
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:getResponse xmlns:ns1="urn:XMLString"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<return xsi:type="xsd:string"><?xml version="1.0"?>
<foo>
<bar>This is data</bar>
</foo></return>
</ns1:getResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The output from the client is:
H:\code\soaphack>java GetXMLString
http://localhost:81/soap/servlet/rpcrouter
<?xml version="1.0"?>
<foo>
<bar>This is data</bar>
</foo>
As you can see from the trace of the response, over the wire the XML string
is escaped. The output of the client, however, shows the un-escaped
strings. Since my client code does not do this explicitly, it must be done
within Apache SOAP (or the XML parser).
Scott Nichol
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, August 21, 2002 4:40 PM
Subject: Re: XML response in SOAP message ???
Thanks for the comprehensive reply Scott,
I will try to fix my client and server code...
Thanks again
Nishant
Scott Nichol
<snicholnews@scottn To:
[EMAIL PROTECTED]
ichol.com> cc: (bcc: Nishant
Awasthi)
Subject: Re: XML
response
in SOAP message ???
08/21/2002 04:37 PM
Please respond to
soap-dev
The compiler is complaining because the valid escape sequences in Java
strings are things like \n, \r, \f, \u00fe.
Where I believe you need the new code is on the client, not the server. I
think the client will receive something like this across the wire:
<Envelope ...>
<Body ...>
<MethodNameResponse ...>
<return>
<?xml version="1.0"?>
<Employee_Info>
<firstname>Scott</firstname>
<lastname>Nichol</lastname>
</Employee_info>
</return>
</MethodNameResponse>
</Body>
</Envelope>
So, the client needs to convert < to <, > to >, " to ", and so
on, in order to have something that looks like XML.
Scott Nichol
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, August 21, 2002 2:55 PM
Subject: Re: XML response in SOAP message ???
Hey Scott
I just now tried to escape the "<" and ">" and "?" tags of XML with
escape charater ("\" - backslash)
and tried to compile my java file it gave me error on each and everyspot
where I please "\"...
I don't know if I did something wrong or what...I am attaching a sample of
the code please
see if I am doing something basically wrong:
mainStr = "<\?xml version=\"1.0\"\?> ";
while (rs.next())
{
firstn = rs.getString(1);
lastn = rs.getString(2);
phone = rs.getString(3);
pager = rs.getString(5);
home = rs.getString(6);
count = count+1;
mainStr = mainStr + "\<Employee_Info\>
\<Firstname\> "+ firstn +" \<\/Firstname>\<Lastname\> "+lastn + "
\<\/Lastname\> "+" \<Extension\> "+ phone +" \<\/Extension\> "+" \<Pager\>
"+pager+" \<\/Pager\> "+ " \<Home\> "+ home +" \<\/Home\>
\<\/Employee_Info\>" + "\n"; }
return mainStr;
Thanks a lot for all your help,
Nishant
Scott Nichol
<snicholnews@scottn To:
[EMAIL PROTECTED]
ichol.com> cc: (bcc: Nishant
Awasthi)
Subject: Re: XML
response
in SOAP message ???
08/21/2002 01:59 PM
Please respond to
soap-dev
>>>>
If the client that calls the SOAP method correctly "un-escapes" these
sequences, the resulting string will look like the string of XML text you
created.
<<<<
I put this out there rather cavalierly: I don't think the Apache SOAP
client
un-escape this on its own.
Scott Nichol
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>