Monday, March 23, 2009

Creating a bottom-up Java web service

This post describes how to create a bottom-up webservice in Java. This involves by first creating your Java class from which the web service is then created from.

The instructions describe how to develop this in Oracle JDeveloper 10g and deploy to Oracle Application Server 10g, but they are mostly compatible with Oracle JDeveloper 11g and Oracle WebLogic Server 11g.

1. Open JDeveloper (e.g., double-click on c:\jdev\jdeveloper.exe)

2. Create a new application WebServiceStubs:
a. Right-click on Applications 
b. Click on New Application and then OK 
c. Enter CustomerRegistration for the project name and then OK
3. Create a Java class:
a. Right-click on CustomerRegistration 
b. Click on New 
c. Choose Java Class under General and then OK 
d. Enter CustomerRegistration for the class and package names for now (should be pre-populated) and then OK
4. Edit CustomerRegistration.java and add the following code:
package customerregistration;

public class CustomerRegistration {
    public String RespondName(String name) {
        String outputString = "Hello " + name;
        return (outputString);
    }
}
5. Create a J2EE Web Service from the Java class:
a. Right-click on CustomerRegistration.java 
b. Choose Create J2EE Web Service 
c. Choose J2EE 1.4 (JAX-RPC) Web Service and then OK
d. Enter "RegisterCustomer" as the Web Service Name and then click Finish
6. Deploy the service:
a. Click on File --> Save All 
b. Right-click on WebServices.deploy and 'Deploy to' your application server
c. Click on OK whenever prompted
7. Navigate to the web service and test (using a tool such as SoapUI):
http://dev.ipnweb.com:7777/WebServiceStubs-CustomerRegistration-context-root/RegisterCustomerSoapHttpPort
8. Example of SOAP message:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                  xmlns:typ="http://customerregistration/types/">
  <soapenv:Header/>
  <soapenv:Body>
    <typ:RespondNameElement>
      <typ:name>World</typ:name>
    </typ:RespondNameElement>
  </soapenv:Body>
</soapenv:Envelope>

Ahmed Aboulnaga

No comments: