Search in sources :

Example 81 with Response

use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method deleteWithResponseClassWhileServerWaitTest.

/*
   * @testName: deleteWithResponseClassWhileServerWaitTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:376;
   * 
   * @test_Strategy: Invoke HTTP DELETE method for the current request
   * asynchronously.
   */
@Test
public void deleteWithResponseClassWhileServerWaitTest() throws Fault {
    AsyncInvoker async = startAsyncInvokerForMethod("deleteandwait");
    Future<Response> future = async.delete(Response.class);
    checkFutureOkResponse(future);
// return future;
}
Also used : Response(jakarta.ws.rs.core.Response) AsyncInvoker(jakarta.ws.rs.client.AsyncInvoker) Test(org.junit.jupiter.api.Test)

Example 82 with Response

use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method optionsWithCallbackWhileServerWaitTest.

/*
   * @testName: optionsWithCallbackWhileServerWaitTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:396;
   * 
   * @test_Strategy: Invoke HTTP options method for the current request
   * asynchronously.
   */
@Test
public void optionsWithCallbackWhileServerWaitTest() throws Fault {
    AsyncInvoker async = startAsyncInvokerForMethod("optionsandwait");
    InvocationCallback<Response> callback = createCallback(true);
    Future<Response> future = async.options(callback);
    checkFutureOkResponse(future);
    assertCallbackCall();
// return future;
}
Also used : Response(jakarta.ws.rs.core.Response) AsyncInvoker(jakarta.ws.rs.client.AsyncInvoker) Test(org.junit.jupiter.api.Test)

Example 83 with Response

use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.

the class Resource method getResponseTest.

@GET
@Path("/getResponseTest")
public Response getResponseTest() {
    Response r = Response.ok(TESTID).header("CTS-HEAD", TESTID).build();
    WebApplicationException wae = new WebApplicationException(r);
    return wae.getResponse();
}
Also used : Response(jakarta.ws.rs.core.Response) WebApplicationException(jakarta.ws.rs.WebApplicationException) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

Example 84 with Response

use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method assertResponse.

protected static void assertResponse(WebApplicationException e, Status status) throws Fault {
    assertNotNull(e.getResponse(), "#getResponse is null");
    Response response = e.getResponse();
    assertEqualsInt(response.getStatus(), status.getStatusCode(), "response contains unexpected status", response.getStatus());
    logMsg("response contains expected", status, "status");
}
Also used : Response(jakarta.ws.rs.core.Response)

Example 85 with Response

use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method registerClassWriterContractsInMapTest.

/*
   * @testName: registerClassWriterContractsInMapTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:989;
   * 
   * @test_Strategy: This registration method provides same functionality as
   * register(Class, Class[]) except that any binding priority specified on the
   * registered JAX-RS component class using @Priority annotation is overridden
   * for each extension provider contract type separately with an integer
   * binding priority value specified as a value in the supplied map.
   */
@Test
public void registerClassWriterContractsInMapTest() throws Fault {
    final String content = "registerClassWriterContractsInMapTest";
    Class<?>[] classes = createProviderClasses();
    // entity to send to a server
    Entity<?> entity = getCallableEntity(content);
    // register only once per client build
    IncrementableRegistrar registrar = new IncrementableRegistrar(0, 1) {

        @Override
        public void register(Configurable<?> config, Object registerable) {
            if (currentValue++ == finalValue) {
                Map<Class<?>, Integer> contracts = new HashMap<Class<?>, Integer>();
                contracts.put(MessageBodyWriter.class, 100);
                config.register((Class<?>) registerable, contracts);
            }
        }
    };
    setResourceMethod("echo");
    // configurable each time
    for (int cnt = 0; cnt != configurableCnt; cnt++) {
        // Check the provider is registered
        logMsg("Check on Configurable", Assertable.getLocation(cnt));
        Assertable assertable = getAssertableWithRegisteredProviderClassesOnConfigurable(cnt, 1);
        // set we want to register the provider on Configurable
        // Assertable::LOCATION[cnt]
        registrar.setCurrentValue(0).setFinalValue(cnt);
        Invocation i = checkConfig(registrar, assertable, classes, entity);
        Response response = i.invoke();
        response.bufferEntity();
        String responseString = response.readEntity(String.class);
        assertEquals(content, responseString, "Expected", content, "differs from given", response);
        logMsg("sucessufully wrote Callable by provider registered on Configurable", Assertable.getLocation(cnt));
        // check message body reader contract
        try {
            Callable<?> callable = response.readEntity(Callable.class);
            fault("MessageBodyReader contract has been unexpectedly registered", callable);
        } catch (Exception e) {
            logMsg("MessageBodyReader contract has not been registered as expected", e);
        }
    }
}
Also used : Invocation(jakarta.ws.rs.client.Invocation) HashMap(java.util.HashMap) Configurable(jakarta.ws.rs.core.Configurable) IOException(java.io.IOException) Response(jakarta.ws.rs.core.Response) Assertable(ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable) SingleCheckAssertable(ee.jakarta.tck.ws.rs.api.rs.core.configurable.SingleCheckAssertable) ConfigurableObject(ee.jakarta.tck.ws.rs.api.rs.core.configurable.ConfigurableObject) Test(org.junit.jupiter.api.Test)

Aggregations

Response (jakarta.ws.rs.core.Response)665 Test (org.junit.jupiter.api.Test)551 AsyncInvoker (jakarta.ws.rs.client.AsyncInvoker)78 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)71 ResponseBuilder (jakarta.ws.rs.core.Response.ResponseBuilder)67 Invocation (jakarta.ws.rs.client.Invocation)65 CompletionStageRxInvoker (jakarta.ws.rs.client.CompletionStageRxInvoker)51 Path (jakarta.ws.rs.Path)44 IOException (java.io.IOException)43 SyncInvoker (jakarta.ws.rs.client.SyncInvoker)41 ClientResponseContext (jakarta.ws.rs.client.ClientResponseContext)33 POST (jakarta.ws.rs.POST)27 Client (jakarta.ws.rs.client.Client)25 WebTarget (jakarta.ws.rs.client.WebTarget)24 Link (jakarta.ws.rs.core.Link)23 Status (jakarta.ws.rs.core.Response.Status)23 MediaType (jakarta.ws.rs.core.MediaType)22 Annotation (java.lang.annotation.Annotation)22 Date (java.util.Date)21 GET (jakarta.ws.rs.GET)18