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();
}
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;
}
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()));
}
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);
}
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());
}
Aggregations