Friday, April 30, 2010

JAX-RS and Jersey

To start with let me give you an one line overview of Jersey, Jersey is the open source and JAX-RS (JSR 311) Reference Implementation for building RESTful Web services.

JAX-RS came along initially as a way of writing RESTful services on the Java platform; using annotations and loose coupling to bind resource beans and their public methods to URIs, HTTP methods and MIME content type negotiation. I've said before I think its awesome, one of the most impressive JSRs we've had.

Root Resource:

Here's simple POJOs (Plain Old Java Objects) that are annotated with @Path have at least one method annotated with @Path or a resource method designator annotation such as @GET, @PUT, @POST, or @DELETE. Resource methods are methods of a resource class annotated with a resource method designator.

The following code example of a root resource class using JAX-RS annotations Java Objects to create RESTful Web Services. The example code shown here is from one of the samples that ships with Jersey, the zip file of which can be found in the maven repository here.



// The Java class will be hosted at the URI path "/helloworld"
public class HelloWorldResource {
// The Java method will process HTTP GET requests
// The Java method will produce content identified by the MIME Media
// type "text/plain"
public String getClichedMessage() {
// Return some cliched textual content
return "Hello World";

Relative URI: @Path

The @Path annotation's value is a relative URI path. In the example above, the Java class will be hosted at the URI path /helloworld. This is an extremely simple use of the @Path annotation. What makes JAX-RS so useful is that you can embed variables in the URIs.

URI path templates are URIs with variables embedded within the URI syntax. These variables are substituted at runtime in order for a resource to respond to a request based on the substituted URI. Variables are denoted by curly braces. For example, look at the following @Path annotation:

Here a user will be prompted to enter their name, and then a Jersey web service configured to respond to requests to this URI path template will respond. For example, if the user entered their username as "Vikas", the web service will respond to the following URL:

Better Content Negotiation Support : @producer & @Consumes

The @Produces annotation is used to specify the MIME media types of representations a resource can produce and send back to the client. In this example, the Java method will produce representations identified by the MIME media type "text/plain".
you might want to prefer to return HTML over XML/JSON so unless folks ask specifically just for XML or JSON you return HTML.

Http Methods: @GET, @PUT, @POST, @DELETE and @HEAD

These are resource method designator annotations defined by JAX-RS and which correspond to the similarly named HTTP methods.

Sunday, April 18, 2010

Working with Spring Roo -2

Just finished creating project in spring roo with JPA provider, Hibernate. what's cool about it, roo take care of everything and create spring project for you, including all source classes and spring appicationContext.xml and all test classes, and creates POM.xml for you to use for build and test far able to run project using selenium and tomcat as server.

here are some commands:

project --topLevelPackage com.vikasroo (creates project structure, pom.xml and spring app context)
persistence setup --provider HIBERNATE --database (creates JPA project with Hibernate as JPA provider)
entity --name ~.vikas.Kuma (creates Entity for JPA)
test integration (will verify command JPA operations in test)

its all about TAB in spring Roo...try it out. its good to have some prior Maven knowledge to use this.

Monday, April 12, 2010

Amazon Announced Simple Notification Service

Amazon recently announced "Simple Notification Service", here's basic information about SNS:

Amazon Simple Notification Service (Amazon SNS) is a web service that makes it easy to set up, operate, and send notifications from the cloud. It provides developers with a highly scalable, flexible, and cost-effective capability to publish messages from an application and immediately deliver them to subscribers or other applications. It is designed to make web-scale computing easier for developers.

Amazon SNS provides a simple web services interface that can be used to create topics you want to notify applications (or people) about, subscribe clients to these topics, publish messages, and have these messages delivered over clients’ protocol of choice (i.e. HTTP, email, etc.). Amazon SNS delivers notifications to clients using a “push” mechanism that eliminates the need to periodically check or “poll” for new information and updates. Amazon SNS can be leveraged to build highly reliable, event-driven workflows and messaging applications without the need for complex middleware and application management. The potential uses for Amazon SNS include monitoring applications, workflow systems, time-sensitive information updates, mobile applications, and many others. As with all Amazon Web Services, there are no up-front investments required, and you pay only for the resources you use.

Saturday, April 10, 2010

Working with Spring Roo -1

Today I start working on my new task from my own TODO list. To work on Spring Roo, I have already installed Spring Roo, when Spring announced Roo with Spring 3.0. Next few days i'll be working on small test app with Spring Roo.

Here's little background of Spring Roo, its targeted to make coder life easier by creating project in few steps. it worked from command line and can guide you, if you don't know what to do next? Spring Roo usage AspectJ behind the scene to inspect and create code for you.

Will update this post once I'm done with Spring Roo test application.

You can download Spring Roo from here.

Tuesday, April 6, 2010

Installation Wiki

While installing JBoss Tools 3.1 on Eclipse 3.5.1 and creating a update site, you can run into problem with network proxy (depending how's security set up for your web server), as it will ask for user & password to access internet to get in to JBoss update site (even if its local site). here's one work around of this problem, add this line in to your Eclipse.ini file (which is in under your eclipse folder) and restart eclipse. This should resolve proxy problem.

Set the following system property in you eclipse.ini file: -


Also, while doing some research on this topic, came across this site, which can be very useful for enterprise. So that you don't end up writing bunch of installation guide.

Saturday, April 3, 2010

MySQL on Mac

Today I'm working with installing MySQL on my MacPro, I found these useful site for installing MySQL on mac...

Mac OS version 10.2 and higher

1- Download the package mentioned above to your desktop. Unpack it and then double-click on the .pkg file to install it.
2- Open a terminal window and type in the following commands (without the double quotes):
3- type cd /usr/local/mysql
4- type sudo chown -R mysql data/, enter your Mac OS X account password when asked for it.
5- To start the server, issue sudo echo first, then type sudo ./bin/mysqld_safe &
6- Use it with /usr/local/mysql/bin/mysql test

Useful Links:

One thing I would like to mention here for bash shell, which is the default for new user accounts created under Mac OS X 10.3, the command is:

echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile

Hope this will help.