Search in sources :

Example 1 with ReplacingOutputStream

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();
}
Also used : ReplacingOutputStream(ee.jakarta.tck.ws.rs.common.impl.ReplacingOutputStream)

Example 2 with ReplacingOutputStream

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);
}
Also used : OutputStream(java.io.OutputStream) ReplacingOutputStream(ee.jakarta.tck.ws.rs.common.impl.ReplacingOutputStream) ReplacingOutputStream(ee.jakarta.tck.ws.rs.common.impl.ReplacingOutputStream)

Example 3 with ReplacingOutputStream

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);
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) ByteArrayInputStream(java.io.ByteArrayInputStream) OutputStream(java.io.OutputStream) ReplacingOutputStream(ee.jakarta.tck.ws.rs.common.impl.ReplacingOutputStream) ContextProvider(ee.jakarta.tck.ws.rs.api.client.clientrequestcontext.ContextProvider) ReplacingOutputStream(ee.jakarta.tck.ws.rs.common.impl.ReplacingOutputStream) Test(org.junit.jupiter.api.Test)

Aggregations

ReplacingOutputStream (ee.jakarta.tck.ws.rs.common.impl.ReplacingOutputStream)3 OutputStream (java.io.OutputStream)2 ContextProvider (ee.jakarta.tck.ws.rs.api.client.clientrequestcontext.ContextProvider)1 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Test (org.junit.jupiter.api.Test)1