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 GETHEADERS:
for (int i = 0; i != 5; i++) builder = builder.header(TemplateInterceptorBody.PROPERTY + i, "any");
break;
case PROCEEDTHROWSWEBAPPEXCEPTION:
builder.entity(new OnWriteExceptionThrowingStringBean(TemplateInterceptorBody.ENTITY));
break;
default:
break;
}
Response response = builder.build();
return response;
}
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);
return builder.build();
}
use of jakarta.ws.rs.core.Response.ResponseBuilder in project jaxrs-api by eclipse-ee4j.
the class BuilderClientIT method expiresTest.
/*
* @testName: expiresTest
*
* @assertion_ids: JAXRS:JAVADOC:147;
*
* @test_Strategy: Set Expires to ResponseBuilder, build a response and check
* expires timestamp.
*/
@Test
public void expiresTest() throws Fault {
Date now = Calendar.getInstance().getTime();
ResponseBuilder rs = Response.ok();
rs.expires(now);
Response response = rs.build();
MultivaluedMap<String, Object> metadata = response.getMetadata();
if (metadata == null)
fail("No metadata in response");
List<Object> expires = response.getMetadata().get("Expires");
if (expires == null || expires.isEmpty())
fail("No Expires property in metadata");
boolean condition = false;
Object fetched = expires.iterator().next();
if (Date.class.isInstance(fetched))
condition = ((Date) fetched).compareTo(now) == 0;
else if (String.class.isInstance(fetched))
condition = formats(now).contains(fetched.toString());
else
fail("Fetched object not recognised");
assertTrue(condition, "Expires value not matched, set: " + now.toString() + "fetched:" + fetched.toString());
logMsg("Set and fetched expire dates matched");
}
use of jakarta.ws.rs.core.Response.ResponseBuilder in project jaxrs-api by eclipse-ee4j.
the class BuilderClientIT method allowStringSetTest.
/*
* @testName: allowStringSetTest
*
* @assertion_ids: JAXRS:JAVADOC:876;
*
* @test_Strategy: Set the list of allowed methods for the resource.
*/
@Test
public void allowStringSetTest() throws Fault {
Set<String> methods = new TreeSet<String>();
methods.add(Request.OPTIONS.name());
methods.add(Request.TRACE.name());
ResponseBuilder rb = RuntimeDelegate.getInstance().createResponseBuilder();
Response response = rb.allow(methods).build();
Set<String> set = response.getAllowedMethods();
String responseMethods = JaxrsUtil.iterableToString(" ", set);
for (String method : methods) {
assertContains(responseMethods, method, "Expected allow method", method, "was not found in response allowed methods", responseMethods);
logMsg("Found expected allowed method", method);
}
}
use of jakarta.ws.rs.core.Response.ResponseBuilder in project jaxrs-api by eclipse-ee4j.
the class Resource method getLastModified.
@POST
@Path("getlastmodified")
public Response getLastModified(String last) {
ResponseBuilder builder = createResponseWithHeader();
if (last != null && last.length() != 0) {
long lastMilist = Long.parseLong(last);
Date date = new Date(lastMilist);
builder = builder.lastModified(date);
}
Response response = builder.build();
return response;
}
Aggregations