2013-06-25 10 views
6

Servlet içine java istirahat WebService Çağrı nasıl WebService Yöntemi Benim Gereği içeride yukarıdaki WebService URL'yi çağırma olduğunui URL'yi yürütmek zaman bir java istirahat WebService URL <code>http://localhost:8080/WebServiceEx/rest/hello/dgdg</code></p> <p>var

bir dize döndürür bir Servlet, herhangi bir Yardım?

ServletCode:

public Class StoreServlet extends HttpServlet{ 
protected void doPost(HttpServletRequest req, HttpServletResponse resp) 
     throws IOException, ServletException { 

//Invoke WebService and Get Response String Here 


} 

WebService Kodu: (- internet üzerinde bir öğretici için bakmak bu amaçlar için)

public class HelloWorldService { 
    @Context 
    private ServletContext context; 

    @GET 
    @Path("/{param}") 
    public Response getMsg(@PathParam("param") String msg) { 

        return Response.status(200).entity(msg).build();  

       } 
    } 

cevap

4

Apache CXF JAX-RS istemci bir göz atın JAX-RS 2.0 kullanıyorsanız

BookStore store = JAXRSClientFactory.create("http://bookstore.com", BookStore.class); 
// (1) remote GET call to http://bookstore.com/bookstore 
Books books = store.getAllBooks(); 
// (2) no remote call 
BookResource subresource = store.getBookSubresource(1); 
// {3} remote GET call to http://bookstore.com/bookstore/1 
Book b = subresource.getBook(); 

Veya, bir client API

örn vardır

Client client = ClientFactory.newClient(); 

String bal = client.target("http://.../atm/balance") 
        .queryParam("card", "111122223333") 
        .queryParam("pin", "9876") 
        .request("text/plain").get(String.class); 

Yoksa sadece düz Java kullanarak bunu "çekirdek" yol yapabilirsiniz: http://www.mkyong.com/webservices/jax-rs/restfull-java-client-with-java-net-url/

İlgili konular