Search in sources :

Example 21 with EntityTag

use of javax.ws.rs.core.EntityTag in project cxf by apache.

the class ResponseBuilderImplTest method testEntityTag2.

@Test
public void testEntityTag2() {
    Response r = Response.ok().tag(new EntityTag("\"foo\"")).build();
    String eTag = r.getMetadata().getFirst("ETag").toString();
    assertEquals("\"foo\"", eTag);
}
Also used : Response(javax.ws.rs.core.Response) EntityTag(javax.ws.rs.core.EntityTag) Test(org.junit.Test)

Example 22 with EntityTag

use of javax.ws.rs.core.EntityTag in project cxf by apache.

the class ResponseBuilderImplTest method testEntityTag.

@Test
public void testEntityTag() {
    Response r = Response.ok().tag(new EntityTag("foo")).build();
    String eTag = r.getMetadata().getFirst("ETag").toString();
    assertEquals("\"foo\"", eTag);
}
Also used : Response(javax.ws.rs.core.Response) EntityTag(javax.ws.rs.core.EntityTag) Test(org.junit.Test)

Example 23 with EntityTag

use of javax.ws.rs.core.EntityTag in project cxf by apache.

the class BookStore method getBookAsResponse2.

@GET
@Path("/books/response2/{bookId}/")
@Produces("application/xml")
public Response getBookAsResponse2(@PathParam("bookId") String id) throws BookNotFoundFault {
    Book entity = doGetBook(id);
    EntityTag etag = new EntityTag(Integer.toString(entity.hashCode()));
    CacheControl cacheControl = new CacheControl();
    cacheControl.setMaxAge(1);
    cacheControl.setPrivate(true);
    return Response.ok().tag(etag).entity(entity).cacheControl(cacheControl).build();
}
Also used : EntityTag(javax.ws.rs.core.EntityTag) CacheControl(javax.ws.rs.core.CacheControl) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 24 with EntityTag

use of javax.ws.rs.core.EntityTag in project iaf by ibissource.

the class ShowMonitors method getTriggers.

@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/{monitorName}/triggers/{triggerId}")
@Produces(MediaType.APPLICATION_JSON)
public Response getTriggers(@PathParam("configuration") String configName, @PathParam("monitorName") String monitorName, @PathParam("triggerId") Integer id) throws ApiException {
    MonitorManager mm = getMonitorManager(configName);
    Monitor monitor = mm.findMonitor(monitorName);
    if (monitor == null) {
        throw new ApiException("Monitor not found!", Status.NOT_FOUND);
    }
    Map<String, Object> returnMap = new HashMap<>();
    if (id != null) {
        ITrigger trigger = monitor.getTrigger(id);
        if (trigger == null) {
            throw new ApiException("Trigger not found!", Status.NOT_FOUND);
        } else {
            returnMap.put("trigger", mapTrigger(trigger));
        }
    }
    returnMap.put("severities", EnumUtils.getEnumList(SeverityEnum.class));
    returnMap.put("events", mm.getEvents());
    EntityTag etag = new EntityTag(returnMap.hashCode() + "");
    Response.ResponseBuilder response = null;
    // Verify if it matched with etag available in http request
    response = request.evaluatePreconditions(etag);
    // If ETag matches the response will be non-null;
    if (response != null) {
        return response.tag(etag).build();
    }
    return Response.status(Status.OK).entity(returnMap).tag(etag).build();
}
Also used : Response(javax.ws.rs.core.Response) MonitorManager(nl.nn.adapterframework.monitoring.MonitorManager) Monitor(nl.nn.adapterframework.monitoring.Monitor) SeverityEnum(nl.nn.adapterframework.monitoring.SeverityEnum) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) EntityTag(javax.ws.rs.core.EntityTag) ITrigger(nl.nn.adapterframework.monitoring.ITrigger) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 25 with EntityTag

use of javax.ws.rs.core.EntityTag in project iaf by ibissource.

the class ShowConfigurationStatus method getAdapters.

@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/adapters")
@Produces(MediaType.APPLICATION_JSON)
public Response getAdapters(@QueryParam("expanded") String expanded, @QueryParam("showPendingMsgCount") boolean showPendingMsgCount) throws ApiException {
    TreeMap<String, Object> adapterList = new TreeMap<String, Object>();
    for (Adapter adapter : getIbisManager().getRegisteredAdapters()) {
        Map<String, Object> adapterInfo = mapAdapter(adapter);
        if (expanded != null && !expanded.isEmpty()) {
            if (expanded.equalsIgnoreCase("all")) {
                adapterInfo.put("receivers", mapAdapterReceivers(adapter, showPendingMsgCount));
                adapterInfo.put("pipes", mapAdapterPipes(adapter));
                adapterInfo.put("messages", mapAdapterMessages(adapter));
            } else if (expanded.equalsIgnoreCase("receivers")) {
                adapterInfo.put("receivers", mapAdapterReceivers(adapter, showPendingMsgCount));
            } else if (expanded.equalsIgnoreCase("pipes")) {
                adapterInfo.put("pipes", mapAdapterPipes(adapter));
            } else if (expanded.equalsIgnoreCase("messages")) {
                adapterInfo.put("messages", mapAdapterMessages(adapter));
            } else {
                throw new ApiException("Invalid value [" + expanded + "] for parameter expanded supplied!");
            }
        }
        adapterList.put((String) adapterInfo.get("name"), adapterInfo);
    }
    Response.ResponseBuilder response = null;
    // Calculate the ETag on last modified date of user resource
    EntityTag etag = new EntityTag(adapterList.hashCode() + "");
    // Verify if it matched with etag available in http request
    response = request.evaluatePreconditions(etag);
    // If ETag matches the response will be non-null;
    if (response != null) {
        return response.tag(etag).build();
    }
    response = Response.status(Response.Status.OK).entity(adapterList).tag(etag);
    return response.build();
}
Also used : Response(javax.ws.rs.core.Response) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Adapter(nl.nn.adapterframework.core.Adapter) EntityTag(javax.ws.rs.core.EntityTag) TreeMap(java.util.TreeMap) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

EntityTag (javax.ws.rs.core.EntityTag)77 Response (javax.ws.rs.core.Response)28 GET (javax.ws.rs.GET)27 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)25 Path (javax.ws.rs.Path)24 CacheControl (javax.ws.rs.core.CacheControl)20 Test (org.junit.Test)18 Produces (javax.ws.rs.Produces)16 Date (java.util.Date)10 Test (org.testng.annotations.Test)9 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)8 Timestamp (com.yahoo.rdl.Timestamp)5 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)5 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 List (java.util.List)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 ContainerResponse (org.everrest.core.impl.ContainerResponse)5 Principal (com.yahoo.athenz.auth.Principal)4