Posts

Showing posts with the label REST

RESTful WS using Jersey Part 3 – Java Client

This post is with reference of Restful WS using Jersey Part 2 – Parameterized approach to provide a java client for accessing Restful services The Complete code for Java Client /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package demo.client; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; /** * * @author Yogesh */ public class JavaClient {     public static void main(String[] args) {         String restUrlStr = " http://localhost:17286/HelloWorldRestWSPrj/resources/hello/Yogesh?query=age";         URLConnection conn = null;         try {             URL restUrl = new URL(restUrlStr);   ...

RESTful WS using Jersey Part 2 – Parameterized approach

Image
This post is in sequel  RESTful WS using Jersey Part 1 - Hello World . It shows how to utilize parameterized urls as well as query string. Please refer Part 1 to know developing restful services from scratch. This post utilizes same example. Parameters can be passed as part of path as well as url query string. Jersey provides two annotations @PathParam   and @QueryParam for extracting parameters from path and query respectively. We have modified getText method to accept both kind of parameters as below 1. Complete resource class will be package demo.resorces; 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; import javax.ws.rs.QueryParam; /** * REST Web Service * * @author Yogesh */ @Path("hello/{UserName}") p...

RESTful WS using Jersey Part 1 - Hello World

Image
Here is the simple tutorial for RESTful Web Service using jersey implementation for RESTful Web Services. Java EE 6 has introduced jersey API as implementation for JSR-311 as API for RESTful Web Services. For ease of development,deployment and testing i have used NetBean 6.8 which supports JEE 6. Jersey is an annotation based implementation. Here are the few important annotations used in this tutorial @path(“/path/”) - a relative URI path indicating where the Java class will be hosted @GET - a request method designator and corresponds to HTTP Get method @POST - a request method designator and corresponds to HTTP Post method @Produces("text/plain") - specify the MIME media types of representations a resource can produce @Consumes("text/plain") -specify the MIME media types of representations a resource can consume @PathParam("User_Name") - a type of parameter that you can extract for use in your resource class @QueryPar...

New Features in Java Enterprise Edition 6 (JEE 6)

Latest version of Java Enterprise Edition is focused on eae of development and simplicity. Key goals of this version are Extensibility – supports for additional technologies and frameworks Profiles – support for creating custom profiles based on application scope or requirement. Pruning New Features introduced in this edition are Simplified EJB 3.1 No local business interface – one step further from EJB 3.0 specification, EJB 3.1 specifications removes mandatory business interface Singleton EJB – to share application wide data and support concurrent access. EJB 3.1 can be part of war file directly without creating a separate jar file EAR >>       WAR >>             JSP/Static Pages             WEB_INF >>         ...

Deploying Services to OC4J with RESTful support

Image
       OC4J container provide support for RESTful services. OC4J installation comes with web service assembling tool (wsa) which take an extra optional parameter to give REST support. This post explains step by step approach to implement and deply RESTful services to OC4J. 1. Interface Code package demo.service; import java.rmi.Remote; import java.rmi.RemoteException; public interface StringService extends Remote{     public String toUppercase(String str) throws RemoteException;     public String toLowerCase(String str)throws RemoteException; } 2. Implementation for Interface package demo.service; import java.rmi.Remote; import java.rmi.RemoteException; public class StringServiceImpl {     public StringServiceImpl() {     }     public String toUppercase(String str){   ...