programmera.net -> jax -> normal för utskrift | info@programmera.net |
Testa tjänsten med SAAJ-klient
1. Testa tjänsten |
1. Testa tjänsten
Vi återanvänder nästan samma SAAJ-klient som beskrevs på SAAJ-sidorna:
Den endra förändringen är att vi nu kör mot "http://localhost:8080/calculator/Calculator". Vi testar:
Vi får följande utskrift på serversidan:
[olle@dev1]$ java SAAJCalculatorClient DIV 2 7
====================================
Main 1. Check parameters
====================================
Operation is division.
====================================
Main 2. Build SOAP message.
====================================
1. Detach the SOAP header.
2. Create SOAP body.
3. Add the operation element (division).
4. Add the request part element.
5. Add the first parameter element.
6. Add the second parameter element.
7. Add empty SOAPAction mime header.
8. SOAP message finished, print it:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<cal:division xmlns:cal="http://www.programmera.net/ws/Calculator">
<divisionRequestPart>
<dividend>2</dividend>
<divisor>7</divisor>
</divisionRequestPart>
</cal:division>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
====================================
Main 3. Send request
====================================
1. Create SOAP connection factory.
2. Create SOAP connection.
3. Call enpoint URL=http://localhost:8080/calculator/Calculator
Response retrieved.
====================================
Main 4. Fetch Response
====================================
<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
<env:Header/>
<env:Body>
<ns1:divisionResponse xmlns:ns1='http://www.programmera.net/ws/Calculator'>
<divisionReturn>0.2857143</divisionReturn>
</ns1:divisionResponse>
</env:Body>
</env:Envelope>
Result=0.2857143
Program finished!
I detta fall ser vi att vår klient lyckas inte behålla HTTP-sessionen. Servern tror att varje anrop är det första i sessionen.
04:47:08,351 INFO [STDOUT] Calculator: ServletEndpointContext retrieved.
04:47:09,067 INFO [STDOUT] Calculator: Call 1, result=9594.0
04:55:11,282 INFO [STDOUT] Calculator: ServletEndpointContext retrieved.
04:55:11,293 INFO [STDOUT] Calculator: Call 1, result=17.571428