logo       

Help in retrieving XML contant submitted via J2ME: msg#00008

java.enhydra.kxml

Subject: Help in retrieving XML contant submitted via J2ME

hi all,
i have written a J2ME client that, using ksoap, sends XML request
to a servlet.
in the servlet (running on JBoss), i am trying to parse the XML request using
AXIS 1.1, but the code keeps on giving me a null pointer exception when i try
to read the content of the message.
here is the message

<v:Envelope xmlns:i="http://www.w3.org/1999/XMLSchema-instance";
xmlns:d="http://www.w3.org/1999/XMLSchema";
xmlns:c="http://schemas.xmlsoap.org/soap/encoding/";
xmlns:v="http://schemas.xmlsoap.org/soap/envelope/";>
<v:Header />
<v:Body>
<n0:agency id="o0" c:root="1" xmlns:n0="http://www.tgmm.com/agenciesdemo";>
<name i:type="d:string">testagency</name>
<tel i:type="d:string">12234</tel>
<email i:type="d:string">tgmm@xxxxxxxxx</email>
<contacted i:type="d:string">01012003</contacted>
<contactperson i:type="d:string">Myself</contactperson>
</n0:agency>
</v:Body>
</v:Envelope>

the code for retrieving it is as follows

Enumeration enumeration = request.getHeaderNames();
MimeHeaders mimeHeaders = new MimeHeaders();
while (enumeration.hasMoreElements()) {
String string1 = (String)enumeration.nextElement();
String string2 = request.getHeader(string1);
mimeHeaders.addHeader(string1, string2);
}
System.err.println("Now instantianting message..");
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage(mimeHeaders, stream);
System.err.println("OK GOT THE MESSAGE..");
SOAPPart soapPart = message.getSOAPPart();
System.err.println("OK GOT THE PART..");
SOAPEnvelope envelope = soapPart.getEnvelope();

and the output is this (showing the exception when i try to retrieve the
envelope..)

13:25:10,927 ERROR [STDERR] Now instantianting message..
13:25:10,977 ERROR [STDERR] OK GOT THE MESSAGE..
13:25:10,977 ERROR [STDERR] OK GOT THE PART..
13:25:11,007 ERROR [STDERR] Exception in reading stream: java.lang.NullPointerEx
ception

If i write my own PullParser that is just looking for the agency etc tags, it
works fine

so it looks like AXIS and ksoap cannot talk to each other...

is there a solution for parsing SOAP messages sent by ksoap client?

thanx in advance and regards
marco






> -----Original Message-----
> From: Mistroni Marco (NET-IMN/Espoo)
> Sent: 23 August, 2003 20:05
> To: 'kXML@xxxxxxxxxxx'
> Subject: help in parsing soap messages
>
> hi all,
> i am fairly new to ksoap. i have written 'two way' xml
> communication
> between a J2ME app (midp toolkit 2.0) and a serverside app
> implemented with struts
> on jboss.
> so far, i have been using my own xml format,but now i want to
> move to SOAP.
>
> writing SOAP from J2ME to serverside logic works fine, but
> now i have the problem
> of parsing the SOAP request.
>
> i have tried to use ksoap for parsing this simple XML
>
> <?xml version="1.0"?>
> <SOAP-ENV:Envelope
> xmlns:SOAP-ENV="http://www.w3.org/2001/12/soap-envelope";
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
> <SOAP-ENV:Body>
> <agencies>
> <agency>
> <name>name1</name>
> <tel>1234</tel>
> </agency>
> </agencies>
> </SOAP-ENV:Body>
> </SOAP-ENV:Envelope>
>
>
> i have followed what was said in previous email to have a
> look at SOAPEnvelope to see
> how to parse it.
> So, i copied the code from SOAPEnvelope and tried to
> customize for my own needs, using
> a the xml pullparser.
>
> but for some reason i keep on getting following exception
>
> Creating new AgencyImpl..
> Exception in thread "main"
> org.xmlpull.v1.XmlPullParserException: expected: END_
> TAG {http://www.w3.org/2001/12/soap-envelope}Body
> (position:START_TAG <agency> @
> 7:13)
> at org.kxml2.io.KXmlParser.exception(KXmlParser.java:228)
> at org.kxml2.io.KXmlParser.require(KXmlParser.java:1261)
> at com.tgmm.commons.SoapParser.parse(Unknown Source)
> at com.tgmm.commons.SoapParser.main(Unknown Source)
>
> i cannot figure out what's wrong. the XML seems ok, since i
> can see it in IE 5.5
>
> i can attach the code that i am using.... if anyone can help
> me in figuring out where is the problem.
>
>
> with best regards
> marco
>
> << File: SoapParser.java >>
>


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise