Accessing resources
To test the system, you need to look at the SOAP messages that would normally be sent as part of the exchange.
You can generate some sample SOAP messages to test the exchange of information with the server; some have automatically been generated as part of the original WSDL generation process.
For example, the SOAP message for getting the property for a resource is shown in Listing 20.
Listing 20 sets the ResourceIdentifier to 999 (the value of the resource you created in your Derby table) before specifying a call to the GetResourceProperty Web service, requesting the person_name property.
Listing 20. SOAP message for getting the property for a resource
<Envelope
xmlns="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:fs="http://ws.codebits.com/derby/wsrf/Person"
>
<Header xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing">
<wsa:To mustUnderstand="1">
http://ws.codebits.com/derby/wsrf/Person
</wsa:To>
<wsa:Action mustUnderstand="1">
http://ws.codebits.com/derby/wsrf/Person/PersonType/GetResourcePropertyReques
t
</wsa:Action>
<fs:ResourceIdentifier
mustUnderstand="1">999</fs:ResourceIdentifier>
</Header>
<Body>
<wsrp:GetResourceProperty
xmlns:wsrp="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourcePropertie
s-1.2-draft-01.xsd"
xmlns:fs="http://ws.codebits.com/derby/wsrf/Person"
>
fs:person_name
</wsrp:GetResourceProperty>
</Body>
</Envelope>
|
Test the GetResourceProperty Web service
To test the Web services, you can use Ant in combination with the SOAP messages you constructed. The Ant tool will send the SOAP message and print out the response (with a lot of debug information) to demonstrate the operation of the service, as shown in Listing 21.
Listing 21. Testing the Web services
C:\java\workspace\eclipse\WS_Derby_01>ant -f soapclient.xml
-Durl=http://localhost:8080/wsrf/services/Person
-Dxml=requests/GetResourceProperty.soap
Buildfile: soapclient.xml
init:
[echo] Using webapp dir:
C:\java\support\apache-tomcat-5.5.16/webapps/wsrf
sendRequest:
[echo] Reading SOAP request from: requests/GetResourceProperty.soap ,,,
[echo] Sending SOAP request to
http://localhost:8080/wsrf/services/Person ...
[echo] ========================== REQUEST ============================
[concat] <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:fs="http://ws.codebits.com/derby/wsrf/Person">
[concat] <Header
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing">
[concat] <wsa:To
mustUnderstand="1">http://ws.codebits.com/derby/wsrf/Person</wsa:To>
[concat] <wsa:Action
mustUnderstand="1">http://ws.codebits.com/derby/wsrf/Person/PersonType/Get
ResourcePropertyRequest</wsa:Action>
[concat] <fs:ResourceIdentifier
mustUnderstand="1">999</fs:ResourceIdentifier>
[concat] </Header>
[concat] <Body>
[concat] <wsrp:GetResourceProperty
xmlns:wsrp="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourcePropertie
s-1.2-draft-01.xsd" xmlns:fs="http://ws.codebits.com/derby/wsrf/Person">
[concat] fs:person_name
[concat] </wsrp:GetResourceProperty>
[concat] </Body>
[concat] </Envelope>
[echo] ========================== RESPONSE ============================
[soapClient] <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
[soapClient] <soapenv:Header>
[soapClient] <wsa:Action
soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"
soapenv:mustUnderstand="0"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing">http://schema
s.xmlsoap.org/ws/2004/03/addressing/anonymous</wsa:Action>
[soapClient] <wsa:To
soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"
soapenv:mustUnderstand="0"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing">http://schema
s.xmlsoap.org/ws/2004/03/addressing/anonymous</wsa:To>
[soapClient] </soapenv:Header>
[soapClient] <soapenv:Body>
[soapClient] <wsrf:GetResourcePropertyResponse
xmlns:wsrf="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourcePropertie
s-1.2-draft-01.xsd">
[soapClient] <per:person_name
xmlns:per="http://ws.codebits.com/derby/wsrf/Person">David</per:person_
name>
[soapClient] </wsrf:GetResourcePropertyResponse>
[soapClient] </soapenv:Body>
[soapClient] </soapenv:Envelope>
BUILD SUCCESSFUL
|
Although the output is quite detailed, the key line is the one shown below:
[soapClient] <per:person_name
xmlns:per="http://ws.codebits.com/derby/wsrf/Person">David</per:person_
name>
This indicates that the system has found the resource with ID 999 and is returning the name property of the Person resource.
To set the resource state, you must create a SOAP message to call the Enable method. You also need to specify the ResourceIdentifier in the message so that the service knows which resource to Enable (see Listing 22).
Listing 22. Setting the resource state
<Envelope
xmlns="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:fs="http://ws.codebits.com/derby/wsrf/Person"
>
<Header xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing">
<wsa:To mustUnderstand="1">
http://ws.codebits.com/derby/wsrf/Person
</wsa:To>
<wsa:Action mustUnderstand="1">
http://ws.codebits.com/derby/wsrf/Person/PersonType/GetResourcePropertyReques
t
</wsa:Action>
<fs:ResourceIdentifier
mustUnderstand="1">999</fs:ResourceIdentifier>
</Header>
<Body>
<fs:Enable />
</Body>
</Envelope>
|
You can run this in the same way as the previous example.




