Search in sources :

Example 36 with ResponseBuilder

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

the class Resource method getEntityType.

@POST
@Path("getentitytype")
public Response getEntityType(String type) {
    ResponseBuilder builder = createResponseWithHeader();
    Object entity = null;
    String content = "ENTity";
    if ("string".equals(type))
        entity = content;
    else if ("bytearray".equals(type))
        entity = content.getBytes();
    else if ("inputstream".equals(type))
        entity = new ByteArrayInputStream(content.getBytes());
    builder = builder.entity(entity);
    Response response = builder.build();
    return response;
}
Also used : Response(jakarta.ws.rs.core.Response) ByteArrayInputStream(java.io.ByteArrayInputStream) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST)

Example 37 with ResponseBuilder

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

the class Resource method getAllowedMethods.

@Path("getallowedmethods")
@GET
public Response getAllowedMethods() {
    ResponseBuilder builder = createResponseWithHeader();
    Response response = builder.allow("OPTIONS", "TRACE").build();
    return response;
}
Also used : Response(jakarta.ws.rs.core.Response) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

Example 38 with ResponseBuilder

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

the class Resource method getEntityAnnotations.

@POST
@Path("getentityannotations")
public Response getEntityAnnotations(String setEntity) {
    Annotation[] annotations = ResponseFilter.class.getAnnotations();
    ResponseBuilder builder = createResponseWithHeader();
    if (Boolean.parseBoolean(setEntity))
        builder = builder.entity("entity", annotations);
    Response response = builder.build();
    return response;
}
Also used : Response(jakarta.ws.rs.core.Response) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Annotation(java.lang.annotation.Annotation) StringBeanWithAnnotation(ee.jakarta.tck.ws.rs.common.provider.StringBeanWithAnnotation) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST)

Example 39 with ResponseBuilder

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

the class Resource method getEntityClass.

@POST
@Path("getentityclass")
public Response getEntityClass(String clazz) {
    String content = "ENTity";
    ResponseBuilder builder = createResponseWithHeader();
    Object entity = null;
    if ("string".equals(clazz))
        entity = content;
    else if ("bytearray".equals(clazz))
        entity = content.getBytes();
    else if ("inputstream".equals(clazz))
        entity = new ByteArrayInputStream(content.getBytes());
    builder = builder.entity(entity);
    Response response = builder.build();
    return response;
}
Also used : Response(jakarta.ws.rs.core.Response) ByteArrayInputStream(java.io.ByteArrayInputStream) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST)

Example 40 with ResponseBuilder

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

the class Resource method set.

@POST
@Path("Set")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response set(String content) {
    ResponseBuilder rb = Response.ok();
    if (content != null) {
        String[] cookies1 = content.split(";");
        for (String cookie : cookies1) {
            // name=0, value=1
            String[] nameVal = cookie.split("=");
            rb.cookie(new NewCookie(nameVal[0], nameVal[1]));
        }
    }
    return rb.build();
}
Also used : ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) NewCookie(jakarta.ws.rs.core.NewCookie) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST) Produces(jakarta.ws.rs.Produces) Consumes(jakarta.ws.rs.Consumes)

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