Posts Tagged apache

How to deploy REST based web services to Liberty Profile ?

In my last blog entry I described how to install Liberty Profile and to configure an Eclipse based development environment.  In this entry, I will show you how to develop & deploy a “Hello World” complexity REST based web service.

Official JAX-RS / Liberty profile is available on IBM Documentation web site.  When developing or debugging REST based services, it is always good to know that IBM’s WebSphere Liberty profile is using Apache’s Wink implementation behind the scene.

Unlike some other Java based application servers (this one and this one for example), WebSphere Liberty Profile does not perform many under covers magical for you, in particular it does not register an application context, you will need to write (one line of) code to do that.

That being said, the process is quite similar for every application server and IDE :

1. Create a web based project

 

Choose a Project Name, select the runtime for deployment and uncheck the “Create EAR” option

2. add a POJO class that will serve as “resource”

Select a package name and class name.

Type the following code :

import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.PathParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;

@javax.ws.rs.ApplicationPath("resources")
@Path("/test")
public class Demo extends javax.ws.rs.core.Application {

    @Context
    private UriInfo context;

    @GET
    @Produces("application/xml")
    public String getXml() {
        return "<xml>Hello Rest World !</xml>";
    }

    @PUT
    @Consumes("application/xml")
    public void putXml(String content) {
    }
}

3. add your business code for the PUT and GET methods

4. Before deploying – Add JAX-RS “feature” to your server configuration

This will tell the Liberty kernel to load the JAX-RS server side implementation. You do not need to restart your server when adding / removing features.

5. Deploy and Test


At this stage, Eclipse’s browser will open on the application default URL and will display an error message.  This is normal as we did not define a landing page or default servlet in this project (index.jsp or index.html) for example.

To access the REST web service, use this URL pattern :

http://<hostname>:<port number>/<project name>/<application path>/<path>

which translates for this example to

http://localhost:9080/TestREST/resources/test

 

Et voilà, you just created, deployed and tested your first REST based web service on WebSphere Liberty Profile.

Enjoy !

 

, , , , , ,

8 Comments

Lotus Symphony Viewer – a free OpenDocument viewer on iPad

I am using OpenOffice from 13+ years, before it was an open source suite and before it was acquired by Sun Microsystems (1999). At that time, StarOffice was the only cross platform productivity suite running on Windows, Linux and Solaris.

After Oracle abandoned the suite – and many other solutions in Sun Microsystems’ portfolio – the situation around Open Office is not easy to follow, let’s try to recap.

  • A group of original developers from Sun, sponsored by Canonical, Novell, RedHat amongst others, forked OpenOffice and created LibreOffice.
  • Oracle donated the original Open Office code base to the Apache Community, now published under an Apache v2 license
  • Several large software editors have created derivative based on the OpenOffice code base, one of them being IBM’s Lotus Symphony (freely available)

Now that OpenOffice code base is not controlled by Oracle anymore, IBM decided to contribute its enhancement to the Apache OpenOffice project.  This is important news for all OpenOffice users.  This means that all improvements and changes made by IBM for Lotus Symphony will be made available for all in OpenOffice.

We are all looking forward the first release combining Apache OpenOffice and Lotus Symphony.

In the mean time, IBM released an iOS viewer application.  It allows you to view Open Document Format (ODF) text documents, presentations, and spreadsheets downloaded to your phone or tablet without the need for any network connection.

IBM OpenDocument Viewer for iOS is freely available on the Apple App Store.

 

 

 

, , , , , , , ,

No Comments