Search in sources :

Example 6 with ClientRequestFilter

use of jakarta.ws.rs.client.ClientRequestFilter 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");
}
Also used : ClientRequestFilter(jakarta.ws.rs.client.ClientRequestFilter) ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) StringBean(ee.jakarta.tck.ws.rs.common.provider.StringBean) Test(org.junit.jupiter.api.Test)

Example 7 with ClientRequestFilter

use of jakarta.ws.rs.client.ClientRequestFilter in project jaxrs-api by eclipse-ee4j.

the class ReaderClient method addProviders.

/**
 * Register providers to client configuration
 *
 * @param response
 *          ClientRequestFilter#abortWith response
 */
protected void addProviders(Response response) throws Fault {
    ClientRequestFilter requestFilter = createRequestFilter(response);
    addProvider(requestFilter);
}
Also used : ClientRequestFilter(jakarta.ws.rs.client.ClientRequestFilter)

Example 8 with ClientRequestFilter

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
 */
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;
}
Also used : ClientRequestFilter(jakarta.ws.rs.client.ClientRequestFilter) ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response)

Example 9 with ClientRequestFilter

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 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;
}
Also used : ClientRequestFilter(jakarta.ws.rs.client.ClientRequestFilter) ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) MediaType(jakarta.ws.rs.core.MediaType)

Example 10 with ClientRequestFilter

use of jakarta.ws.rs.client.ClientRequestFilter in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method createBadResponseFilter.

protected ClientRequestFilter createBadResponseFilter() {
    ClientRequestFilter filter = new ClientRequestFilter() {

        @Override
        public void filter(ClientRequestContext arg0) throws IOException {
            Response r = Response.status(Status.NOT_ACCEPTABLE).build();
            arg0.abortWith(r);
        }
    };
    return filter;
}
Also used : ClientRequestFilter(jakarta.ws.rs.client.ClientRequestFilter) ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response)

Aggregations

ClientRequestFilter (jakarta.ws.rs.client.ClientRequestFilter)13 Response (jakarta.ws.rs.core.Response)11 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)10 Test (org.junit.jupiter.api.Test)4 Invocation (jakarta.ws.rs.client.Invocation)3 JAXRSCommonClient (ee.jakarta.tck.ws.rs.common.JAXRSCommonClient)2 Client (jakarta.ws.rs.client.Client)2 ClientResponseContext (jakarta.ws.rs.client.ClientResponseContext)2 WebTarget (jakarta.ws.rs.client.WebTarget)2 StringBean (ee.jakarta.tck.ws.rs.common.provider.StringBean)1 ClientBuilder (jakarta.ws.rs.client.ClientBuilder)1 Link (jakarta.ws.rs.core.Link)1 Builder (jakarta.ws.rs.core.Link.Builder)1 MediaType (jakarta.ws.rs.core.MediaType)1 UriBuilder (jakarta.ws.rs.core.UriBuilder)1 IOException (java.io.IOException)1