You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Rui Oliveira <ra...@gmail.com> on 2011/12/29 17:05:02 UTC

Array String parameter on SOAP Web Service

Hi

I'm new to Axis2, and i've developed a soap web service using Eclipse
Helios integration with Axis2 and tomcat. I've tried searching the mailing
list but no solution seemed to address my problem. This is why i send this
email since i don't know what to do anymore! :(

I'm trying to pass a string of array to the following web service function:

package pt.uc.dei.MyWebService;

public class MyWebService {
//other functions ignored
(...)

    public int getArray(String[]result) {
       return (result.length);
   }
}

The WSDL generated is attached with this email (it has definitions of other
operations but getArray is the one with the problem)


However when i use SOAPUI to generate a client. The default request that
SoapUI generate is:

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>xmlns:myw=
"http://MyWebService.dei.uc.pt" <http://mywebservice.dei.uc.pt/>>
    <soapenv:Header/>
         <soapenv:Body>
           <myw:getArray>
                <myw:result>?</myw:result>
           </myw:getArray>
         </soapenv:Body>
</soapenv:Envelope>


I've edited the soap envelop tag, and the request content inside result tag
it in order to support an array like this:

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>
xmlns:xsd="http://www.w3.org/2001/XMLSchema"<http://www.w3.org/2001/XMLSchema>xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"<http://www.w3.org/2001/XMLSchema-instance>xmlns:SOAP-ENC=
"http://schemas.xmlsoap.org/soap/encoding/"<http://schemas.xmlsoap.org/soap/encoding/>xmlns:myw=
"http://MyWebService.dei.uc.pt" <http://mywebservice.dei.uc.pt/>>
<soapenv:Header/>
  <soapenv:Body>
    <myw:getArray>
         <myw:result>
            <param SOAP-ENC:arrayType="xsd:string[4]" >
                 <item xsi:type="xsd:string">Egypt</item>
                 <item xsi:type="xsd:string">Amsterdam</item>
                 <item xsi:type="xsd:string">Lisbon</item>
                 <item xsi:type="xsd:string">Paris</item>
            </param>
         </myw:result>
    </myw:getArray>
  </soapenv:Body>
</soapenv:Envelope>

However the response i get from the getArray operation is :

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>>

   <soapenv:Body>
      <ns:getArrayResponse
xmlns:ns="http://MyWebService.dei.uc.pt"<http://mywebservice.dei.uc.pt/>>

          <ns:return>1</ns:return>
      </ns:getArrayResponse>
   </soapenv:Body>
</soapenv:Envelope>


It seems like the array of strings is being converted to one dimensional
empty Array, and i'm not receiving the strings inside the soap array from
the request.

Can anyone provide me what is causing this and if my request is being built
correctly?

Best Regards

Re: Array String parameter on SOAP Web Service

Posted by Rui Oliveira <ra...@gmail.com>.
Thank you Sagara and Raghu (again), your reply's helped me to know all i
wanted about axis handling of soap array's.

Best regards

On Wed, Jan 4, 2012 at 5:36 AM, Sagara Gunathunga <
sagara.gunathunga@gmail.com> wrote:

>  Axis2 does not support for  SOAP encoding hence you can't use arrayType
> attribute. As previous post mentioned you have to edit WSDL and use
> XMLSchema to specify your array constrains.
>
>  Thanks !
>
> On Wed, Jan 4, 2012 at 12:32 AM, Raghu Upadhyayula <
> rupadhyayula@responsys.com> wrote:
>
>>  I guess for that you have to modify your WSDL as follows and regenerate
>> the code from wsdl.****
>>
>> ** **
>>
>> <xs:element name="getArray">****
>>
>>     <xs:complexType>****
>>
>>         <xs:sequence>****
>>
>>             <xs:element *maxOccurs="4"* minOccurs="0" name="result"
>> nillable="true" type="xs:string" /> ****
>>
>>         </xs:sequence>****
>>
>>     </xs:complexType>****
>>
>> </xs:element>****
>>
>> ** **
>>
>> ** **
>>
>> Thanks****
>>
>> Raghu****
>>
>> [image: Description: cid:B80A849F-8953-4496-BB5B-34FFFD4B2394]<http://www.responsys.com/>
>> ****
>>
>> ** **
>>
>> *From:* Rui Oliveira [mailto:racoqster@gmail.com]
>> *Sent:* Tuesday, January 03, 2012 10:44 AM
>> *To:* java-user@axis.apache.org
>> *Subject:* Re: Array String parameter on SOAP Web Service****
>>
>> ** **
>>
>> Raghu
>>
>> Thanks! That worked it returned me 4 (the length of the array with all
>> the elements).
>>
>> However, this only addresses part of the problem.
>>
>> I would like to reserve a array with a fixed size like what was done with
>> my previous request example with:
>>
>> arrayType="xsd:string[4]"
>>
>>
>> For instance, i want the array to reserve 4 elements for the array and
>> not more.
>>
>> How i can do that?
>>
>> Best regards
>>
>> ****
>>
>> On Tue, Jan 3, 2012 at 6:26 PM, Raghu Upadhyayula <
>> rupadhyayula@responsys.com> wrote:****
>>
>> Hi Rui,****
>>
>>  ****
>>
>> Try this and see ….****
>>
>>  ****
>>
>> <soapenv:Envelope xmlns:soapenv=
>> "http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>xmlns:myw=
>> "http://MyWebService.dei.uc.pt" <http://mywebservice.dei.uc.pt/>>
>>     <soapenv:Header/>
>>          <soapenv:Body>
>>            <myw:getArray> ****
>>
>>                 <myw:result>Egypt</myw:result>
>>                 <myw:result>Amsterdam</myw:result>
>>                 <myw:result>Lisbon</myw:result>
>>                 <myw:result>Paris</myw:result> ****
>>
>>            </myw:getArray>
>>          </soapenv:Body>
>> </soapenv:Envelope>
>>
>> ****
>>
>>  ****
>>
>>  ****
>>
>> Thanks****
>>
>> Raghu****
>>
>>  ****
>>
>>  ****
>>
>> *From:* Rui Oliveira [mailto:racoqster@gmail.com]
>> *Sent:* Tuesday, January 03, 2012 9:46 AM
>> *To:* java-user@axis.apache.org****
>>
>>
>> *Subject:* Array String parameter on SOAP Web Service****
>>
>>  ****
>>
>> Sorry about bumping this thread but i really need a solution, or at least
>> the confirmation that i'm doing things right and this is a limitation of
>> Apache Axis2.****
>>
>> ---------- Forwarded message ----------
>> From: *Rui Oliveira* <ra...@gmail.com>
>> Date: Thu, Dec 29, 2011 at 4:05 PM
>> Subject: Array String parameter on SOAP Web Service
>> To: java-user@axis.apache.org
>>
>>
>> Hi
>>
>> I'm new to Axis2, and i've developed a soap web service using Eclipse
>> Helios integration with Axis2 and tomcat. I've tried searching the mailing
>> list but no solution seemed to address my problem. This is why i send this
>> email since i don't know what to do anymore! :(
>>
>> I'm trying to pass a string of array to the following web service
>> function:
>>
>> package pt.uc.dei.MyWebService;
>>
>> public class MyWebService {
>> //other functions ignored
>> (...)
>>
>>     public int getArray(String[]result) {
>>        return (result.length);
>>    }
>> }
>>
>> The WSDL generated is attached with this email (it has definitions of
>> other operations but getArray is the one with the problem)
>>
>>
>> However when i use SOAPUI to generate a client. The default request that
>> SoapUI generate is:
>>
>> <soapenv:Envelope xmlns:soapenv=
>> "http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>xmlns:myw=
>> "http://MyWebService.dei.uc.pt" <http://mywebservice.dei.uc.pt/>>
>>     <soapenv:Header/>
>>          <soapenv:Body>
>>            <myw:getArray>
>>                 <myw:result>?</myw:result>
>>            </myw:getArray>
>>          </soapenv:Body>
>> </soapenv:Envelope>
>>
>>
>> I've edited the soap envelop tag, and the request content inside result
>> tag it in order to support an array like this:
>>
>> <soapenv:Envelope xmlns:soapenv=
>> "http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>
>> xmlns:xsd="http://www.w3.org/2001/XMLSchema"<http://www.w3.org/2001/XMLSchema>xmlns:xsi=
>> "http://www.w3.org/2001/XMLSchema-instance"<http://www.w3.org/2001/XMLSchema-instance>xmlns:SOAP-ENC=
>> "http://schemas.xmlsoap.org/soap/encoding/"<http://schemas.xmlsoap.org/soap/encoding/>xmlns:myw=
>> "http://MyWebService.dei.uc.pt" <http://mywebservice.dei.uc.pt/>>
>> <soapenv:Header/>
>>   <soapenv:Body>
>>     <myw:getArray>
>>          <myw:result>
>>             <param SOAP-ENC:arrayType="xsd:string[4]" >
>>                  <item xsi:type="xsd:string">Egypt</item>
>>                  <item xsi:type="xsd:string">Amsterdam</item>
>>                  <item xsi:type="xsd:string">Lisbon</item>
>>                  <item xsi:type="xsd:string">Paris</item>
>>             </param>
>>          </myw:result>
>>     </myw:getArray>
>>   </soapenv:Body>
>> </soapenv:Envelope>
>>
>> However the response i get from the getArray operation is :
>>
>> <soapenv:Envelope xmlns:soapenv=
>> "http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>>
>>
>>    <soapenv:Body>
>>       <ns:getArrayResponse xmlns:ns="http://MyWebService.dei.uc.pt"<http://mywebservice.dei.uc.pt/>>
>>
>>           <ns:return>1</ns:return>
>>       </ns:getArrayResponse>
>>    </soapenv:Body>
>> </soapenv:Envelope>
>>
>>
>> It seems like the array of strings is being converted to one dimensional
>> empty Array, and i'm not receiving the strings inside the soap array from
>> the request.
>>
>> Can anyone provide me what is causing this and if my request is being
>> built correctly?
>>
>> Best Regards****
>>
>>  ****
>>
>> ** **
>>
>
>
>
> --
> Sagara Gunathunga
>
> Blog      - http://ssagara.blogspot.com
> Web      - http://people.apache.org/~sagara/
> LinkedIn - http://www.linkedin.com/in/ssagara
>

Re: Array String parameter on SOAP Web Service

Posted by Sagara Gunathunga <sa...@gmail.com>.
 Axis2 does not support for  SOAP encoding hence you can't use arrayType
attribute. As previous post mentioned you have to edit WSDL and use
XMLSchema to specify your array constrains.

 Thanks !

On Wed, Jan 4, 2012 at 12:32 AM, Raghu Upadhyayula <
rupadhyayula@responsys.com> wrote:

>  I guess for that you have to modify your WSDL as follows and regenerate
> the code from wsdl.****
>
> ** **
>
> <xs:element name="getArray">****
>
>     <xs:complexType>****
>
>         <xs:sequence>****
>
>             <xs:element *maxOccurs="4"* minOccurs="0" name="result"
> nillable="true" type="xs:string" /> ****
>
>         </xs:sequence>****
>
>     </xs:complexType>****
>
> </xs:element>****
>
> ** **
>
> ** **
>
> Thanks****
>
> Raghu****
>
> [image: Description: cid:B80A849F-8953-4496-BB5B-34FFFD4B2394]<http://www.responsys.com/>
> ****
>
> ** **
>
> *From:* Rui Oliveira [mailto:racoqster@gmail.com]
> *Sent:* Tuesday, January 03, 2012 10:44 AM
> *To:* java-user@axis.apache.org
> *Subject:* Re: Array String parameter on SOAP Web Service****
>
> ** **
>
> Raghu
>
> Thanks! That worked it returned me 4 (the length of the array with all the
> elements).
>
> However, this only addresses part of the problem.
>
> I would like to reserve a array with a fixed size like what was done with
> my previous request example with:
>
> arrayType="xsd:string[4]"
>
>
> For instance, i want the array to reserve 4 elements for the array and not
> more.
>
> How i can do that?
>
> Best regards
>
> ****
>
> On Tue, Jan 3, 2012 at 6:26 PM, Raghu Upadhyayula <
> rupadhyayula@responsys.com> wrote:****
>
> Hi Rui,****
>
>  ****
>
> Try this and see ….****
>
>  ****
>
> <soapenv:Envelope xmlns:soapenv=
> "http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>xmlns:myw=
> "http://MyWebService.dei.uc.pt" <http://mywebservice.dei.uc.pt/>>
>     <soapenv:Header/>
>          <soapenv:Body>
>            <myw:getArray> ****
>
>                 <myw:result>Egypt</myw:result>
>                 <myw:result>Amsterdam</myw:result>
>                 <myw:result>Lisbon</myw:result>
>                 <myw:result>Paris</myw:result> ****
>
>            </myw:getArray>
>          </soapenv:Body>
> </soapenv:Envelope>
>
> ****
>
>  ****
>
>  ****
>
> Thanks****
>
> Raghu****
>
>  ****
>
>  ****
>
> *From:* Rui Oliveira [mailto:racoqster@gmail.com]
> *Sent:* Tuesday, January 03, 2012 9:46 AM
> *To:* java-user@axis.apache.org****
>
>
> *Subject:* Array String parameter on SOAP Web Service****
>
>  ****
>
> Sorry about bumping this thread but i really need a solution, or at least
> the confirmation that i'm doing things right and this is a limitation of
> Apache Axis2.****
>
> ---------- Forwarded message ----------
> From: *Rui Oliveira* <ra...@gmail.com>
> Date: Thu, Dec 29, 2011 at 4:05 PM
> Subject: Array String parameter on SOAP Web Service
> To: java-user@axis.apache.org
>
>
> Hi
>
> I'm new to Axis2, and i've developed a soap web service using Eclipse
> Helios integration with Axis2 and tomcat. I've tried searching the mailing
> list but no solution seemed to address my problem. This is why i send this
> email since i don't know what to do anymore! :(
>
> I'm trying to pass a string of array to the following web service
> function:
>
> package pt.uc.dei.MyWebService;
>
> public class MyWebService {
> //other functions ignored
> (...)
>
>     public int getArray(String[]result) {
>        return (result.length);
>    }
> }
>
> The WSDL generated is attached with this email (it has definitions of
> other operations but getArray is the one with the problem)
>
>
> However when i use SOAPUI to generate a client. The default request that
> SoapUI generate is:
>
> <soapenv:Envelope xmlns:soapenv=
> "http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>xmlns:myw=
> "http://MyWebService.dei.uc.pt" <http://mywebservice.dei.uc.pt/>>
>     <soapenv:Header/>
>          <soapenv:Body>
>            <myw:getArray>
>                 <myw:result>?</myw:result>
>            </myw:getArray>
>          </soapenv:Body>
> </soapenv:Envelope>
>
>
> I've edited the soap envelop tag, and the request content inside result
> tag it in order to support an array like this:
>
> <soapenv:Envelope xmlns:soapenv=
> "http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"<http://www.w3.org/2001/XMLSchema>xmlns:xsi=
> "http://www.w3.org/2001/XMLSchema-instance"<http://www.w3.org/2001/XMLSchema-instance>xmlns:SOAP-ENC=
> "http://schemas.xmlsoap.org/soap/encoding/"<http://schemas.xmlsoap.org/soap/encoding/>xmlns:myw=
> "http://MyWebService.dei.uc.pt" <http://mywebservice.dei.uc.pt/>>
> <soapenv:Header/>
>   <soapenv:Body>
>     <myw:getArray>
>          <myw:result>
>             <param SOAP-ENC:arrayType="xsd:string[4]" >
>                  <item xsi:type="xsd:string">Egypt</item>
>                  <item xsi:type="xsd:string">Amsterdam</item>
>                  <item xsi:type="xsd:string">Lisbon</item>
>                  <item xsi:type="xsd:string">Paris</item>
>             </param>
>          </myw:result>
>     </myw:getArray>
>   </soapenv:Body>
> </soapenv:Envelope>
>
> However the response i get from the getArray operation is :
>
> <soapenv:Envelope xmlns:soapenv=
> "http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>>
>
>    <soapenv:Body>
>       <ns:getArrayResponse xmlns:ns="http://MyWebService.dei.uc.pt"<http://mywebservice.dei.uc.pt/>>
>
>           <ns:return>1</ns:return>
>       </ns:getArrayResponse>
>    </soapenv:Body>
> </soapenv:Envelope>
>
>
> It seems like the array of strings is being converted to one dimensional
> empty Array, and i'm not receiving the strings inside the soap array from
> the request.
>
> Can anyone provide me what is causing this and if my request is being
> built correctly?
>
> Best Regards****
>
>  ****
>
> ** **
>



-- 
Sagara Gunathunga

Blog      - http://ssagara.blogspot.com
Web      - http://people.apache.org/~sagara/
LinkedIn - http://www.linkedin.com/in/ssagara

RE: Array String parameter on SOAP Web Service

Posted by Raghu Upadhyayula <ru...@responsys.com>.
I guess for that you have to modify your WSDL as follows and regenerate the code from wsdl.

<xs:element name="getArray">
    <xs:complexType>
        <xs:sequence>
            <xs:element maxOccurs="4" minOccurs="0" name="result" nillable="true" type="xs:string" />
        </xs:sequence>
    </xs:complexType>
</xs:element>


Thanks
Raghu
[Description: cid:B80A849F-8953-4496-BB5B-34FFFD4B2394]<http://www.responsys.com/>

From: Rui Oliveira [mailto:racoqster@gmail.com]
Sent: Tuesday, January 03, 2012 10:44 AM
To: java-user@axis.apache.org
Subject: Re: Array String parameter on SOAP Web Service

Raghu

Thanks! That worked it returned me 4 (the length of the array with all the elements).

However, this only addresses part of the problem.

I would like to reserve a array with a fixed size like what was done with my previous request example with:

arrayType="xsd:string[4]"


For instance, i want the array to reserve 4 elements for the array and not more.

How i can do that?

Best regards

On Tue, Jan 3, 2012 at 6:26 PM, Raghu Upadhyayula <ru...@responsys.com>> wrote:
Hi Rui,

Try this and see ....

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/> xmlns:myw="http://MyWebService.dei.uc.pt"<http://mywebservice.dei.uc.pt/>>
    <soapenv:Header/>
         <soapenv:Body>
           <myw:getArray>
                <myw:result>Egypt</myw:result>
                <myw:result>Amsterdam</myw:result>
                <myw:result>Lisbon</myw:result>
                <myw:result>Paris</myw:result>
           </myw:getArray>
         </soapenv:Body>
</soapenv:Envelope>



Thanks
Raghu


From: Rui Oliveira [mailto:racoqster@gmail.com<ma...@gmail.com>]
Sent: Tuesday, January 03, 2012 9:46 AM
To: java-user@axis.apache.org<ma...@axis.apache.org>

Subject: Array String parameter on SOAP Web Service

Sorry about bumping this thread but i really need a solution, or at least the confirmation that i'm doing things right and this is a limitation of  Apache Axis2.
---------- Forwarded message ----------
From: Rui Oliveira <ra...@gmail.com>>
Date: Thu, Dec 29, 2011 at 4:05 PM
Subject: Array String parameter on SOAP Web Service
To: java-user@axis.apache.org<ma...@axis.apache.org>


Hi

I'm new to Axis2, and i've developed a soap web service using Eclipse Helios integration with Axis2 and tomcat. I've tried searching the mailing list but no solution seemed to address my problem. This is why i send this email since i don't know what to do anymore! :(

I'm trying to pass a string of array to the following web service function:

package pt.uc.dei.MyWebService;

public class MyWebService {
//other functions ignored
(...)

    public int getArray(String[]result) {
       return (result.length);
   }
}

The WSDL generated is attached with this email (it has definitions of other operations but getArray is the one with the problem)


However when i use SOAPUI to generate a client. The default request that SoapUI generate is:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/> xmlns:myw="http://MyWebService.dei.uc.pt"<http://mywebservice.dei.uc.pt/>>
    <soapenv:Header/>
         <soapenv:Body>
           <myw:getArray>
                <myw:result>?</myw:result>
           </myw:getArray>
         </soapenv:Body>
</soapenv:Envelope>


I've edited the soap envelop tag, and the request content inside result tag it in order to support an array like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>  xmlns:xsd="http://www.w3.org/2001/XMLSchema"<http://www.w3.org/2001/XMLSchema> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<http://www.w3.org/2001/XMLSchema-instance> xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"<http://schemas.xmlsoap.org/soap/encoding/> xmlns:myw="http://MyWebService.dei.uc.pt"<http://mywebservice.dei.uc.pt/>>
<soapenv:Header/>
  <soapenv:Body>
    <myw:getArray>
         <myw:result>
            <param SOAP-ENC:arrayType="xsd:string[4]" >
                 <item xsi:type="xsd:string">Egypt</item>
                 <item xsi:type="xsd:string">Amsterdam</item>
                 <item xsi:type="xsd:string">Lisbon</item>
                 <item xsi:type="xsd:string">Paris</item>
            </param>
         </myw:result>
    </myw:getArray>
  </soapenv:Body>
</soapenv:Envelope>

However the response i get from the getArray operation is :

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>>
   <soapenv:Body>
      <ns:getArrayResponse xmlns:ns="http://MyWebService.dei.uc.pt"<http://mywebservice.dei.uc.pt/>>
          <ns:return>1</ns:return>
      </ns:getArrayResponse>
   </soapenv:Body>
</soapenv:Envelope>


It seems like the array of strings is being converted to one dimensional empty Array, and i'm not receiving the strings inside the soap array from the request.

Can anyone provide me what is causing this and if my request is being built correctly?

Best Regards



Re: Array String parameter on SOAP Web Service

Posted by Rui Oliveira <ra...@gmail.com>.
Raghu

Thanks! That worked it returned me 4 (the length of the array with all the
elements).

However, this only addresses part of the problem.

I would like to reserve a array with a fixed size like what was done with
my previous request example with:

arrayType="xsd:string[4]"


For instance, i want the array to reserve 4 elements for the array and not
more.

How i can do that?

Best regards


On Tue, Jan 3, 2012 at 6:26 PM, Raghu Upadhyayula <
rupadhyayula@responsys.com> wrote:

>  Hi Rui,****
>
> ** **
>
> Try this and see ….****
>
> ** **
>
> <soapenv:Envelope xmlns:soapenv=
> "http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>xmlns:myw=
> "http://MyWebService.dei.uc.pt" <http://mywebservice.dei.uc.pt/>>
>     <soapenv:Header/>
>          <soapenv:Body>
>            <myw:getArray>
>                 <myw:result>Egypt</myw:result>
>                 <myw:result>Amsterdam</myw:result>
>                 <myw:result>Lisbon</myw:result>
>                 <myw:result>Paris</myw:result>
>            </myw:getArray>
>          </soapenv:Body>
> </soapenv:Envelope>
>
>
> ****
>
> ** **
>
> ** **
>
> Thanks****
>
> Raghu****
>
> ** **
>
> ** **
>
> *From:* Rui Oliveira [mailto:racoqster@gmail.com]
> *Sent:* Tuesday, January 03, 2012 9:46 AM
> *To:* java-user@axis.apache.org
>
> *Subject:* Array String parameter on SOAP Web Service****
>
> ** **
>
> Sorry about bumping this thread but i really need a solution, or at least
> the confirmation that i'm doing things right and this is a limitation of
> Apache Axis2.****
>
> ---------- Forwarded message ----------
> From: *Rui Oliveira* <ra...@gmail.com>
> Date: Thu, Dec 29, 2011 at 4:05 PM
> Subject: Array String parameter on SOAP Web Service
> To: java-user@axis.apache.org
>
>
> Hi
>
> I'm new to Axis2, and i've developed a soap web service using Eclipse
> Helios integration with Axis2 and tomcat. I've tried searching the mailing
> list but no solution seemed to address my problem. This is why i send this
> email since i don't know what to do anymore! :(
>
> I'm trying to pass a string of array to the following web service
> function:
>
> package pt.uc.dei.MyWebService;
>
> public class MyWebService {
> //other functions ignored
> (...)
>
>     public int getArray(String[]result) {
>        return (result.length);
>    }
> }
>
> The WSDL generated is attached with this email (it has definitions of
> other operations but getArray is the one with the problem)
>
>
> However when i use SOAPUI to generate a client. The default request that
> SoapUI generate is:
>
> <soapenv:Envelope xmlns:soapenv=
> "http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>xmlns:myw=
> "http://MyWebService.dei.uc.pt" <http://mywebservice.dei.uc.pt/>>
>     <soapenv:Header/>
>          <soapenv:Body>
>            <myw:getArray>
>                 <myw:result>?</myw:result>
>            </myw:getArray>
>          </soapenv:Body>
> </soapenv:Envelope>
>
>
> I've edited the soap envelop tag, and the request content inside result
> tag it in order to support an array like this:
>
> <soapenv:Envelope xmlns:soapenv=
> "http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"<http://www.w3.org/2001/XMLSchema>xmlns:xsi=
> "http://www.w3.org/2001/XMLSchema-instance"<http://www.w3.org/2001/XMLSchema-instance>xmlns:SOAP-ENC=
> "http://schemas.xmlsoap.org/soap/encoding/"<http://schemas.xmlsoap.org/soap/encoding/>xmlns:myw=
> "http://MyWebService.dei.uc.pt" <http://mywebservice.dei.uc.pt/>>
> <soapenv:Header/>
>   <soapenv:Body>
>     <myw:getArray>
>          <myw:result>
>             <param SOAP-ENC:arrayType="xsd:string[4]" >
>                  <item xsi:type="xsd:string">Egypt</item>
>                  <item xsi:type="xsd:string">Amsterdam</item>
>                  <item xsi:type="xsd:string">Lisbon</item>
>                  <item xsi:type="xsd:string">Paris</item>
>             </param>
>          </myw:result>
>     </myw:getArray>
>   </soapenv:Body>
> </soapenv:Envelope>
>
> However the response i get from the getArray operation is :
>
> <soapenv:Envelope xmlns:soapenv=
> "http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>>
>
>    <soapenv:Body>
>       <ns:getArrayResponse xmlns:ns="http://MyWebService.dei.uc.pt"<http://mywebservice.dei.uc.pt/>>
>
>           <ns:return>1</ns:return>
>       </ns:getArrayResponse>
>    </soapenv:Body>
> </soapenv:Envelope>
>
>
> It seems like the array of strings is being converted to one dimensional
> empty Array, and i'm not receiving the strings inside the soap array from
> the request.
>
> Can anyone provide me what is causing this and if my request is being
> built correctly?
>
> Best Regards****
>
> ** **
>

RE: Array String parameter on SOAP Web Service

Posted by Raghu Upadhyayula <ru...@responsys.com>.
Hi Rui,

Try this and see ....

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/> xmlns:myw="http://MyWebService.dei.uc.pt"<http://mywebservice.dei.uc.pt/>>
    <soapenv:Header/>
         <soapenv:Body>
           <myw:getArray>
                <myw:result>Egypt</myw:result>
                <myw:result>Amsterdam</myw:result>
                <myw:result>Lisbon</myw:result>
                <myw:result>Paris</myw:result>
           </myw:getArray>
         </soapenv:Body>
</soapenv:Envelope>




Thanks
Raghu


From: Rui Oliveira [mailto:racoqster@gmail.com]
Sent: Tuesday, January 03, 2012 9:46 AM
To: java-user@axis.apache.org
Subject: Array String parameter on SOAP Web Service

Sorry about bumping this thread but i really need a solution, or at least the confirmation that i'm doing things right and this is a limitation of  Apache Axis2.
---------- Forwarded message ----------
From: Rui Oliveira <ra...@gmail.com>>
Date: Thu, Dec 29, 2011 at 4:05 PM
Subject: Array String parameter on SOAP Web Service
To: java-user@axis.apache.org<ma...@axis.apache.org>


Hi

I'm new to Axis2, and i've developed a soap web service using Eclipse Helios integration with Axis2 and tomcat. I've tried searching the mailing list but no solution seemed to address my problem. This is why i send this email since i don't know what to do anymore! :(

I'm trying to pass a string of array to the following web service function:

package pt.uc.dei.MyWebService;

public class MyWebService {
//other functions ignored
(...)

    public int getArray(String[]result) {
       return (result.length);
   }
}

The WSDL generated is attached with this email (it has definitions of other operations but getArray is the one with the problem)


However when i use SOAPUI to generate a client. The default request that SoapUI generate is:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/> xmlns:myw="http://MyWebService.dei.uc.pt"<http://mywebservice.dei.uc.pt/>>
    <soapenv:Header/>
         <soapenv:Body>
           <myw:getArray>
                <myw:result>?</myw:result>
           </myw:getArray>
         </soapenv:Body>
</soapenv:Envelope>


I've edited the soap envelop tag, and the request content inside result tag it in order to support an array like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>  xmlns:xsd="http://www.w3.org/2001/XMLSchema"<http://www.w3.org/2001/XMLSchema> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<http://www.w3.org/2001/XMLSchema-instance> xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"<http://schemas.xmlsoap.org/soap/encoding/> xmlns:myw="http://MyWebService.dei.uc.pt"<http://mywebservice.dei.uc.pt/>>
<soapenv:Header/>
  <soapenv:Body>
    <myw:getArray>
         <myw:result>
            <param SOAP-ENC:arrayType="xsd:string[4]" >
                 <item xsi:type="xsd:string">Egypt</item>
                 <item xsi:type="xsd:string">Amsterdam</item>
                 <item xsi:type="xsd:string">Lisbon</item>
                 <item xsi:type="xsd:string">Paris</item>
            </param>
         </myw:result>
    </myw:getArray>
  </soapenv:Body>
</soapenv:Envelope>

However the response i get from the getArray operation is :

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>>
   <soapenv:Body>
      <ns:getArrayResponse xmlns:ns="http://MyWebService.dei.uc.pt"<http://mywebservice.dei.uc.pt/>>
          <ns:return>1</ns:return>
      </ns:getArrayResponse>
   </soapenv:Body>
</soapenv:Envelope>


It seems like the array of strings is being converted to one dimensional empty Array, and i'm not receiving the strings inside the soap array from the request.

Can anyone provide me what is causing this and if my request is being built correctly?

Best Regards


Array String parameter on SOAP Web Service

Posted by Rui Oliveira <ra...@gmail.com>.
Sorry about bumping this thread but i really need a solution, or at least
the confirmation that i'm doing things right and this is a limitation of
Apache Axis2.

---------- Forwarded message ----------
From: Rui Oliveira <ra...@gmail.com>
Date: Thu, Dec 29, 2011 at 4:05 PM
Subject: Array String parameter on SOAP Web Service
To: java-user@axis.apache.org


Hi

I'm new to Axis2, and i've developed a soap web service using Eclipse
Helios integration with Axis2 and tomcat. I've tried searching the mailing
list but no solution seemed to address my problem. This is why i send this
email since i don't know what to do anymore! :(

I'm trying to pass a string of array to the following web service function:

package pt.uc.dei.MyWebService;

public class MyWebService {
//other functions ignored
(...)

    public int getArray(String[]result) {
       return (result.length);
   }
}

The WSDL generated is attached with this email (it has definitions of other
operations but getArray is the one with the problem)


However when i use SOAPUI to generate a client. The default request that
SoapUI generate is:

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>xmlns:myw=
"http://MyWebService.dei.uc.pt" <http://mywebservice.dei.uc.pt/>>
    <soapenv:Header/>
         <soapenv:Body>
           <myw:getArray>
                <myw:result>?</myw:result>
           </myw:getArray>
         </soapenv:Body>
</soapenv:Envelope>


I've edited the soap envelop tag, and the request content inside result tag
it in order to support an array like this:

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>
xmlns:xsd="http://www.w3.org/2001/XMLSchema"<http://www.w3.org/2001/XMLSchema>xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"<http://www.w3.org/2001/XMLSchema-instance>xmlns:SOAP-ENC=
"http://schemas.xmlsoap.org/soap/encoding/"<http://schemas.xmlsoap.org/soap/encoding/>xmlns:myw=
"http://MyWebService.dei.uc.pt" <http://mywebservice.dei.uc.pt/>>
<soapenv:Header/>
  <soapenv:Body>
    <myw:getArray>
         <myw:result>
            <param SOAP-ENC:arrayType="xsd:string[4]" >
                 <item xsi:type="xsd:string">Egypt</item>
                 <item xsi:type="xsd:string">Amsterdam</item>
                 <item xsi:type="xsd:string">Lisbon</item>
                 <item xsi:type="xsd:string">Paris</item>
            </param>
         </myw:result>
    </myw:getArray>
  </soapenv:Body>
</soapenv:Envelope>

However the response i get from the getArray operation is :

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>>

   <soapenv:Body>
      <ns:getArrayResponse
xmlns:ns="http://MyWebService.dei.uc.pt"<http://mywebservice.dei.uc.pt/>>

          <ns:return>1</ns:return>
      </ns:getArrayResponse>
   </soapenv:Body>
</soapenv:Envelope>


It seems like the array of strings is being converted to one dimensional
empty Array, and i'm not receiving the strings inside the soap array from
the request.

Can anyone provide me what is causing this and if my request is being built
correctly?

Best Regards

[Axis2] Array String parameter on SOAP Web Service

Posted by Rui Oliveira <ra...@gmail.com>.
Since i'm really needing a reply to my research project and no one at the
Axis2 User List managed to reply, i ask here help for the specific problem
i explain below, about developing java web services with Soap array as
parameters.

For the record, i'm using Apache Axis2 1.6.1 build


---------- Forwarded message ----------
From: Rui Oliveira <ra...@gmail.com>
Date: Thu, Dec 29, 2011 at 4:05 PM
Subject: Array String parameter on SOAP Web Service
To: java-user@axis.apache.org


Hi

I'm new to Axis2, and i've developed a soap web service using Eclipse
Helios integration with Axis2 and tomcat. I've tried searching the mailing
list but no solution seemed to address my problem. This is why i send this
email since i don't know what to do anymore! :(

I'm trying to pass a string of array to the following web service function:

package pt.uc.dei.MyWebService;

public class MyWebService {
//other functions ignored
(...)

    public int getArray(String[]result) {
       return (result.length);
   }
}

The WSDL generated is attached with this email (it has definitions of other
operations but getArray is the one with the problem)


However when i use SOAPUI to generate a client. The default request that
SoapUI generate is:

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>xmlns:myw=
"http://MyWebService.dei.uc.pt" <http://mywebservice.dei.uc.pt/>>
    <soapenv:Header/>
         <soapenv:Body>
           <myw:getArray>
                <myw:result>?</myw:result>
           </myw:getArray>
         </soapenv:Body>
</soapenv:Envelope>


I've edited the soap envelop tag, and the request content inside result tag
it in order to support an array like this:

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>
xmlns:xsd="http://www.w3.org/2001/XMLSchema"<http://www.w3.org/2001/XMLSchema>xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"<http://www.w3.org/2001/XMLSchema-instance>xmlns:SOAP-ENC=
"http://schemas.xmlsoap.org/soap/encoding/"<http://schemas.xmlsoap.org/soap/encoding/>xmlns:myw=
"http://MyWebService.dei.uc.pt" <http://mywebservice.dei.uc.pt/>>
<soapenv:Header/>
  <soapenv:Body>
    <myw:getArray>
         <myw:result>
            <param SOAP-ENC:arrayType="xsd:string[4]" >
                 <item xsi:type="xsd:string">Egypt</item>
                 <item xsi:type="xsd:string">Amsterdam</item>
                 <item xsi:type="xsd:string">Lisbon</item>
                 <item xsi:type="xsd:string">Paris</item>
            </param>
         </myw:result>
    </myw:getArray>
  </soapenv:Body>
</soapenv:Envelope>

However the response i get from the getArray operation is :

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"<http://schemas.xmlsoap.org/soap/envelope/>>

   <soapenv:Body>
      <ns:getArrayResponse
xmlns:ns="http://MyWebService.dei.uc.pt"<http://mywebservice.dei.uc.pt/>>

          <ns:return>1</ns:return>
      </ns:getArrayResponse>
   </soapenv:Body>
</soapenv:Envelope>


It seems like the array of strings is being converted to one dimensional
empty Array, and i'm not receiving the strings inside the soap array from
the request.

Can anyone provide me what is causing this and if my request is being built
correctly?

Best Regards

Re: Database connection pooling

Posted by Ted Zeng <ze...@adobe.com>.
Hi Deepal,

I read the following line:
"When using a connection pool, closing the connection just returns it to the pool for reuse by another request, it doesn't close the connection."
>From http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html

So returning the connection to the pool is the same as closing it?

I do see exception "org.apache.tomcat.jdbc.pool.ConnectionPool abandon" from time to time when I try to get a connection. I need to look at this.

Extra words: I saw you are the creator of Axis2. I would like to express my appreciation for your great work.
I used SOAP 10 years ago to create a test automation framework which has been using since. I used Perl SOAP module.
It was very hard to use. It made me afraid to use SOAP. This time around, I found Axis2 and installed and started to use it
In almost no time. And it works much better than I expected. It is hard to describe the feeling when I saw my own module running in Axis2.
Thank you!

Best,

-ted

On 12/30/11 2:16 PM, "Deepal Jayasinghe" <de...@opensource.lk> wrote:

 Hi Ted,

 Managing database connections (or any other types of connection) entirely up to the service author. He can write his service and manage connection as he wish. However, since Axis2 has the notion of session management, if you create and store your DB connections inside the service impl class then depending on the session type (whether transport, application, request etc) lifetime of a DB connection varies. That is why we have introduced ServiceLifeCycle class, once you store your DB connection inside the serviceLifeCycle it will be there until you restart your application.

 Regarding the connection pool, you do not need to close DB connection every time when you use it, you can store them in the pool and put them back to the pool after each usage.

 On 12/30/2011 2:49 PM, Ted Zeng wrote:
Database connection pooling Hi all,

 I am new to Axis2 and database connection pooling.
 I read the article "Exposing a Database as a Web Service" by Deepal Jayasinghe. Thanks to Deepal otherwise I don't know where to start.
 Then I used the sample code there and modified for my use.
 Everything works well except the database connection timeout.

 Most articles about connection pool is using app. Server. But I use the stand alone Axis2.
 So no help there. In fact, a question "DB connection pool in Standalone Axis2?" in stackoverflow.com never gets answered.

  After quite a bit of reading and searching Axis2 source, I realized that the following statement
 configctx.setProperty(DB_CONNECTION, conn);
 Did nothing more than store the connection object for later retrieval. For whatever reason, I kept thinking
 The ServiceLifeCycle helps managing the database connection.

 Then I looked up the DB connection pool and choose org.apache.tomcat.jdbc.pool to implement the pooling.
 Here is what I did to implement the DB connection pool (pretty much the same as the sample code in tomcat jdbc pool website).
 First, I set up the DataSource and store it instead of connection in ServiceLifeCycle.

               Class.forName("com.mysql.jdbc.Driver");
             // Creating the DB connection for our DB
                 PoolProperties p = new PoolProperties();
                p.setUrl("jdbc:mysql://localhost:3306/AndroidAuto?autoReconnect=true");
                 p.setDriverClassName("com.mysql.jdbc.Driver");
                 ..
                 p.setJmxEnabled(true);
                 p.setTestOnBorrow(true);
                 p.setValidationQuery("SELECT 1");
                 p.setValidationInterval(30000);
                 p.setTimeBetweenEvictionRunsMillis(30000);
                 p.setMaxActive(100);
                 p.setInitialSize(10);
                 ..
                p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"+
                  "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
                 DataSource datasource = new DataSource();
                 datasource.setPoolProperties(p);
                 //Storing the DB in the ConfigurationContext
                 configctx.setProperty(DB_DATASOURCE, datasource);

 Then the datasource is retrieved and connection is created from it. After DB operation,
 The connection is closed and returned to the pool. I am not sure if this is the right way to implement
 DB conn pool in Axis2.

         DataSource datasource = (DataSource) MessageContext.getCurrentMessageContext().getProperty(
                 DBServiceLifeCycle.DB_DATASOURCE);
         Connection conn = null;
         try {
             conn = datasource.getConnection();
             String SQL = "SELECT xxx  FROM Devices";
             PreparedStatement statement = conn.prepareStatement(SQL);
             ResultSet result = statement.executeQuery();
             ... (get the result)
             result.close();
             statement.close();
             return (String[])list.toArray(new String[list.size()]);
         } catch (SQLException e) {
             e.printStackTrace();
         }finally {
           if (conn!=null) try {conn.close();}catch (Exception ignore) {}
         }

 I hope my approach is right. I am testing the code. Not sure why the first call take a couple of seconds. But
 Fine after that. I need to wait to 6 hours (I don't know how to modify the mysql timeout yet) to test the Timeout condition.

 Thanks,

 Happy Holiday!

 Ted Zeng
 Adobe Systems




Re: Database connection pooling

Posted by Deepal Jayasinghe <de...@opensource.lk>.
Hi Ted,

Managing database connections (or any other types of connection)
entirely up to the service author. He can write his service and manage
connection as he wish. However, since Axis2 has the notion of session
management, if you create and store your DB connections inside the
service impl class then depending on the session type (whether
transport, application, request etc) lifetime of a DB connection varies.
That is why we have introduced ServiceLifeCycle class, once you store
your DB connection inside the serviceLifeCycle it will be there until
you restart your application.

Regarding the connection pool, you do not need to close DB connection
every time when you use it, you can store them in the pool and put them
back to the pool after each usage.

On 12/30/2011 2:49 PM, Ted Zeng wrote:
> Hi all,
>
> I am new to Axis2 and database connection pooling.
> I read the article "Exposing a Database as a Web Service" by Deepal
> Jayasinghe. Thanks to Deepal otherwise I don't know where to start.
> Then I used the sample code there and modified for my use.
> Everything works well except the database connection timeout.
>
> Most articles about connection pool is using app. Server. But I use
> the stand alone Axis2.
> So no help there. In fact, a question "DB connection pool in
> Standalone Axis2?" in stackoverflow.com never gets answered.
>
>  After quite a bit of reading and searching Axis2 source, I realized
> that the following statement
> configctx.setProperty(DB_CONNECTION, conn);
> Did nothing more than store the connection object for later retrieval.
> For whatever reason, I kept thinking
> The ServiceLifeCycle helps managing the database connection.
>
> Then I looked up the DB connection pool and choose
> org.apache.tomcat.jdbc.pool to implement the pooling.
> Here is what I did to implement the DB connection pool (pretty much
> the same as the sample code in tomcat jdbc pool website).
> First, I set up the DataSource and store it instead of connection in
> ServiceLifeCycle.
>
>               Class.forName("com.mysql.jdbc.Driver");
>             // Creating the DB connection for our DB
>                 PoolProperties p = new PoolProperties();
>                 p.setUrl("jdbc:mysql://localhost:3306/AndroidAuto?autoReconnect=true");
>                 p.setDriverClassName("com.mysql.jdbc.Driver");
>                 ..
>                 p.setJmxEnabled(true);
>                 p.setTestOnBorrow(true);
>                 p.setValidationQuery("SELECT 1");
>                 p.setValidationInterval(30000);
>                 p.setTimeBetweenEvictionRunsMillis(30000);
>                 p.setMaxActive(100);
>                 p.setInitialSize(10);
>                 ..
>                 p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"+
>                   "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
>                 DataSource datasource = new DataSource();
>                 datasource.setPoolProperties(p);
>                 //Storing the DB in the ConfigurationContext
>                 configctx.setProperty(DB_DATASOURCE, datasource);
>           
>
> Then the datasource is retrieved and connection is created from it.
> After DB operation,
> The connection is closed and returned to the pool. I am not sure if
> this is the right way to implement
> DB conn pool in Axis2.
>
>         DataSource datasource = (DataSource)
> MessageContext.getCurrentMessageContext().getProperty(
>                 DBServiceLifeCycle.DB_DATASOURCE);
>         Connection conn = null;
>         try {
>             conn = datasource.getConnection();
>             String SQL = "SELECT xxx  FROM Devices";
>             PreparedStatement statement = conn.prepareStatement(SQL);
>             ResultSet result = statement.executeQuery();
>             ... (get the result)
>             result.close();
>             statement.close();
>             return (String[])list.toArray(new String[list.size()]);
>         } catch (SQLException e) {
>             e.printStackTrace();
>         }finally {
>           if (conn!=null) try {conn.close();}catch (Exception ignore) {}
>         }
>
> I hope my approach is right. I am testing the code. Not sure why the
> first call take a couple of seconds. But
> Fine after that. I need to wait to 6 hours (I don't know how to modify
> the mysql timeout yet) to test the Timeout condition.
>
> Thanks,
>
> Happy Holiday!
>
> Ted Zeng
> Adobe Systems

-- 
Blog - http://blogs.deepal.org/

Database connection pooling

Posted by Ted Zeng <ze...@adobe.com>.
Hi all,

I am new to Axis2 and database connection pooling.
I read the article "Exposing a Database as a Web Service" by Deepal Jayasinghe. Thanks to Deepal otherwise I don't know where to start.
Then I used the sample code there and modified for my use.
Everything works well except the database connection timeout.

Most articles about connection pool is using app. Server. But I use the stand alone Axis2.
So no help there. In fact, a question "DB connection pool in Standalone Axis2?" in stackoverflow.com never gets answered.

 After quite a bit of reading and searching Axis2 source, I realized that the following statement
configctx.setProperty(DB_CONNECTION, conn);
Did nothing more than store the connection object for later retrieval. For whatever reason, I kept thinking
The ServiceLifeCycle helps managing the database connection.

Then I looked up the DB connection pool and choose org.apache.tomcat.jdbc.pool to implement the pooling.
Here is what I did to implement the DB connection pool (pretty much the same as the sample code in tomcat jdbc pool website).
First, I set up the DataSource and store it instead of connection in ServiceLifeCycle.

              Class.forName("com.mysql.jdbc.Driver");
            // Creating the DB connection for our DB
                PoolProperties p = new PoolProperties();
                p.setUrl("jdbc:mysql://localhost:3306/AndroidAuto?autoReconnect=true");
                p.setDriverClassName("com.mysql.jdbc.Driver");
                ..
                p.setJmxEnabled(true);
                p.setTestOnBorrow(true);
                p.setValidationQuery("SELECT 1");
                p.setValidationInterval(30000);
                p.setTimeBetweenEvictionRunsMillis(30000);
                p.setMaxActive(100);
                p.setInitialSize(10);
                ..
                p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"+
                  "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
                DataSource datasource = new DataSource();
                datasource.setPoolProperties(p);
                //Storing the DB in the ConfigurationContext
                configctx.setProperty(DB_DATASOURCE, datasource);

Then the datasource is retrieved and connection is created from it. After DB operation,
The connection is closed and returned to the pool. I am not sure if this is the right way to implement
DB conn pool in Axis2.

        DataSource datasource = (DataSource) MessageContext.getCurrentMessageContext().getProperty(
                DBServiceLifeCycle.DB_DATASOURCE);
        Connection conn = null;
        try {
            conn = datasource.getConnection();
            String SQL = "SELECT xxx  FROM Devices";
            PreparedStatement statement = conn.prepareStatement(SQL);
            ResultSet result = statement.executeQuery();
            ... (get the result)
            result.close();
            statement.close();
            return (String[])list.toArray(new String[list.size()]);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
          if (conn!=null) try {conn.close();}catch (Exception ignore) {}
        }

I hope my approach is right. I am testing the code. Not sure why the first call take a couple of seconds. But
Fine after that. I need to wait to 6 hours (I don't know how to modify the mysql timeout yet) to test the Timeout condition.

Thanks,

Happy Holiday!

Ted Zeng
Adobe Systems