Advanced Web Service Interoperability

This tutorial needs a review. You can edit it in GitHub following these contribution guidelines.

Advanced Web Service Interoperability (WSIT), also referred to as Web Service "Quality of Service", encompasses components that enable interoperability between Java web services and .Net web services. This document demonstrates some of the support in the IDE for configuring a web service and client that use WSIT. For more information on using WSIT, see Chapter 3 WSIT Example Using a Web Container and NetBeans IDE in The WSIT Tutorial

netbeans stamp 74 73 72
Figure 1. Content on this page applies to the NetBeans IDE 7.2, 7.3 and 7.4

To follow this tutorial, you need the following software and resources.

Software or Resource Version Required

NetBeans IDE

Java EE download bundle

Java Development Kit (JDK)

version 6 or version 7

Java EE-compliant web or application server

GlassFish Server Open Source Edition 3.1.x, 4.x or Oracle WebLogic Server 11g or 12c

The GlassFish server can be installed, optionally, with the Java EE distribution of NetBeans IDE. Alternatively, you can visit the the GlassFish server downloads page or the Apache Tomcat downloads page.

*Important: *Java EE projects require GlassFish Server 3.1.x, 4.x, or Oracle WebLogic Server 12c.

Introduction

Components relating to advanced web services interoperability fall into four main categories:

  • Bootstrapping and configuration. The process that is executed to create a Web service client that can access and consume a Web service.

  • Message security. The following security configuration options are supported:

  • Targets to sign and encrypt options

  • Client/service Web services security

  • Client/service trust options

  • Advanced configuration options

  • Keystore configuration options

  • Message optimization. Ensures that Web services messages are transmitted over the Internet in the most efficient manner. Message optimization is achieved in Web services communication by encoding messages prior to transmission and then de-encoding them when they reach there final destination.

  • Reliable messaging. Measured by a system’s ability to deliver messages from point A to point B without error.

"Quality of service" is configured in the Web Service Attributes Editor, which can be accessed from the node representing the web service or client in the Projects window. In this document you are introduced to two samples that are distributed with the IDE: an unsecured web service sample and a secured web service sample. This document will show some of the differences between the samples and also how to use the IDE to configure security for your own web services and clients.

For a full and complete guide to topics relating to 'Quality of Service', see The WSIT Tutorial.

Getting to Know the Calculator Sample

The goal of this exercise is to get to know the Calculator sample that is bundled with the IDE. In contrast to the next sample, this sample is not secured, as you will see when you examine the web service.

Exploring the Sample

In this exercise you will use the New Project wizard to create the sample, examine the sample in the IDE and deploy the application.

  1. Choose File > New Project (Ctrl-Shift-N on Linux and Windows, ⌘-Shift-N on MacOS) to open the New Project wizard.

  2. Expand the Samples category and select the Web Services node and then select the Calculator sample. Click Next.

wsit newproject
Figure 2. New Project wizard showing calculator sample
  1. Confirm that a Java EE-compliant server is selected in the Server drop-down list. Click Finish.

When you click Finish the wizard creates two projects:

  • CalculatorApp provides a web service named CalculatorWS that exposes an operation named 'add'.

  • CalculatorClientApp provides a client named CalculatorWSService that invokes the web service’s 'add' operation.

The CalculatorClientApp service might be badged with an error icon because the IDE cannot find the WSDL for the CalculatorWS service. The error will be resolved after you deploy CalculatorApp and clean and build the CalculatorClientApp.

wsit projects
Figure 3. Projects window displaying the web service and the client
  1. Double-click the CalculatorWS web service to open the file in the editor and click the Design tab at the top of the editor to view the web service in the visual designer.

wsit design
Figure 4. CalculatorWS service in Design GUI (Visual Designer) tab

Note: In the Quality of Service section in the design tab of the service you can see that no options are enabled. As a result, the Quality of Service components have not been applied to this particular web service. You will look at a web service where a Quality of Service component is enabled when you create the secure web service.

For a full tutorial on web services in the IDE, see Getting Started with JAX-WS Web Services.

Deploying and Testing the Calculator Sample

  1. Right-click the CalculatorApp project and choose Run.

The server starts and the web service is deployed to the server. You will see a page open in your default browser that provides some details of the service.

wsit browser1
Figure 5. CalculatorWS information window in browser
  1. Click on the WSDL link in the page in the browser to see the WSDL file that defines the web service.

wsit browser2
Figure 6. Calculator WS WSDL in browser

Note. If the WSDL does not display, check the URL in the browser’s location bar. It should point to http://localhost:_your_port_number_/CalculatorApp/CalculatorWSService?WSDL .

  1. In the Projects window of the IDE, right-click CalculatorWS under the Web Services node and choose Test Web Service in the popup menu.

When you test the web service a page for testing the service opens in your browser.

wsit browser3
Figure 7. Calculator WS Tester in browser

The IDE can provide a client for testing your web service and open the test application in your browser. In the test application you can enter values for each of the fields defined in the web service. The test application has a button that is labeled after the name of the operation in the service. When you click the button you will see the result of invoking the operation.

  1. Examine the CalculatorClientApp project in the Projects window for any error badges.

If there are error icons for ClientServlet.java , right-click the project node and choose Clean and Build in the popup menu. The errors appeared because the CalculatorWS service was not deployed. Now that it is deployed, the IDE can parse the WSDL and the ClientServlet compiles.

  1. Right-click the CalculatorClientApp project node and choose Run.

When you run the application an interface for the service opens in your browser.

wsit browser4
Figure 8. Calculator Service client in browser
  1. Enter values in the two fields and click Get Result.

When you click Get Result the result of the operation is retrieved from the web service and displayed in the client.

The web service is functioning correctly and the client retrieves results, but this project does not make use of the Quality of Service components. In the next section, you will see how you can configure Quality of Service components.

Getting to Know the Secured Calculator Sample

The goal of this exercise is to examine how a secured web service is set up and how a client interacts with it.

Exploring the Sample

In this exercise you use the New Project wizard to create the sample and then examine how Quality of Service is configured for the application.

  1. Choose File > New Project (Ctrl-Shift-N on Linux and Windows, ⌘-Shift-N on MacOS) to open the New Project wizard.

  2. Expand the Samples category and select the Web Services node and then select the Secure Calculator sample. Click Next.

  3. Confirm that a Java EE-compliant server is selected in the Server drop-down list. Click Finish.

When you click Finish the wizard creates two projects:

  • SecureCalculatorApp provides a web service named CalculatorWS that exposes an operation named 'add'.

  • SecureCalculatorClientApp provides a client named CalculatorWSService that invokes the web service’s 'add' operation.

The SecureCalculatorClientApp service might be badged with an error icon because the IDE cannot find the WSDL for the CalculatorWS service. The error will be resolved after you deploy SecureCalculatorApp and clean and build the SecureCalculatorClientApp.

  1. Double-click the CalculatorWS web service in the Web Services folder of SecureCalculatorApp to open the file in the editor and click the Design tab at the top of the editor to view the web service in the visual designer.

Note: In the Quality of Service section in the design view of the service you can see that the Secure Service option is selected and that the other two options are not selected. The Quality of Service section in the design view specifies which of the Quality of Service components is enabled for the current web service.

  1. Click Edit Web Service Attributes to open the Web Service Attributes Editor.

wsit quality dialog
Figure 9. Quality of Service page in WS Attributes Editor

In the Quality of Service tab you can see that a Version Compatibility option is selected. You should select the latest version that matches the version of Metro or .NET that is installed.

To enable the version compatibility drop down list, add the latest version of Metro to your project’s classpath. To add the latest Metro library, right-click the project’s node in the Projects window, open the project’s Properties, go to the Libraries category, and browse for and add the latest Metro library.

Notice that the Secure Service option is selected and that a security mechanism is selected in the drop-down list. The security mechanism specifies the approach used for securing the web service.

In this sample application the Username Authentication with Symmetric Keys security mechanism is selected. For a description of options and properties for the Username Authentication with Symmetric Keys security mechanism, see Username Authentication with Symmetric Key +]. For a description of other available security mechanisms, see link:http://docs.oracle.com/cd/E19182-01/820-0595/6ncatc2q5/index.html[+Configuring Security Mechanisms.

  1. Expand the Input Message and Output Message sections in the Quality of Service tab.

wsit quality dialog2
Figure 10. Quality of Service page with Message Parts button enabled

The Message Parts button is enabled for Input Message and Output Message if you select the Username Authentication with Symmetric Keys as the security mechanism.

Note: The Authentication Token drop-down list and the options for Input Message are not enabled for the Username Authentication with Symmetric Keys security mechanism.

  1. Click the Message Parts button in the Input Message section.

wsit messageparts
Figure 11. Message Parts dialog

In the Message Parts dialog box you can see security options for different elements. You can select a checkbox to enable or disable the parts that should be signed, encrypted and required. For each element you can specify the following options:

  • Select Sign to specify the parts or elements of a message that require integrity protection (digital signature).

  • Select Encrypt to specify the parts or elements of a message that require confidentiality (encryption).

  • Select Require to specify the set of parts and/or elements that a message must contain.

Next you will look at how the web service client’s Quality of Service is configured.

  1. In the Projects window, expand the Web Service References node in the SecureCalculatorClientApp project.

  1. Right-click the CalculatorWSService node and choose Edit Web Service Attributes in the popup menu to open the Web Service Attributes dialog box.

wsit qos wsservice
Figure 12. Web service client quality of service dialog

You can see that a default user "wsitUser" and password exist. The default user and password were created in the "file" realm.

If you select the Use Development Defaults option in the Security section the IDE imports certificates into the GlassFish server keystore and truststore, so that they can be used immediately for development.

*Important: * In a production environment, you will probably want to provide your own certificates and user settings, however, in a development environment you may find these defaults useful.

For a more detailed description of how to configure security for a web service client, see Chapter 7 Using WSIT Security in The WSIT Tutorial.

Deploying and Testing the Secured Calculator Sample

  1. Right-click the web service project node and choose Run to deploye the web service.

  2. Right-click the web service client project node and choose Run.

When you run the client the application is deployed and and the interface for the service opens in the browser.

wsit browser secure1
Figure 13. Secure web service client in browser
  1. Type a number in each of the fields and click Get Result.

When you click Get Result the page will display a message that the client was authenticated and will display the result of the operation.

wsit browser secure2
Figure 14. Secure web service client in browser showing results

If you get an error message that authentication failed due to an invalid user/password pair, there is either a problem with the default user created by the IDE or there are mismatched credentials set on the client. In this case, you need to create the user/password pair manually. For instructions, please see Chapter 7 Using WSIT Security in The WSIT Tutorial.

See Also

For more information about using NetBeans IDE to develop Web Services, see the following resources:

To send comments and suggestions, get support, and keep informed about the latest developments on the NetBeans IDE Java EE development features, join the nbj2ee@netbeans.org mailing list.