Search in sources :

Example 21 with ResponseBuilder

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

the class JAXRSClientIT method getHeadersHeadersSetTest.

/*
   * @testName: getHeadersHeadersSetTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:923; JAXRS:JAVADOC:920; JAXRS:SPEC:85;
   * 
   * @test_Strategy: Get mutable map of HTTP headers.
   * 
   * ReaderInterceptor.aroundReadFrom If abortWith is invoked, execution is
   * aborted
   */
@Test
public void getHeadersHeadersSetTest() throws Fault {
    ResponseBuilder builder = createResponse(ContextOperation.GETHEADERS);
    for (int i = 0; i != 5; i++) {
        setProperty(Property.UNORDERED_SEARCH_STRING, TemplateInterceptorBody.PROPERTY + i);
        builder = builder.header(TemplateInterceptorBody.PROPERTY + i, "any");
    }
    Response fake = builder.build();
    addProviders(fake);
    setTextCaser(TextCaser.LOWER);
    setProperty(Property.UNORDERED_SEARCH_STRING, TemplateInterceptorBody.OPERATION);
    invoke();
}
Also used : Response(jakarta.ws.rs.core.Response) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Test(org.junit.jupiter.api.Test)

Example 22 with ResponseBuilder

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

the class JAXRSClientIT method proceedThrowsWebApplicationExceptionTest.

/*
   * @testName: proceedThrowsWebApplicationExceptionTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:925; JAXRS:JAVADOC:1008; JAXRS:JAVADOC:920;
   * JAXRS:SPEC:85;
   * 
   * @test_Strategy: Throws: WebApplicationException - thrown by the wrapped
   * {@code MessageBodyReader.readFrom} method.
   * 
   * Proceed is tested in any of the intercepter tests.
   * 
   * ReaderInterceptor.aroundReadFrom If abortWith is invoked, execution is
   * aborted
   */
@Test
public void proceedThrowsWebApplicationExceptionTest() throws Fault {
    ResponseBuilder builder = createResponse(ContextOperation.PROCEEDTHROWSWEBAPPEXCEPTION);
    Response fake = builder.build();
    addProviders(fake);
    addProvider(ExceptionThrowingStringBeanEntityProvider.class);
    invoke();
    // Exception thrown, caught in InterceptorBodyOne
    StringBean bean = getResponseBody(ExceptionThrowingStringBean.class);
    // 
    assertContains(bean.get(), TemplateInterceptorBody.WAE, "WebApplicationException has not been thrown and the message is", bean.get());
    logMsg("WebApplicationException has been thrown as expected", bean.get());
}
Also used : Response(jakarta.ws.rs.core.Response) StringBean(ee.jakarta.tck.ws.rs.common.provider.StringBean) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Test(org.junit.jupiter.api.Test)

Example 23 with ResponseBuilder

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

the class Resource method genericResponse.

@GET
@Path("{id}")
public Response genericResponse(@PathParam("id") String path) {
    ContextOperation op = ContextOperation.valueOf(path.toUpperCase());
    ResponseBuilder builder = createResponseBuilderWithHeader(op);
    switch(op) {
        case GETANNOTATIONS:
            Annotation[] annotations = ContextOperation.class.getAnnotations();
            builder = builder.entity(TemplateInterceptorBody.ENTITY, annotations);
            break;
        case GETMEDIATYPE:
            builder = builder.type(MediaType.APPLICATION_JSON_TYPE);
            break;
        case SETTYPE:
            ByteArrayInputStream bais = new ByteArrayInputStream(TemplateInterceptorBody.ENTITY.getBytes());
            Reader reader = new InputStreamReader(bais);
            builder = builder.entity(reader);
            break;
        default:
            break;
    }
    Response response = builder.build();
    return response;
}
Also used : Response(jakarta.ws.rs.core.Response) ContextOperation(ee.jakarta.tck.ws.rs.api.rs.ext.interceptor.ContextOperation) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Annotation(java.lang.annotation.Annotation) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

Example 24 with ResponseBuilder

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

the class Resource method createResponseBuilderWithHeader.

// ///////////////////////////////////////////////////////////////////////
ResponseBuilder createResponseBuilderWithHeader(ContextOperation op) {
    Response.ResponseBuilder builder = Response.ok();
    // set a header with ContextOperation so that the filter knows what to
    // do
    builder = builder.header(TemplateInterceptorBody.OPERATION, op.name());
    builder = builder.entity(TemplateInterceptorBody.ENTITY);
    return builder;
}
Also used : Response(jakarta.ws.rs.core.Response) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder)

Example 25 with ResponseBuilder

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

the class Resource method createResponseBuilderWithHeader.

// ///////////////////////////////////////////////////////////////////////
static ResponseBuilder createResponseBuilderWithHeader(ContextOperation op) {
    Response.ResponseBuilder builder = Response.ok();
    // set a header with ContextOperation so that the filter knows what to
    // do
    builder = builder.header(TemplateInterceptorBody.OPERATION, op.name());
    builder = builder.entity(TemplateInterceptorBody.ENTITY);
    return builder;
}
Also used : Response(jakarta.ws.rs.core.Response) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder)

Aggregations

ResponseBuilder (jakarta.ws.rs.core.Response.ResponseBuilder)80 Response (jakarta.ws.rs.core.Response)69 Path (jakarta.ws.rs.Path)41 Test (org.junit.jupiter.api.Test)34 POST (jakarta.ws.rs.POST)27 GET (jakarta.ws.rs.GET)14 Date (java.util.Date)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Annotation (java.lang.annotation.Annotation)4 VerificationResult (ee.jakarta.tck.ws.rs.api.rs.core.responseclient.VerificationResult)3 StringBean (ee.jakarta.tck.ws.rs.common.provider.StringBean)3 NewCookie (jakarta.ws.rs.core.NewCookie)3 RuntimeDelegate (jakarta.ws.rs.ext.RuntimeDelegate)3 IOException (java.io.IOException)3 StringBeanWithAnnotation (ee.jakarta.tck.ws.rs.common.provider.StringBeanWithAnnotation)2 Produces (jakarta.ws.rs.Produces)2 WebApplicationException (jakarta.ws.rs.WebApplicationException)2 EntityTag (jakarta.ws.rs.core.EntityTag)2 Link (jakarta.ws.rs.core.Link)2 InputStreamReader (java.io.InputStreamReader)2