About:
In this blog, I will be explaining on how to create Restful Service where we can read the Http Header Parameters in the Service Class
Code Snippet:
package project1;
import java.util.ArrayList;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
@Path("project1")
public class TestApp {
@Context
private HttpHeaders header;
public TestApp() {
super();
}
private ArrayList al = new ArrayList();
@GET
@Produces("application/xml")
public String greet()
{
String userAgent = header.getRequestHeader("UserType").get(0);
return ""+userAgent+" ";
}
}
In JAX-WS we can use the MessageContext to read the header parameters but in the caseof Restful services we have to use the @Context parameter to get the Header values
Consuming In Client :
In my other blog i will be explaining on how to pass header parameters to service like above using WebService DataControl in Jdeveloper Link.
Nice explanation, Have you written the Consuming in Client? I mean WebService DataControl in Jdev. I am trying to write a client using Webservice DataControl for a service which consumes an xml and produces an xml. Your post would be really helpful.
ReplyDeleteHi Prabhu,
ReplyDeleteRefer this Blog : http://alemathe.blogspot.in/2014/04/passing-header-parameters-in-webservice.html