use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getConfigurationTest.
/*
* @testName: getConfigurationTest
*
* @assertion_ids: JAXRS:JAVADOC:977; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get the immutable configuration of the request.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getConfigurationTest() throws Fault {
final Client client = ClientBuilder.newClient();
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
Client contextClient = context.getClient();
assertEquals(contextClient, client, "the client instance is different from the context one");
Configuration contextConfig = context.getConfiguration();
assertNotNull(contextConfig, "context.getConfiguration() returned null");
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);
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method setEntityTest.
/*
* @testName: setEntityTest
*
* @assertion_ids: JAXRS:JAVADOC:450; JAXRS:JAVADOC:434; JAXRS:JAVADOC:435;
* JAXRS:JAVADOC:438; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456; JAXRS:SPEC:85;
*
* @test_Strategy: Set a new response message entity. It is the callers
* responsibility to wrap the actual entity with
* jakarta.ws.rs.core.GenericEntity if preservation of its generic type is
* required.
*
* ClientRequestFilter.abortWith
*/
@Test
public void setEntityTest() throws Fault {
final AtomicInteger counter = new AtomicInteger(0);
ContextProvider provider = new SetEntityProvider(counter);
ContextProvider provider2 = new SetEntityProvider(counter) {
};
Entity<ByteArrayInputStream> entity = createEntity(new ByteArrayInputStream("test".getBytes()));
WebTarget target = buildTarget(provider, provider2);
Invocation invocation = target.request().buildPost(entity);
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 buildInvocation.
protected static Invocation buildInvocation(ClientRequestFilter requestFilter, ContextProvider... provider) {
WebTarget target = buildTarget(requestFilter, provider);
Invocation i = target.request().buildGet();
return i;
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class MultipartClient method retrievePdfs.
public List<Path> retrievePdfs(String remoteDirName) throws IOException {
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:9080/multipart").queryParam("dirName", remoteDirName);
Response response = target.request(MediaType.MULTIPART_FORM_DATA).get();
List<EntityPart> parts = response.readEntity(new GenericType<List<EntityPart>>() {
});
return parts.stream().map(part -> {
try (InputStream is = part.getContent()) {
Path file = Files.createFile(Paths.get(part.getFileName().orElse(part.getName() + ".pdf")));
Files.copy(is, file);
return file;
} catch (IOException ioex) {
LOG.log(Level.WARNING, "Failed to process attachment part {0}", part);
return null;
}
}).collect(Collectors.toList());
}
use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method createSyncInvokerForMethod.
/**
* Create SyncInvoker for given resource method and start time
*/
protected SyncInvoker createSyncInvokerForMethod(String methodName) {
Client client = ClientBuilder.newClient();
client.register(new JdkLoggingFilter(false));
WebTarget target = client.target(getUrl(methodName));
SyncInvoker sync = target.request();
return sync;
}
Aggregations