use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getHeadersIsMutableTest.
/*
* @testName: getHeadersIsMutableTest
*
* @assertion_ids: JAXRS:JAVADOC:439; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
*
* @test_Strategy: Get the generic entity type information.
*/
@Test
public void getHeadersIsMutableTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
MultivaluedMap<String, Object> headers = context.getHeaders();
headers.add("Accept-Language", "en_gb");
headers.add("Date", "Tue, 15 Nov 1994 08:12:31 GMT");
headers.add("tck", "cts");
}
};
addProvider(provider);
setProperty(Property.REQUEST, buildRequest(Request.GET, "headers"));
invoke();
String body = getResponseBody().toLowerCase();
assertContains(body, "accept-language");
assertContains(body, "date");
assertContains(body, "tck");
}
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
*/
private static 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 createRequestFilter.
// ///////////////////////////////////////////////////////////////////////
/**
* Simulates server side
*
* @return Response containing request method and entity
*/
protected static ClientRequestFilter createRequestFilter() {
ClientRequestFilter filter = new ClientRequestFilter() {
@Override
public void filter(ClientRequestContext ctx) throws IOException {
StringBuilder sb = new StringBuilder();
sb.append(ctx.getMethod()).append(";");
sb.append(ctx.getUri().toASCIIString()).append(";");
if (ctx.hasEntity())
sb.append(ctx.getEntity()).append(";");
List<MediaType> list = ctx.getAcceptableMediaTypes();
for (MediaType type : list) sb.append(type).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 getAllowedMethodsTest.
/*
* @testName: getAllowedMethodsTest
*
* @assertion_ids: JAXRS:JAVADOC:457; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: Get the allowed HTTP methods from the Allow HTTP header.
* All methods will returned as upper case strings.
*
* ClientResponseFilter.filter
*/
@Test
public void getAllowedMethodsTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
Set<String> map = responseContext.getAllowedMethods();
logMsg("found methods:", JaxrsUtil.iterableToString(" ", map));
assertTrue(map.size() == 2, "Allowed mthods were not set");
assertTrue(map.contains("OPTIONS"), "OPTIONS allowed method were not found");
assertTrue(map.contains("GET"), "GET allowed method was not found");
}
};
Response response = Response.ok().header(HttpHeaders.ALLOW, "get").header(HttpHeaders.ALLOW, "options").build();
invokeWithResponseAndAssertStatus(response, Status.OK, provider);
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method setEntityStreamTest.
/*
* @testName: setEntityStreamTest
*
* @assertion_ids: JAXRS:JAVADOC:476; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: Set a new entity input stream. ClientResponseFilter.filter
*/
@Test
public void setEntityStreamTest() throws Fault {
final String entity = "ENTITY";
ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
responseContext.setEntityStream(new ByteArrayInputStream(entity.getBytes()));
InputStream stream = responseContext.getEntityStream();
assertTrue(stream != null, "the #getEntityStream is null");
InputStreamReader isr = new InputStreamReader(stream);
BufferedReader br = new BufferedReader(isr);
String line = null;
try {
line = br.readLine();
} catch (IOException e) {
throw new Fault(e);
} finally {
try {
br.close();
} catch (IOException e) {
}
}
assertTrue(entity.equals(line), "The #getEntityStream " + line + " is not equal to what is inserted to the response: " + entity);
logMsg("#setEntityStream(", entity, ") set entity", line);
}
};
Response response = Response.ok().build();
invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
Aggregations