Showing posts with label Hello World. Show all posts
Showing posts with label Hello World. Show all posts

Saturday, May 9, 2009

Tools for connecting to IBM WAS Service Integration Bus

For the past year me and my colleagues at CROZ were doing a lot of work that included using service integration bus (SIB) and WAS 6.1 as JMS provider. Very often we needed to look are there any messages in queue or send test message. Two basic tools that does the job comes with WAS distribution:
  • WAS admin console

  • Universal test client (UTC)
Admin console can be used for looking queue (and topic) status at runtime. You can use UTC for sending and posting message using JMS API. However admin console is very cumbersome to use because you need to make 10 clicks to see message content and UTC is okay only for basic scenario.

So what other tools you can use to connect to SIB? Preferably stand alone one.

There are actually 3 nice tools from IBM and few from open source community that are very handy. From IBM you have:
  1. Service Integration Bus Explorer
  2. Service Integration Bus Performance
  3. IBM Client Application Tool for JMS


There are also very nice open source tools that can be connected to WAS SIB. I will mention :
  1. Hermes JMS
  2. Apache JMeter

Service Integration Bus Explorer

SIB explorer Tool that we used the most was SIB Explorer. It is stand alone tool from IBM alphaWorks. Installation is simple and described here. Trickier part is downloading SWT libraries. I have in my swt dir (version number may vary)
  • org.eclipse.swt.win32.win32.x86_3.3.2.v3347a.jar
  • org.eclipse.swt_3.3.2.v3347.jar
  • swt-gdip-win32-3347.dll
  • swt-win32-3347.dll
The reason this tool is very handy is that everything is there and you don't need to click too much. If you like to see what messages are in what queue you just open queue points and there you have all queues with their current depth. However for putting new messages in queue it is not so great because you can't add any message property (for instance targetService for SOAP/JMS).

Service Integration Bus Performance

If you need to get some SIB performance related data this tool can be very useful. You can use it to monitor thread pools, queues, topic spaces, communication and data store in near real time (with refresh every 2s). We didn't use it much as we have ITCAM but data it provides can be used for performance tuning. Also you can detect some anomalies like messages with inadequate reliability level.

IBM Client Application Tool for JMS

If you need to experiment a lot with putting messages in queue than you should probably use this tool. It also come from IBM alphaWorks but it doesn't require SWT libraries. However this tool connects to WAS JNDI so you need to have JMS JNDI resources defined. Dan Zrobok has wrote how to connect to the WAS from this tool. Once you connect you can send and receive message (tabs Message Producer and PtoP Message Consumer). Very nice feature is registering new Message Listener. Window pops up for every new message that is deliverd to destination that listener listens to.

Hermes JMS

One more tool you can use for exploring SIB destinations and posting is Hermes JMS. It can be quite handy if you have (or wanna have) messages stored in files and use them for testing. Also you can save messages to file from destinations for later use. Unfortunately Hermes JMS doesn't come with SIB adapter (only with WebSphere MQ one) so you must set it up on your own. It isn't trivial but you can start with downloading "IBM Client for JMS on J2SE with IBM WebSphere Application Server" and installing it. There are also some resources on the web available describing the whole procedure.

Apache JMeter

Another tool that can be very useful is Apache JMeter. With JMeter you can send and receive P2P messages using JMS Point-to-Point sampler. Publish-Subscribe functionality is also available. I was using JMeter for performance testing and also for functional testing. It is really great because you can set up JMS test case and test your messaging infrastructure with it. To set it up connect to the WAS SIB, you will also need IBM Client for JMS on J2SE with IBM WebSphere Application Server. If you need instructions on any of these tools please reply and maybe I'll blog about it.

Friday, April 3, 2009

Hello World! REST service using Jersey and WebSphere Application Server v6.1 (WAS)

I was wondering how easy it is to create Hello World REST service using Jersey and deploying it to WAS 6.1. Long story short: It is really easy. So here are the steps:

  1. Download jersey-archive-1.0.2.zip from http://jersey.dev.java.net/.
  2. Extract jersey-archive-1.0.2.zip.
  3. Go to your favorite tool for WAS development. Mine was Rational Software Architect 7.5 (RSA) but the same steps works for 7.0.
  4. Create new Dynamic web project (HelloWorldRest). In RSA 7.5 you should choose WAS 6.1 as your target platform. Also choose Servlet spec 2.4.
  5. Copy jersey jars from lib folder. That’s the folder where you extracted jersey archive in step 2. Put them in the WEB-INF/lib folder.
  6. Now you must add Servlet configuration and mapping. You can do this through wizard or you can copy the following in web.xml just after display-name element:
    
     Jersey Servlet
     ServletContainer
     ServletContainer
     com.sun.jersey.spi.container.servlet.ServletContainer
    
    
     ServletContainer
     /resources/*
    
    
    With this in place we have configured Jersey servlet. It will serve REST services with pattern resources in URI.
  7. Now we can create service implementation class. We are creating simple POJO class (in JAX-RS term Root Resource Class) with one method like one below:
    /**
     * 
     */
    package org.example;
    
    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.Produces;
    import javax.ws.rs.QueryParam;
    
    @Path("/helloworld")
    public class HelloWorldResource {
    
     @GET
     @Produces("text/plain")
     public String sayHello(@QueryParam("world") String world) {
      return "Hello " + world;
     }
    
    }
    
    The interesting bits are four annotations:
    1. @Path("/helloworld") – this annotation exposes methods in this class through helloword path. Annotation value is the thing that we will add after resources in URI to call this service
    2. @GET – annotated method (sayHello) is available through HTTP GET method
    3. @Produces("text/plain") – method will return plain text
    4. @QueryParam("world") – with this annotation we are mapping URI parameter world to method parameter world
  8. Deploy project on server!
And that’s it. Now we can test service using browser. If you enter following URI: http://localhost:9080/HelloWorldRest/resources/helloworld?world=World! you should get response in clear text, as expected: Hello World!. Next we can create a simple stand alone client for this service. I have:
  1. Created a new Java project called HelloWorldRestJava.
  2. Created new folder called lib.
  3. Copied jars from WEB-INF/lib to lib folder. Added them to project classpath.
  4. Created new class with main method:
    package org.example;
    
    import com.sun.jersey.api.client.Client;
    import com.sun.jersey.api.client.WebResource;
    
    public class HelloWorldRestClient {
    
     public static void main(String[] args) {
      Client client = new Client();
      WebResource webResource = client.resource("http://localhost:9080/HelloWorldRest");
      String response = webResource.path("resources").path("helloworld")
        .queryParam("world", "World!").get(String.class);
      System.out.println("Response: " + response);
     }
    }
    
  5. Run the client as Java application.
If you do the same you should see Response: Hello World! in the console. Now when you saw how easy it is, you can continue to play with Jersey.