use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method startAsyncInvokerForMethod.
/**
* Create AsyncInvoker for given resource method and start time
*/
protected AsyncInvoker startAsyncInvokerForMethod(String methodName) {
Client client = ClientBuilder.newClient();
client.register(new JdkLoggingFilter(false));
WebTarget target = client.target(getUrl(methodName));
AsyncInvoker async = target.request().async();
setStartTime();
return async;
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JaxrsWebTestCase method execute.
/**
* Executes the test case.
*
* @throws TestFailureException
* if the test fails for any reason.
* @throws IllegalStateException
* if no request was configured or if no Validator is available at
* runtime.
*/
public void execute() throws TestFailureException {
verifyValidationStrategy();
verifySettings();
try {
String url = logClientRequestAndGetUrl();
client = getClientWithRegisteredProviders();
WebTarget target = client.target(url.toString());
Invocation i = buildRequest(target);
response = invoke(i);
if (bufferEntity)
response.bufferEntity();
} catch (Throwable t) {
String message = t.getMessage();
StringBuilder sb = new StringBuilder();
sb.append("[FATAL] Unexpected failure during test execution.\n");
// print client call code to report into JIRA when needed
sb.append(printClientCall().toString());
// Inherited message
sb.append((message == null ? t.toString() : message));
throw new TestFailureException(sb.toString(), t);
}
// Validate this test case instance
if (!strategy.validate(this)) {
throw new TestFailureException("Test FAILED!");
}
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class BasicExamples method creatingResourceAndSubResourceUris.
public void creatingResourceAndSubResourceUris() {
// Target( http://jaxrs.examples.org/jaxrsApplication/customers/ )
WebTarget customersUri = ClientBuilder.newClient().target("http://jaxrs.examples.org/jaxrsApplication/customers");
// Target( http://jaxrs.examples.org/jaxrsApplication/customers/{id}/ )
WebTarget anyCustomerUri = customersUri.path("{id}");
// Target( http://jaxrs.examples.org/jaxrsApplication/customers/123/ )
WebTarget customer123 = anyCustomerUri.resolveTemplate("id", 123);
assert customer123 != null;
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class CacheExample method cacheExample.
public void cacheExample() {
Client client = ClientBuilder.newClient();
client.register(CachingFeature.class);
WebTarget resource = client.target("http://example.com/foo/bar.txt");
String text = resource.request("text/plain").get(String.class);
String second = resource.request("text/plain").get(String.class);
System.out.println(text);
System.out.println(second);
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class GzipExample method gzipExample.
public void gzipExample() {
WebTarget target = ClientBuilder.newClient().target("http://example.com/foo/bar.txt");
target.register(GzipEntityInterceptor.class);
// getting a gzip encoded body
String body = target.request("text/plain").get(String.class);
// send a gzip encoded body
target.request().header("Content-Encoding", "gzip").post(text(body));
}
Aggregations