Bottom Up Java Web Service using JDeveloper

One of the usual ways of developing web services – especially in organizations where Java is already being used – is to expose the java code as web services as part of SOA enablement. Converting code to a service is an example of bottom up development in SOA World and we are going to understand this using a simple Hello World Bottom Up Java Web Service using JDeveloper

Please refer to the Top Down and Bottom Up Design article under Architecture section to understand the design methodology behind bottom up development.

Contents of this article are

Bottom Up Java Web Service Development Video

Video of bottom up java web service development using JDeveloper is available below and also at our Youtube channel

Bottom Up Java Web Service using JDeveloper
Bottom Up Java Web Service using JDeveloper

Creation of JDeveloper Project and Hello World Code

Creation of the JDeveloper project with a simple Hello world java class is a straight forward process. Steps involved to get this done are:

  1. Create JDeveloper project by right clicking in the workspace and selecting new project.
  2. Enter a name for the project and select Java and Web Service technologies to the project
  3. Accept rest of the defaults and click Finish.
  4. In the empty project created, create a new Java Class called Hello World – include Main method in the generation window so that you can test out the java class locally.
  5. Modify the generated class to add a simple sayHello function which takes a simple String name as input and returns a String as output after concatenating “Hello ” to the name. This means that if the name “ExpertzMe” is given as input, output from the function would be “Hello ExpertzMe”
  6. Save all files and test the java class by right clicking the java class and selecting run.

Exposing Java code as a web service

JDeveloper provides a wizard to automate creation of java web services. Steps involved to create java web services are:

  1. Right click the java class in the application navigator and select the option to create web service
  2. The wizard provides you various options to configure like
    1. Select the library used to generate web service
    2. Selecting the details of the service like SOAP versions, web service types
    3. Selecting additional options to add service handlers
    4. Attaching policies to the service, etc
  3. Accept the default options and click Finish to generate the web services.

Executing the service in JDeveloper

JDeveloper comes with a default integrated web logic server, which could be used for testing the web services (or java applications) in the developer machine itself. For our example, we will execute the service locally using the embedded integrated web logic server. Steps to achieve this are:

  1. Right click the service in the application navigator and select Run
  2. Select the option to run the service in WLS
  3. Wait for the weblogic server to come up and display the web service end point URL in the log window
  4. Copy paste the URL onto the browser window and add ?wsdl to the end of the URL. This should show you the generatd WSDL for your service.
  5. Click the end point URL in JDeveloper itself – which opens up the HTTP Analyzer window
  6. Enter the name value in the arg0 section as ExpertzMe
  7. Click the Send Request button to invoke the service and observe that you receive “Hello ExpertzMe” as response.
  8. Click on the HTTP content tab to see the entire SOAP payload exchange

Conclusion

Some of the things to conclude from this example are:

  • JDeveloper provides multiple wizards to automate the Java Web service creation process
  • You can configure many options like library to use, policies to configure, etc as options in a wizard to help with rapid development
  • JDeveloper comes with built in integrated web logic server to help with running and testing of the code by the developer locally
  • HTTP analyzer tool is provided by the JDeveloper to help you with quick execution and validation of web services

Share this:

About Chethan

I am the Founder and Director of Expertz.me! I am an Entrepreneur, Architect, Problem Solver & Techy - All rolled into one!!