use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class SpecExamples method typeRelationships.
public void typeRelationships() {
Client client = ClientBuilder.newClient();
WebTarget uri = client.target("");
Invocation.Builder builder = uri.request("text/plain");
SyncInvoker syncInvoker = builder;
AsyncInvoker asyncInvoker = builder.async();
Invocation inv = builder.buildGet();
Response r1 = builder.get();
Response r2 = syncInvoker.get();
Response r3 = inv.invoke();
Future<Response> fr1 = asyncInvoker.get();
Future<Response> fr2 = inv.submit();
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class MultipartClient method sendPdfs.
public boolean sendPdfs(Path dir) throws IOException {
List<EntityPart> parts = Files.list(dir).map(this::toPart).collect(Collectors.toList());
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:9080/multipart?dirName=abc");
Entity<List<EntityPart>> entity = Entity.entity(parts, MediaType.MULTIPART_FORM_DATA);
Response response = target.request().post(entity);
return response.getStatus() == 200;
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method buildInvocation.
protected static Invocation buildInvocation(ContextProvider... provider) {
WebTarget target = buildTarget(provider);
Invocation i = target.request().buildGet();
return i;
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getAcceptableLanguagesIsImmutableTest.
/*
* @testName: getAcceptableLanguagesIsImmutableTest
*
* @assertion_ids: JAXRS:JAVADOC:428; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: a read-only list of requested response media types sorted
* according to their q-value, with highest preference first.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getAcceptableLanguagesIsImmutableTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
List<Locale> locales = context.getAcceptableLanguages();
try {
locales.add(Locale.JAPAN);
} catch (Exception e) {
// either exception is thrown, or add does nothing
}
locales = context.getAcceptableLanguages();
boolean b = locales.contains(Locale.JAPAN);
assertTrue(!b, "getAcceptableLanguages is not read-only");
Response r = Response.ok().build();
context.abortWith(r);
}
};
WebTarget target = buildTarget(provider);
Invocation.Builder builder = target.request();
Invocation invocation;
invocation = builder.header("Accept-Language", "da, en-gb;q=0.6, en-us;q=0.7").buildGet();
Response response = invoke(invocation);
assertStatus(response, Status.OK);
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getClientTest.
/*
* @testName: getClientTest
*
* @assertion_ids: JAXRS:JAVADOC:430; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get the client instance associated with the request.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getClientTest() throws Fault {
final Client client = ClientBuilder.newClient();
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
Client contextClient = context.getClient();
assertTrue(client == contextClient, "the client instance is different from the context one");
Response r = Response.ok().build();
context.abortWith(r);
}
};
client.register(provider);
WebTarget target = client.target(getUrl());
Invocation invocation = target.request().buildGet();
Response response = invoke(invocation);
assertStatus(response, Status.OK);
}
Aggregations