Samples in WST  Developing client applications

Chapter 10: Using the Web Services Toolkit Samples

Using the WST development tool and features

Your WST installation includes the following samples and tutorials that familiarize you with the WST development tool. All samples in this section require Eclipse to be running and the Sybase Web services plug-in installed. See Chapter 4, “Web Services Administration.”


Exposing a Java class as a Web service

The WST development tool provides the architecture and tools to create and deploy Web services from various types of files, which generate a WSDL file as part of the Web service creation. From the generated WSDL file, use the WST development tool to create a test client that tests your newly exposed Web service.

In this tutorial, you:

The Java source files are in the JavaClass/simpleJavaClass and JavaClassClient subdirectories. Instructions for running the tutorial are in the file ReadmeForEclipse.txt in the JavaClass/simpleJavaClass directory.


Running the test client using HTTPS

The sample described above includes a client, AddClient.java located in the JavaClassClient/client subdirectory. This section describes how to modify this sample and import a test certificate into a keystore so that you can run the tutorial using HTTPS.

To run the test client using HTTPS, you must have Java Secure Socket Extension (JSSE) installed and configured on the client. See Chapter 5, “Using SSL in Java Clients”, in the EAServer Security Administration and Programming Guide for more information.

StepsExporting the Jaguar Test CA

You must export the Jaguar Test CA using Security Manager. See the EAServer Security Administration and Programming Guide for information about starting and using Security Manager.

  1. From Security Manager, select the CA Certificates folder.

  2. Highlight the Sybase Jaguar User Test CA.

  3. Select File | Export Certificate.

  4. From the Export Certificate wizard, select the format type for the exported certificate. For the Test CA, select Binary Encode X509 Certificate. Click Next.

  5. Select Save to File and enter the full path name to a file that will contain the test CA. Use EASTestCA as the certificate name.

    Do not add any extension to the file name. A .crt extension is automatically added to the exported certificate by Security Manager.

  6. Click Finish to export the certificate to the EASTestCA.crt.

StepsCreate a Java Keystore containing the Sybase Jaguar test CA and mark the certificate trusted.

This procedure uses the Java keytool command to create a keystore, import the EASTestCA.crt certificate, and mark it trusted.

  1. From the command line, go to the $JAGUAR/sample/wst_samples directory.

  2. Enter this command to create the keystore named EASTestCA.jks and install EASTestCA.crt, mark it trusted, and protect the keystore with the password “changeit”:

    <path_to_JDK_1.3>/bin/keytool -import -v -trustcacerts -alias eastestca -file EASTestCA.crt -keypass changeit -keystore EASTestCA.jks

    The Java keytool command requires you to answer two questions. Here are the questions, answers you should provide, and output:

    Enter keystore password: changeit 
    
    Owner: L=Sybase Jaguar User Test Locality, O=Sybase Jaguar User Test, CN=Sybase Jaguar User Test CA (TEST USE ONLY) 
    Issuer: L=Sybase Jaguar User Test Locality, O=Sybase Jaguar User Test, CN=Sybase Jaguar User Test CA (TEST USE ONLY) 
    Serial number: 1
    Valid from: Fri Oct 16 11:02:16 PDT 1998 until: Thu Oct 16 11:02:16 PDT 2003 
    Certificate fingerprints: 
    MD5: 5B:66:65:6A:4F:11:41:7C:B4:9B:17:CF:30:61:26:5F
    SHA1: B5:38:55:36:E2:FF:F2:28:5E:45:80:94:BF:54:20:96:28:5B:CC:F8 
    
    Trust this certificate? [no]: yes
    
    Certificate was added to keystore 
    [Saving EASTestCA.jks] 
    

StepsModify the client program

Make these changes to the AddClient.java file. When you run the program, the client will connect to the listener at port 8081. This tutorial assumes that you are running the client on the same machine as your EAServer installation.

  1. modify AddClient.java as follows:

    import java.net.URL; 
    import java.net.MalformedURLException; 
    import java.security.Security; 
    import java.io.File; 
    
    
    public class AddClient 
    { 
    public static void main(String[] args) 
    { 
    
    ... 
    String jksStore= 
    ".." + File.separator + ".." + File.separator + 
    "EASTestCA.jks"; 
    
    System.setProperty("javax.net.ssl.trustStore", jksStore); 
    System.out.println("Set system property " + 
    javax.net.ssl.trustStore to " + jksStore); 
    // Dynamically register the JSSE provider 
    Security.addProvider(new 
    com.sun.net.ssl.internal.ssl.Provider()); 
    
    context = new AddNumbers_ServiceLocator(); 
    URL newURL = null; 
    try 
    { 
    newURL = 
    new URL("https://localhost:8081/AddSample/services/AddNumbers"); 
    } 
    catch(MalformedURLException me) 
    { 
    me.printStackTrace(); 
    return; 
    } 
    
    System.out.println("Connecting to: " + newURL.toString()); 
    client = context.getAddNumbers(newURL); 
    
    

StepsCompile and run the sample

  1. Change to the JavaClassClient/client subdirectory and compile and run the test client. For example:

    $JAGUAR/bin/wstant compile run -Dnum1=5 -Dnum2=8 
    

Exposing a Web service that implements JAX-RPC defined interfaces

The WST development tool allows you to develop, deploy, and run Web services that conform to the JAX-RPC specification.

In this tutorial, you:

The source files are in the JAXRPCService and JAXRPCClient subdirectories. Instructions for running the tutorial are in the file readmeEclipse.txt in the JAXRPCService/server directory.


Exposing a stateless EJB as a Web service

The WST development tool offers different options for exposing Web services and generating test clients.

In this tutorial, you:

The source files are in the EJBSample/statelessEjbSample subdirectory. Instructions for running the tutorial are in the file readme.txt.


Establishing Web service security, and generating a test client

Authorization for Web services is enforced by roles. Using the WST development tool you can create new roles, or use predefined roles to establish security at the Web service and Web service operation level. Using different levels of security at the operation level allows you to closely control who has access to your resources.

In this tutorial, you:

The source files are in the SecuritySample and SecuritySampleClient subdirectories. Instructions for running the tutorial are in the file readme.txt in the SecuritySample directory.


Exposing a CORBA component as a Web service

This sample demonstrates how to expose an existing CORBA component as a Web service. In addition, the sample illustrates which component properties enable the component to be exposed. The WST development tool contains an “Other components” folder, which contains components that can be deployed as Web services. Once deployed, the components remain listed in the Other Components folder. This tutorial contains a CORBA Java component that can be exposed as a Web service once it is made stateless. Use EAServer Manager and the WST development tool together to run this tutorial.

In this tutorial, you:

The source files are in the CORBAComponent subdirectory. Instructions for running the tutorial are in the file readme.txt.


Google search API demonstration

In this sample you download the Google Web services APIs and create a Web service client that allows you to perform sample Google searches.

The source files are in the GoogleAPI subdirectory. Instructions for running the tutorial are in the file GoogleSearchEAS5.htm.





Copyright © 2005. Sybase Inc. All rights reserved. Developing client applications