Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Apache Derby resources from the Web services perspective, Part 1: Derby data as WS-Resources

David Medinets (david.medinets@gmail.com), Freelance Writer, Eclectic Consulting
David Medinets has been programming since 1980, when he started with a TRS-80 Model 1. He still fondly remembers the days when he could cross-wire the keyboard to create funny-looking characters on the display. Since those days, he has spent time debugging the Emacs text editor on UNIX® machines, working on VAXen, and building cutting-edge Web applications (think Toys"R"Us and 7,000 simultaneous users in 1999). David is married to Kathryn and lives in Fairfax, Virginia. He runs Eclectic Consulting and has authored books on Perl, PHP, and BASH. He also runs the CodeBits.com site.

Summary:  As the world moves in the direction of service-oriented architecture (SOA), it becomes crucial that all of your resources are SOA friendly. That may mean they produce services, that they consume services, or that they are services. This three-part tutorial series looks at Apache Derby from the perspective of making it Web services-aware. Web services are stateless, but most applications are not. This tutorial, Part 1, shows you how to use WS-Resources to refer to Derby data and structures from within the inherently stateless environment of Web services.

View more content in this series

Date:  03 Oct 2006
Level:  Intermediate PDF:  A4 and Letter (109 KB | 32 pages)Get Adobe® Reader®

Activity:  7583 views
Comments:  

Accessing resources

To test the system, you need to look at the SOAP messages that would normally be sent as part of the exchange.

Generate SOAP test messages

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.


Set resource states

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.

6 of 10 | Previous | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source, Information Management, SOA and Web services
ArticleID=163965
TutorialTitle=Apache Derby resources from the Web services perspective, Part 1: Derby data as WS-Resources
publish-date=10032006
author1-email=david.medinets@gmail.com
author1-email-cc=ruterbo@us.ibm.com