For invoking an HTTP request, we require an instance of Invocation Builder. An Invocation Builder instance is created using the web target's request method. Invocation Builder is basically used for wrapping up response media type, headers, properties, authentication token, cookies, and so on. These can be used for data manipulation or authentication at the server side. Let's look at the following example:
WebTarget target = client.target("http://localhost:8080/Chapter2/services/getResource"); Invocation.Builder builder = target.request("text/plain"); Invocation invocation = builder.buildGet(); String responseData = invocation.invoke(String.class);
Here, we first created an instance of WebTarget
for the URI from the client instance. We set the accept type in the request and set the instance to Invocation.Builder
. We then wrapped the Builder instance to Invocation; that is, our request is ready with the headers/properties, data, and so on, and ready to call the web...