Search in sources :

Example 61 with ResponseBuilder

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

the class Resource method getMediaType.

@POST
@Path("getmediatype")
public Response getMediaType(String media) throws URISyntaxException {
    ResponseBuilder builder = createResponseWithHeader();
    if (media != null && media.length() != 0)
        builder = builder.type(media);
    Response response = builder.build();
    return response;
}
Also used : Response(jakarta.ws.rs.core.Response) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST)

Example 62 with ResponseBuilder

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

the class Resource method getStatus.

@POST
@Path("getstatus")
public Response getStatus(String entity) {
    int status = Integer.parseInt(entity);
    ResponseBuilder builder = createResponseWithHeader();
    Response response = builder.status(status).build();
    return response;
}
Also used : Response(jakarta.ws.rs.core.Response) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST)

Example 63 with ResponseBuilder

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

the class Resource method setOriginalRuntime.

// We need to switch back to the original runtime delegate since
// we cannot be sure what happen when the war with our runtimedelegate gets
// undeployed
@Path("setoriginalruntime")
@GET
public Response setOriginalRuntime() {
    ResponseBuilder builder = createResponseWithHeader();
    RuntimeDelegate stringBeanDelegate = RuntimeDelegate.getInstance();
    if (stringBeanDelegate instanceof StringBeanRuntimeDelegate) {
        RuntimeDelegate original = ((StringBeanRuntimeDelegate) stringBeanDelegate).getOriginal();
        RuntimeDelegate.setInstance(original);
    } else
        builder = builder.status(Status.NO_CONTENT);
    return builder.build();
}
Also used : StringBeanRuntimeDelegate(ee.jakarta.tck.ws.rs.common.provider.StringBeanRuntimeDelegate) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) RuntimeDelegate(jakarta.ws.rs.ext.RuntimeDelegate) StringBeanRuntimeDelegate(ee.jakarta.tck.ws.rs.common.provider.StringBeanRuntimeDelegate) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

Example 64 with ResponseBuilder

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

the class Resource method buildResponse.

private Response buildResponse(Object content, MediaType type) {
    List<String> list = headers.getRequestHeader(HEADERNAME);
    String name = null;
    if (list != null && list.size() != 0)
        name = list.iterator().next();
    ResponseBuilder builder = Response.ok(content, type).type(type);
    if (name != null)
        builder.header(HEADERNAME, name + DIRECTION);
    return builder.build();
}
Also used : ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder)

Example 65 with ResponseBuilder

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

the class ReturnTypeTest method entityResponseTest.

@GET
@Path("entitybodyresponsetest")
public Response entityResponseTest() {
    RuntimeDelegate rd = RuntimeDelegate.getInstance();
    ResponseBuilder rb = rd.createResponseBuilder();
    ReadableWritableEntity rwe = entityTest();
    return rb.entity(rwe).build();
}
Also used : ReadableWritableEntity(ee.jakarta.tck.ws.rs.ee.rs.ext.messagebodyreaderwriter.ReadableWritableEntity) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) RuntimeDelegate(jakarta.ws.rs.ext.RuntimeDelegate) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

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