Re: kSOAP2 issue?

Stefan Haustein <[email protected]> Thu, 04 Mar 2004 11:40:23 +0100
Newsgroups gmane.comp.java.enhydra.ksoap
Message-ID <[email protected]>
Hi Michael,

I think reusing the envelope is not a good idea because of potential threading 
issues... Creating a new instance seems to be the best solution, but another 
problem is probably that the envelope is a member variable... So if doPosts 
overlap, still strange things may happen... :-/

Best regards,
Stefan

McCune, Michael wrote:
> I've been working with the kSOAP2 release, and I've encountered a
> problem related to the SoapServlet class.  SoapServlet.java declares the
> SoapSerializationEnvelope member variable, as below:
> 
> SoapSerializationEnvelope envelope = new
> SoapSerializationEnvelope(SoapSerializationEnvelope.VER12);
> 
> The servlet uses this class repeatedly every time that the doPost(...)
> method is called.  However, it seems like some member variables of
> SoapSerializationEnvelope need to be reset between requests.
> 
> Mainly, I'm concerned about the call: envelope.parse(parser);
> 
> Eventually, this calls parseBody(XmlPullParser parser) within
> SoapSerializationEnvelope.java. This method calls:
> 
> protected Object read(
>         XmlPullParser parser,
>         Object owner,
>         int index,
>         String namespace,
>         String name,
>         PropertyInfo expected)
>         throws IOException, XmlPullParserException
> 
> Within read(...), a Hashtable called idMap (which is a member variable
> of the class) is populated, etc.
> 
> When 2 SOAP requests are made (of the exact same type,etc.) in
> succession, then an exception is thrown because an object is found in
> the idMap which is not an instance of FwdRef ( the code is: else if (hlp
> != null) throw new RuntimeException("double ID"); ).
> 
> It seems like this mapping may need to be cleared between requests, and
> some synchronization might be required on the method calls, or a
> synchronized block could be used.
> 
> Right now, my workaround is (probably not the best) to create a new
> instance of SoapSerializationEnvelope under the doPost(...) method,
> every time doPost(...) is called:
> 
>        SoapSerializationEnvelope envelope = new
> SoapSerializationEnvelope(SoapSerializationEnvelope.VER12);
>         envelope.qNameToClass = this.envelope.qNameToClass;
>         envelope.classToQName = this.envelope.classToQName;
> 
> I changed qNameToClass and classToQName to have a public accessor.
> 
> Thanks,
> Mike
> 
> _______________________________________________
> Ksoap mailing list
> [email protected]
> http://www.enhydra.org/mailman/listinfo.cgi/ksoap