See: Description
| Class | Description |
|---|---|
| WebResourceFactory |
Factory for client-side representation of a resource.
|
Consider a server which exposes a resource at http://localhost:8080. The resource can be described by the following interface:
@Path("myresource")
public interface MyResourceIfc {
@GET
@Produces("text/plain")
String get();
@POST
@Consumes("application/xml")
@Produces("application/xml")
MyBean postEcho(MyBean bean);
@Path("{id}")
@GET
@Produces("text/plain")
String getById(@PathParam("id") String id);
}
You can use WebResourceFactory class defined in this package to access the server-side resource using this interface. Here is an example:
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:8080/");
MyResourceIfc resource = WebResourceFactory.newResource(MyResourceIfc.class, target);
String responseFromGet = resource.get();
MyBean responseFromPost = resource.postEcho(myBeanInstance);
String responseFromGetById = resource.getById("abc");
Copyright © 2007-2017, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.