Did you know? DZone has great portals for Python, Cloud, NoSQL, and HTML5!
Enterprise Integration Zone is brought to you in partnership with:

Martin has posted 1 posts at DZone. View Full User Profile

Advanced Web Service Interoperability In Easy Steps

06.12.2008
Email
Views: 42238
  • submit to reddit
The Enterprise Integration Zone is presented by DZone and FuseSource. Check out the EI Zone for real world integration scenarios to help you learn which technology will give you the most elegant solution.  For open source systems based on Apache Camel, ActiveMQ, or ServiceMix, look into FuseSource's training and technology.  
This article is intended for programmers who are interested in adding additional qualities to their services, clients, or SOA solutions, as well as for beginners in Java web service development. You will learn how to use NetBeans IDE 6.1 to develop Java web service clients and services that can interoperate with Microsoft .NET 3.0 clients and services, how to use encryption and signatures to protect confidentiality and integrity of message transmission without need for SSL, and how to use Reliability features to ensure that none of your application messages are lost or delivered twice.

NetBeans IDE 6.1 comes with enhanced support for web services development, reflecting the state of industry-wide adopted technologies in web services and Service Oriented Architecture (SOA). NetBeans includes unique and easy to use tools, from visual web service design to enabling powerful technologies for security, reliability or transactions. Bundled together with ready-to-run examples, help and documentation, it provides an easy entrance point for beginners in web service development as well as a broad set of features required by enterprise class solutions and SOA.

METRO Overview

Most of the web service related features in NetBeans are built with the use of Project Metro. Project Metro is the Web services stack (framework) from Sun Microsystems. The stack is integrated in GlassFish V2, a high-performance, production-quality, Java EE 5 compatible application server.

The individual components of Metro can be divided in two categories:

● JAX-WS Implementation – The core Web services platform
Project Tango, also referred to as Web Services Interoperability Technology (WSIT)

JAX-WS is the core Web Service platform, including all the SOAP message functionality, and Project Tango adds interoperability with Microsoft .NET, Reliability, Security, and Transactions.

Tango Terminology

  • Credentials – A set of claims used to prove the identity of a client. They contain an identifier for the client and a proof of the client's identity, such as a password. They may also include information, such as a signature, to indicate that the issuer certifies the claims in the credential.
  • Direct Authentication – A type of authentication where the service validates credentials directly with an identity store, such as a database or directory service.
  • Impersonation – The act of assuming a different identity on a temporary basis so that a different security context or set of credentials can be used to access the resource.
  • Message Layer Security – Represents an approach where all the information that is related to security is encapsulated in the message. In other words, with message layer security, the credentials are passed in the message.
  • Mutual Authentication – This is a form of authentication where the client authenticates the server in addition to the server that authenticates the client.
  • Security Token – A set of claims used to prove the identity of a client. They contain an identifier for the client and a proof of the client's identity such as a password. They may also include information, such as a signature, to indicate that the issuer certifies the claims in the credential. Most security tokens will also contain additional information that is specific to the authentication broker that issued the token.
  • Transport Layer Security – Represents an approach where security protection is enforced by lower level network communication protocols (such as SSL).
  • Trusted subsystem (domain) – This is a process where a trusted business identity is used to access a resource on behalf of the client. The identity could belong to a service account or it could be the identity of an application account created specifically for access to remote resources.

 

Get Ready For Web Services


Implement and Deploy web service

In this example, we show how to develop a web service. We enhance this service with additional capabilities in later chapters. Our service will be able to receive banking orders and store them in a map (for simplicity, we'll skip databases in this example). First, create an Enterprise Application in which we will host our web service, by choosing File -> New Project and selecting Enterprise Application. Click Next and name the application BankApplication. Leave the other values at default. Your wizard screen for Enterprise Application should look similar to Figure 1.

Note: The target server is GlassFish v2. You can have it installed with your NetBeans IDE 6.1 installation if you choose the Full or Web & J2EE download or specifically select GlassFish). If you don't have it, download GlassFish from http://glassfish.dev.java.net, and register it into NetBeans through Tools -> Servers.


Figure 1. Creating Enterprise Application

 

Now create the web service itself in the EJB module. Right-click BankApplication-ejb node and select New -> Web Service. In the wizard window, name the web service BankOrderService and place it in package bankorder.service as shown on Figure 2.


Figure 2. Creating a Web Service in an EJB module

After clicking Finish, you should see the Visual Designer window for your web service. It is empty, because we did not define any operations for the service yet. Our application should be able to receive orders, and we would like to model them as a Java class with 3 fields for recipient account number, sender account number, and the actual amount being transferred. We will represent this data in a class called bankorder.data.BankOrder. Create the class as shown on Listing 1, and then use the Refactoring -> Encapsulate Fields feature in the editor to generate setters and getters for all fields.

Listing 1. BankOrder.java Class for transferring information about the Banking orders between service and client

package bankorder.data;

public class BankOrder {
private int id;
private String receiverAccount;
private String sender Account;
}

With the data transfer class ready, we are able to implement the web service itself. Return to the web service BankOrderService we created in previous step, click Add Operation in the visual designer, and fill in the details as shown in Figure 3. The operation should return String as a status code to reflect if the order has been successfully submitted or not, and will take our BankOrder data transfer object as a parameter. After you added the operation, select Source tab at the top of the visual designer, which will navigate you to the service source code. There, make sure the implementation of the receiveBankOrder() operation corresponds to Listing 2.


Figure 3. Creating Data Transfer Object

Listing 2. BankOrderService.java Banking Web Service implementation

package bankorder.service;

import bankorder.data.BankOrder;
import java.util.HashMap;
import javax.jws.*;
import javax.ejb.Stateless;

@WebService()
@Stateless()
public class BankOrderService {

public static final HashMap bankOrderStorage = new HashMap();

@WebMethod(operationName = "receiveBankOrder")
public String receiveBankOrder(@WebParam(name = "order")
BankOrder order) {
String status = "";
try {
order.setId(bankOrderStorage.size());
bankOrderStorage.put(order.getId(), order);
return "OK";
} catch (Exception e) {
status += e.getLocalizedMessage();
}
return "FAIL" + status;
}

}

Implementing the web service is the final step, and we're ready to deploy the web service to the application server (GlassFish). Right-click the BankApplication node, and select the Undeploy & Deploy menu item. Once the application is deployed, verify your service by invoking BankOrderService -> Test Web Service action. After invocation, your browser window should show a page similar to Figure 4.


Figure 4. Web Service Tester Page

 

AttachmentSize
figure1.png69.91 KB
figure2.png58.05 KB
figure3.png38.63 KB
figure4.png46.74 KB
figure5.png68.87 KB
figure6.png58.29 KB
figure7.png77.2 KB
figure8.png12.83 KB
figure9.png20.8 KB
figure10.png42.9 KB
figure11.png81.43 KB
Published at DZone with permission of its author, Martin Grebac.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Enterprise Integration is a huge problem space for developers, and with so many different technologies to choose from, finding the most elegant solution can be tricky.  The Enterprise Integration Zone is a place for enterprise developers of all backgrounds to share design patterns and technology solutions that make integration easier for various scenarios.  FuseSource proudly supports the EI Zone and provides its own gamut of training, services, and tools based on Apache Camel, ActiveMQ, CXF, and ServiceMix.  

Comments

Jeff Rubinoff replied on Mon, 2008/06/16 - 11:11am

Very nice, simple introduction to WSIT functionality.

nasim khan replied on Tue, 2009/10/06 - 12:04am

Very nice simple introductin of wsit.Any way I'll be subscribing to your feed and I hope you post again soon.

<a href=" http://www.allsarongs.com/"> Sarong </a>

 

 

 

pankaj barman replied on Wed, 2009/10/07 - 12:20pm

I read this article. Pretty good post. I just stumbled upon your blog and wanted to say,simple introduction to WSIT functionality. Lawyers Devon Park

Pankaj Shukla replied on Thu, 2010/01/21 - 8:37am

Bankruptcy - Debt Mediators help you with debt problems through debt consolidation with debt agreements and advice on bankruptcy.

giminicologu (not verified) replied on Mon, 2010/05/31 - 8:54am

This domain needs some very good service client and the best in giving advices about that are those at Trianz and after having a meeting with them you would certainly know better about how you can improve your services .

Ritesh Kumar replied on Thu, 2011/03/10 - 5:32am

Very Well , and easy ....templates to create a web service ........we(me and my friend) enjoyed.....very much in creating this web service ..thanks alot.....

Loops Like replied on Sat, 2011/09/17 - 11:55am

Hello,

It is given in Mack OSX. How can I impliment it in Windows? Please give me a suggession.

loops@  san antonio dentists

Jen Worton replied on Sat, 2011/11/12 - 8:21am

Good tutorial - easy to follow and informative.  Thanks for the detailed instructions on advanced web services.

Jen @ Christmas Advent Calendars

Lucie Hauri replied on Mon, 2012/01/16 - 4:11am in response to: pa1000

it is true... the author has excellent writing skills. I am really impressed. I will follow the above advice. Mallorca property

Bratnyh Tnyh replied on Mon, 2012/02/13 - 4:40am

website design cumbria - Search Marketing solutions to UK businesses looking to promote their websites on the internet and through the search engines.

Inchanto Delmar replied on Tue, 2012/02/21 - 1:18pm

Very informative and simply article. Thank you. chat

Carla Brian replied on Sun, 2012/04/01 - 5:57pm

I will try this one. I thnk this is really effective. Thanks for sharing it though. - Alan Shortall

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.