use of jakarta.ws.rs.client.ClientRequestFilter in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method createRequestFilter.
// ///////////////////////////////////////////////////////////////////////
protected static ClientRequestFilter createRequestFilter(final Response response) {
ClientRequestFilter outFilter = new ClientRequestFilter() {
@Override
public void filter(ClientRequestContext context) throws IOException {
// logMsg(" -- OUT FILTER --");
Response r;
if (response == null)
r = Response.ok().build();
else
r = response;
context.abortWith(r);
}
};
return outFilter;
}
use of jakarta.ws.rs.client.ClientRequestFilter in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getStatusTest.
/*
* @testName: getStatusTest
*
* @assertion_ids: JAXRS:JAVADOC:472; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: Get the status code associated with the response.
* ClientResponseFilter.filter
*/
@Test
public void getStatusTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
assertTrue(responseContext.getStatus() == 222, "unexpected status " + responseContext.getStatus());
TestUtil.logMsg("Found expected response status 222");
}
};
Response response = Response.status(222).build();
ClientRequestFilter filter = createRequestFilter(response);
Invocation i = buildInvocation(filter, provider);
Response r = invoke(i);
assertTrue(r.getStatus() == 222, "unexpected status " + r.getStatus());
}
use of jakarta.ws.rs.client.ClientRequestFilter 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.ClientRequestFilter 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.ClientRequestFilter 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;
}
Aggregations