Search in sources :

Example 91 with Response

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

the class StreamOutputTest method testIOException.

@GET
@Path("IOExceptionTest")
public Response testIOException() {
    StreamingOutput so = new StreamingOutput() {

        public void write(OutputStream output) throws IOException {
            throw new IOException("TckIOExceptionTest");
        }
    };
    Response response = Response.ok(so).build();
    return response;
}
Also used : Response(jakarta.ws.rs.core.Response) OutputStream(java.io.OutputStream) StreamingOutput(jakarta.ws.rs.core.StreamingOutput) IOException(java.io.IOException) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

Example 92 with Response

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

the class JAXRSClientIT method getLanguageNotPresentTest.

/*
   * @testName: getLanguageNotPresentTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:850;
   * 
   * @test_Strategy: Get null if not present.
   */
@Test
public void getLanguageNotPresentTest() throws Fault {
    ResponseHeaderValue<Locale> value = new ResponseHeaderValue<>();
    addProvider(new HeaderNotPresent<Locale>(value) {

        @Override
        protected void setHeader(ClientResponseContext responseContext, ResponseHeaderValue<Locale> header) {
            header.value = responseContext.getLanguage();
        }
    });
    Response response = invokePost("language", null);
    Locale locale = response.getLanguage();
    assertHeaderNull(locale, value, "getLanguage");
}
Also used : Locale(java.util.Locale) Response(jakarta.ws.rs.core.Response) ClientResponseContext(jakarta.ws.rs.client.ClientResponseContext) Test(org.junit.jupiter.api.Test)

Example 93 with Response

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

the class JAXRSClientIT method readEntityGenericTypeCloseIsNotCalledOnInputStreamTest.

/*
   * @testName: readEntityGenericTypeCloseIsNotCalledOnInputStreamTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:866;
   * 
   * @test_Strategy: Unless the supplied entity type is an input stream, this
   * method automatically closes the consumed response entity stream if it is
   * not buffered.
   */
@Test
public void readEntityGenericTypeCloseIsNotCalledOnInputStreamTest() throws Fault {
    AtomicInteger ai = setCorruptedStream();
    Response response = invokeGet("corrupted");
    try {
        response.readEntity(generic(InputStream.class));
        logMsg("Close() has not been called on entity stream as expected");
    } catch (Exception e) {
        throw new Fault("Close was called", e);
    }
    assertTrue(ai.get() == 0, "Close was called");
}
Also used : Response(jakarta.ws.rs.core.Response) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InputStream(java.io.InputStream) ProcessingException(jakarta.ws.rs.ProcessingException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 94 with Response

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

the class JAXRSClientIT method responseCreatedRelativeURITest.

/*
   * @testName: responseCreatedRelativeURITest
   *
   * @assertion_ids: JAXRS:JAVADOC:121;
   *
   * @test_Strategy: The resource calls Response.created() to set the Location header with a
   * relative URI. The relative URI should be converted into an absolute URI by resolving it
   * relative to the base URI.
   */
@Test
public void responseCreatedRelativeURITest() throws Fault {
    String resourceUrl = getAbsoluteUrl();
    String expected = resourceUrl.substring(0, resourceUrl.length() - "resource".length()) + "created";
    Response response = invokeGet("created");
    try {
        assertTrue(expected.equals(response.getHeaderString("location")), "#response.getHeaderString(\"location\") [" + response.getHeaderString("location") + "] differs from " + expected);
    } finally {
        response.close();
    }
}
Also used : Response(jakarta.ws.rs.core.Response) Test(org.junit.jupiter.api.Test)

Example 95 with Response

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

the class JAXRSClientIT method readEntityClassAnnotationTest.

/*
   * @testName: readEntityClassAnnotationTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:869;
   * 
   * @test_Strategy: Read the message entity input stream as an instance of
   * specified Java type using a MessageBodyReader that supports mapping the
   * message entity stream onto the requested type. annotations - annotations
   * that will be passed to the MessageBodyReader.
   */
@Test
public void readEntityClassAnnotationTest() throws Fault {
    Date date = Calendar.getInstance().getTime();
    String sDate = String.valueOf(date.getTime());
    Annotation[] annotations = AnnotatedClass.class.getAnnotations();
    int expected = DateReaderWriter.ANNOTATION_CONSUMES | DateReaderWriter.ANNOTATION_PROVIDER;
    AtomicInteger ai = new AtomicInteger();
    DateReaderWriter drw = new DateReaderWriter(ai);
    addProvider(drw);
    Response response = invokeGet("date?date=" + sDate);
    response.bufferEntity();
    Date entity = response.readEntity(Date.class, annotations);
    assertTrue(date.equals(entity), "#readEntity(Date, annotations)={" + entity + "} differs from expected" + date);
    assertTrue(ai.get() == expected, ai.get() + "differes from expected" + expected + "which suggest a problem with annotation passing");
    String responseDate = response.readEntity(String.class, annotations);
    assertTrue(sDate.equals(responseDate), "#readEntity(String.class, annotations)={" + responseDate + "} differs from expected" + sDate);
    assertTrue(ai.get() == expected, ai.get() + "differes from expected" + expected + "which suggest a problem with annotation passing");
    logMsg("Got expected date", date);
}
Also used : Response(jakarta.ws.rs.core.Response) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Date(java.util.Date) Annotation(java.lang.annotation.Annotation) 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