Search in sources :

Example 56 with EntityTag

use of javax.ws.rs.core.EntityTag in project exhibitor by soabase.

the class ConfigResource method getSystemState.

@Path("get-state")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getSystemState(@Context Request request) throws Exception {
    InstanceConfig config = context.getExhibitor().getConfigManager().getConfig();
    String response = new FourLetterWord(FourLetterWord.Word.RUOK, config, context.getExhibitor().getConnectionTimeOutMs()).getResponse();
    ServerList serverList = new ServerList(config.getString(StringConfigs.SERVERS_SPEC));
    ServerSpec us = UsState.findUs(context.getExhibitor(), serverList.getSpecs());
    ObjectNode mainNode = JsonNodeFactory.instance.objectNode();
    ObjectNode configNode = JsonNodeFactory.instance.objectNode();
    ObjectNode controlPanelNode = JsonNodeFactory.instance.objectNode();
    mainNode.put("version", context.getExhibitor().getVersion());
    mainNode.put("running", "imok".equals(response));
    mainNode.put("backupActive", context.getExhibitor().getBackupManager().isActive());
    mainNode.put("standaloneMode", context.getExhibitor().getConfigManager().isStandaloneMode());
    mainNode.put("extraHeadingText", context.getExhibitor().getExtraHeadingText());
    mainNode.put("nodeMutationsAllowed", context.getExhibitor().nodeMutationsAllowed());
    configNode.put("rollInProgress", context.getExhibitor().getConfigManager().isRolling());
    configNode.put("rollStatus", context.getExhibitor().getConfigManager().getRollingConfigState().getRollingStatus());
    configNode.put("rollPercentDone", context.getExhibitor().getConfigManager().getRollingConfigState().getRollingPercentDone());
    configNode.put("hostname", context.getExhibitor().getThisJVMHostname());
    configNode.put("serverId", (us != null) ? us.getServerId() : -1);
    for (StringConfigs c : StringConfigs.values()) {
        configNode.put(fixName(c), config.getString(c));
    }
    for (IntConfigs c : IntConfigs.values()) {
        String fixedName = fixName(c);
        int value = config.getInt(c);
        configNode.put(fixedName, value);
    }
    EncodedConfigParser zooCfgParser = new EncodedConfigParser(config.getString(StringConfigs.ZOO_CFG_EXTRA));
    ObjectNode zooCfgNode = JsonNodeFactory.instance.objectNode();
    for (EncodedConfigParser.FieldValue fv : zooCfgParser.getFieldValues()) {
        zooCfgNode.put(fv.getField(), fv.getValue());
    }
    configNode.put("zooCfgExtra", zooCfgNode);
    if (context.getExhibitor().getBackupManager().isActive()) {
        ObjectNode backupExtraNode = JsonNodeFactory.instance.objectNode();
        EncodedConfigParser parser = context.getExhibitor().getBackupManager().getBackupConfigParser();
        List<BackupConfigSpec> configs = context.getExhibitor().getBackupManager().getConfigSpecs();
        for (BackupConfigSpec c : configs) {
            String value = parser.getValue(c.getKey());
            backupExtraNode.put(c.getKey(), (value != null) ? value : "");
        }
        configNode.put("backupExtra", backupExtraNode);
    }
    configNode.put("controlPanel", controlPanelNode);
    mainNode.put("config", configNode);
    String json = JsonUtil.writeValueAsString(mainNode);
    EntityTag tag = new EntityTag(Hashing.sha1().hashString(json, Charsets.UTF_8).toString());
    Response.ResponseBuilder builder = request.evaluatePreconditions(tag);
    if (builder == null) {
        builder = Response.ok(json).tag(tag);
    }
    return builder.build();
}
Also used : ServerSpec(com.netflix.exhibitor.core.state.ServerSpec) ObjectNode(org.codehaus.jackson.node.ObjectNode) IntConfigs(com.netflix.exhibitor.core.config.IntConfigs) Response(javax.ws.rs.core.Response) InstanceConfig(com.netflix.exhibitor.core.config.InstanceConfig) EncodedConfigParser(com.netflix.exhibitor.core.config.EncodedConfigParser) FourLetterWord(com.netflix.exhibitor.core.state.FourLetterWord) BackupConfigSpec(com.netflix.exhibitor.core.backup.BackupConfigSpec) ServerList(com.netflix.exhibitor.core.state.ServerList) EntityTag(javax.ws.rs.core.EntityTag) StringConfigs(com.netflix.exhibitor.core.config.StringConfigs) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 57 with EntityTag

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

the class RequestImpl method evaluateIfNonMatch.

private ResponseBuilder evaluateIfNonMatch(EntityTag eTag, Date lastModified) {
    List<String> ifNonMatch = headers.getRequestHeader(HttpHeaders.IF_NONE_MATCH);
    if (ifNonMatch == null || ifNonMatch.isEmpty()) {
        return lastModified == null ? null : evaluateIfModifiedSince(lastModified);
    }
    String method = getMethod();
    boolean getOrHead = HttpMethod.GET.equals(method) || HttpMethod.HEAD.equals(method);
    try {
        for (String value : ifNonMatch) {
            boolean result = "*".equals(value);
            if (!result) {
                EntityTag requestTag = EntityTag.valueOf(value);
                result = getOrHead ? requestTag.equals(eTag) : !requestTag.isWeak() && !eTag.isWeak() && requestTag.equals(eTag);
            }
            if (result) {
                Response.Status status = getOrHead ? Response.Status.NOT_MODIFIED : Response.Status.PRECONDITION_FAILED;
                return Response.status(status).tag(eTag);
            }
        }
    } catch (IllegalArgumentException ex) {
    // ignore
    }
    return null;
}
Also used : Response(javax.ws.rs.core.Response) EntityTag(javax.ws.rs.core.EntityTag)

Example 58 with EntityTag

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

the class EntityTagHeaderProviderTest method testFromString.

@Test
public void testFromString() {
    EntityTag tag = EntityTag.valueOf("\"\"");
    assertFalse(tag.isWeak() && "".equals(tag.getValue()));
    tag = EntityTag.valueOf("W/");
    assertTrue(tag.isWeak() && "".equals(tag.getValue()));
    tag = EntityTag.valueOf("W/\"12345\"");
    assertTrue(tag.isWeak() && "12345".equals(tag.getValue()));
    tag = EntityTag.valueOf("\"12345\"");
    assertTrue(!tag.isWeak() && "12345".equals(tag.getValue()));
    tag = EntityTag.valueOf("\"wyoBLW/ye71RgN/0LNyj4eA5rfE1ovtlM03aakuGr2Y=\"");
    assertTrue(!tag.isWeak() && "wyoBLW/ye71RgN/0LNyj4eA5rfE1ovtlM03aakuGr2Y=".equals(tag.getValue()));
}
Also used : EntityTag(javax.ws.rs.core.EntityTag) Test(org.junit.Test)

Example 59 with EntityTag

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

the class RequestImplTest method testIfNoneMatchAndDateWithMatchingTags.

@Test
public void testIfNoneMatchAndDateWithMatchingTags() throws Exception {
    metadata.putSingle(HttpHeaders.IF_NONE_MATCH, "\"123\"");
    metadata.putSingle("If-Modified-Since", "Tue, 21 Oct 2008 14:00:00 GMT");
    Date lastModified = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH).parse("Mon, 22 Oct 2008 14:00:00 GMT");
    ResponseBuilder rb = new RequestImpl(m).evaluatePreconditions(lastModified, new EntityTag("\"123\""));
    assertNull("Precondition is not met", rb);
}
Also used : EntityTag(javax.ws.rs.core.EntityTag) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 60 with EntityTag

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

the class RequestImplTest method testWeakEtags.

@Test
public void testWeakEtags() {
    metadata.putSingle("If-Match", new EntityTag("123", true).toString());
    ResponseBuilder rb = new RequestImpl(m).evaluatePreconditions(new EntityTag("123"));
    assertNotNull("Strict compararison is required", rb);
    Response r = rb.build();
    assertEquals("If-Match precondition was not met", 412, r.getStatus());
    assertEquals("Response should include ETag", "\"123\"", r.getMetadata().getFirst("ETag").toString());
}
Also used : Response(javax.ws.rs.core.Response) EntityTag(javax.ws.rs.core.EntityTag) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Test(org.junit.Test)

Aggregations

EntityTag (javax.ws.rs.core.EntityTag)73 GET (javax.ws.rs.GET)24 Response (javax.ws.rs.core.Response)24 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)23 Path (javax.ws.rs.Path)21 CacheControl (javax.ws.rs.core.CacheControl)20 Test (org.junit.Test)18 Produces (javax.ws.rs.Produces)13 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 List (java.util.List)5 ContainerResponse (org.everrest.core.impl.ContainerResponse)5 Principal (com.yahoo.athenz.auth.Principal)4 EnvironmentUser (fi.otavanopisto.muikku.model.users.EnvironmentUser)4 ArrayList (java.util.ArrayList)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4