Monday, October 4, 2010

Test Web Services thru Telnet

I use Mac OS X here, so other OS's might vary but I think in Linux, it is still ppp0 (but not sure with that) for VPN connection interface.

1. First, I use Wireshark in order to capture the packets.
2. Afterwards, I use the ppp0 interface (Mac OS X) then start
3. Now connect thru telnet by example:

telnet 192.168.10.51 8080


4. Then paste the example POST


POST /api/soap/v2/loyaltyaccount HTTP/1.0
User-Agent: NuSOAP/0.7.3 (1.114)
Content-Type: text/xml; charset=ISO-8859-1
SOAPAction: ""
Content-Length: 1189

   <s:Header>
      <wsse:Security s:mustUnderstand='1' xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'>
            <wsu:Created>2010-10-04T17:24:48Z</wsu:Created>
            <wsu:Expires>2010-10-04T17:25:48Z</wsu:Expires>
        </wsu:Timestamp>
        <wsse:UsernameToken>
            <wsse:Username>testusername</wsse:Username>
            <wsse:Password Type='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'>testpassword</wsse:Password>
        </wsse:UsernameToken>
      </wsse:Security>
  </s:Header>
      <GetTransactions xmlns='http://testapi.com/api/loyaltyaccount/v2'><id>411018</id><startDate>2010-09-18T18:00:00</startDate><endDate>2010-09-22T18:20:00</endDate></GetTransactions></s:Body>
</s:Envelope>



Server's response example:





HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-Powered-By: Servlet 2.5; JBoss-5.0/JBossWeb-2.1
Content-Type: text/xml;charset=ISO-8859-1
Content-Length: 7130
Date: Mon, 04 Oct 2010 17:02:53 GMT
Connection: close

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetTransactionsResponse
<loyaltyTransactions>
<ns2:id>2100334</ns2:id>
<ns2:createdAt>2010-09-18T22:55:51.458Z</ns2:createdAt>
<ns2:updatedAt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:nil="true" />
<amount>120</amount>
<balance>600</balance>
xsi:nil="true" />
<loyaltyAccountId>411018</loyaltyAccountId>
<loyaltyProgramId>3</loyaltyProgramId>
<pincodeId>439080117</pincodeId>
<pincode>8020-003888H0F732</pincode>
xsi:nil="true" />
xsi:nil="true" />
xsi:nil="true" />
<productPurchaseId xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:nil="true" />
xsi:nil="true" />
xsi:nil="true" />
<optionalDetails>PIN Code 8020-003888H0F732</optionalDetails>
</loyaltyTransactions>
<loyaltyTransactions>
<ns2:id>2100434</ns2:id>
<ns2:createdAt>2010-09-22T18:18:18.831Z</ns2:createdAt>
<ns2:updatedAt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:nil="true" />
<amount>123</amount>
<balance>2553</balance>
<description>Balance Updated:another test on 2:19pm</description>
<loyaltyAccountId>411018</loyaltyAccountId>
<loyaltyProgramId>3</loyaltyProgramId>
xsi:nil="true" />
xsi:nil="true" />
xsi:nil="true" />
xsi:nil="true" />
xsi:nil="true" />
<productPurchaseId xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:nil="true" />
xsi:nil="true" />
xsi:nil="true" />
<optionalDetails>Balance Updated:another test on 2:19pm
</optionalDetails>
</loyaltyTransactions>
</GetTransactionsResponse>
</soap:Body>
</soap:Envelope>


Afterwards, I do copy paste the stuff that I have and just edit it if you have another sub-URI for your service. I think it's faster this way, for development purposes only, but not ideally for QA. Still, scripts as client like Java, PHP, Python, Ruby is of course ideal since you need automation specially when you do continuous integration.

Hope this helps.