I have a java Rest WebService URL http://localhost:8080/WebServiceEx/rest/hello/dgdg
When i execute the URL ,the WebService Method Returns a String
My Requirement is to call the above WebService URL inside a Servlet ,Could any one Help?
ServletCode:
public Class StoreServlet extends HttpServlet{
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException, ServletException {
//Invoke WebService and Get Response String Here
}
WebService Code:
public class HelloWorldService {
@Context
private ServletContext context;
@GET
@Path("/{param}")
public Response getMsg(@PathParam("param") String msg) {
return Response.status(200).entity(msg).build();
}
}
One possibility is to generate a webservice client using jaxws(for this purposes - look up for a tutorial on the internet). Thus you get some Java classes you can use as usually inside your servlet.
Take a look at Apache CXF JAX-RS client:
http://cxf.apache.org/docs/jax-rs-client-api.html
e.g.
Or, if you use JAX-RS 2.0, it has a client API
e.g.
Or you can do it the "core" way using just plain Java: http://www.mkyong.com/webservices/jax-rs/restfull-java-client-with-java-net-url/