use of ee.jakarta.tck.ws.rs.common.impl.ReplacingOutputStream in project jaxrs-api by eclipse-ee4j.
the class EntityWriterInterceptor method aroundWriteTo.
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
MultivaluedMap<String, Object> headers = context.getHeaders();
String header = (String) headers.getFirst(Resource.HEADERNAME);
if (header != null && header.startsWith(getClass().getName())) {
StringBuilder sb = new StringBuilder();
sb.append("<interceptor>").append(getClass().getName());
if (header.contains(Resource.DIRECTION))
sb.append(Resource.DIRECTION);
sb.append("</interceptor>");
String content = sb.toString();
ReplacingOutputStream stream = new ReplacingOutputStream(context.getOutputStream(), content);
context.setOutputStream(stream);
headers.remove(Resource.HEADERNAME);
}
context.proceed();
}
use of ee.jakarta.tck.ws.rs.common.impl.ReplacingOutputStream in project jaxrs-api by eclipse-ee4j.
the class InterceptorBodyOne method setOutputStream.
public void setOutputStream() throws IOException {
OutputStream originalStream = context.getOutputStream();
OutputStream replace = new ReplacingOutputStream(originalStream, 't', 'x');
context.setOutputStream(replace);
}
use of ee.jakarta.tck.ws.rs.common.impl.ReplacingOutputStream in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getEntityStreamTest.
/* Run test */
/*
* @testName: getEntityStreamTest
*
* @assertion_ids: JAXRS:JAVADOC:437; JAXRS:JAVADOC:451; JAXRS:JAVADOC:455;
* JAXRS:JAVADOC:456;
*
* @test_Strategy: Get the entity output stream. Set a new entity output
* stream.
*/
@Test
public void getEntityStreamTest() throws Fault {
final String entityStreamWorks = "ENTITY_STREAM_WORKS";
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
OutputStream stream = context.getEntityStream();
ReplacingOutputStream wrapper = new ReplacingOutputStream(stream, 'X', 'T');
context.setEntityStream(wrapper);
}
};
ByteArrayInputStream entity = new ByteArrayInputStream(entityStreamWorks.replace('T', 'X').getBytes());
addProvider(provider);
setRequestContentEntity(entity);
setProperty(Property.REQUEST, buildRequest(Request.POST, "post"));
invoke();
String body = getResponseBody();
assertContains(body, entityStreamWorks);
}
Aggregations