use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method createRequestFilter.
// ///////////////////////////////////////////////////////////////////////
/**
* Simulates server side
*
* @return Response containing request method and entity
*/
protected ClientRequestFilter createRequestFilter() {
ClientRequestFilter filter = new ClientRequestFilter() {
@Override
public void filter(ClientRequestContext ctx) throws IOException {
StringBuilder sb = new StringBuilder();
sb.append(ctx.getMethod()).append(";");
if (ctx.hasEntity())
sb.append(ctx.getEntity()).append(";");
Response r = Response.ok(sb.toString()).build();
ctx.abortWith(r);
}
};
return filter;
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method fromResourceMethodLinkUsedInInvocationTest.
/*
* @testName: fromResourceMethodLinkUsedInInvocationTest
*
* @assertion_ids: JAXRS:JAVADOC:787;
*
* @test_Strategy: Generate a link by introspecting a resource method.
*/
@Test
public void fromResourceMethodLinkUsedInInvocationTest() throws Fault {
final String linkName = "link";
Client client = ClientBuilder.newClient();
client.register(new ClientRequestFilter() {
@Override
public void filter(ClientRequestContext ctx) throws IOException {
String uri = ctx.getUri().toASCIIString();
Link.Builder builder = Link.fromMethod(Resource.class, "consumesAppJson").rel(linkName);
Link link = builder.build();
Response response = Response.ok(uri).links(link).build();
ctx.abortWith(response);
}
});
// Phase 1, ask for a link;
WebTarget target = client.target(url() + "resource/get");
Response response = target.request().get();
String entity = response.readEntity(String.class);
assertTrue(response.hasLink(linkName), "No link received");
assertContains(url() + "resource/get", entity);
// Phase 2, use the link, check the correctness
assertTrue(response.hasLink(linkName), "No link received");
Link link = response.getLink(linkName);
response = client.invocation(link).post(null);
entity = response.readEntity(String.class);
assertTrue(response.hasLink(linkName), "No link received");
assertContains(url() + "resource/consumesappjson", entity);
logMsg("Opaque Link has been used in Client.invocation() sucessfully");
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class ReaderClient method createRequestFilter.
/**
* Create a request filter to be aborted with given fake response simulating
* the resource from a request
*
* @param response
* @return
*/
protected static ClientRequestFilter createRequestFilter(final Response response) {
ClientRequestFilter outFilter = new ClientRequestFilter() {
@Override
public void filter(ClientRequestContext context) throws IOException {
Response r;
if (response == null)
r = Response.ok().build();
else
r = response;
context.abortWith(r);
}
};
return outFilter;
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getHeaderStringUsesToStringTest.
/*
* @testName: getHeaderStringUsesToStringTest
*
* @assertion_ids: JAXRS:JAVADOC:780;
*
* @test_Strategy: Get a HTTP header as a single string value. Each single
* header value is converted to String using its toString method if a header
* delegate is not available.
*/
@Test
public void getHeaderStringUsesToStringTest() throws Fault {
final StringBean bean = new StringBean("bean");
ClientRequestFilter filter = new ClientRequestFilter() {
@Override
public void filter(ClientRequestContext ctx) throws IOException {
ctx.getHeaders().add(bean.get(), bean);
}
};
setProperty(Property.REQUEST, buildRequest(Request.POST, "headerstring"));
setProperty(Property.CONTENT, bean.get());
addProvider(filter);
setProperty(Property.SEARCH_STRING, bean.toString());
invoke();
logMsg("#getHeaderString() returned expected header converted by toString() method");
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method setMethodTest.
/*
* @testName: setMethodTest
*
* @assertion_ids: JAXRS:JAVADOC:452; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
*
* @test_Strategy: Set the request method.
*/
@Test
public void setMethodTest() throws Fault {
String entity = "ENTITY";
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
context.setMethod("PUT");
}
};
addProvider(provider);
setRequestContentEntity(entity);
setProperty(Property.REQUEST, buildRequest(Request.POST, "put"));
invoke();
String body = getResponseBody();
assertContains(body, entity);
}
Aggregations