List of usage examples for com.fasterxml.jackson.core Base64Variants getDefaultVariant
public static Base64Variant getDefaultVariant()
From source file:com.googlecode.jmxtrans.model.output.LibratoWriterFactory.java
public LibratoWriterFactory(@JsonProperty("typeNames") ImmutableList<String> typeNames, @JsonProperty("booleanAsNumber") boolean booleanAsNumber, @JsonProperty("url") URL url, @JsonProperty("libratoApiTimeoutInMillis") Integer readTimeoutInMillis, @JsonProperty("username") String username, @JsonProperty("token") String token, @JsonProperty("proxyHost") String proxyHost, @JsonProperty("proxyPort") Integer proxyPort) { this.booleanAsNumber = booleanAsNumber; this.typeNames = firstNonNull(typeNames, ImmutableList.<String>of()); this.url = checkNotNull(url); this.readTimeoutInMillis = firstNonNull(readTimeoutInMillis, 1000); this.authorization = "Basic" + Base64Variants.getDefaultVariant() .encode((checkNotNull(username) + ":" + checkNotNull(token)).getBytes(US_ASCII)); proxy = initProxy(proxyHost, proxyPort); }
From source file:org.jmxtrans.embedded.output.LibratoWriter.java
/** * Load settings//from w ww .j a va2s.co m */ @Override public void start() { try { url = new URL(getStringSetting(SETTING_URL, DEFAULT_LIBRATO_API_URL)); user = getStringSetting(SETTING_USERNAME); token = getStringSetting(SETTING_TOKEN); basicAuthentication = Base64Variants.getDefaultVariant() .encode((user + ":" + token).getBytes(Charset.forName("US-ASCII"))); if (getStringSetting(SETTING_PROXY_HOST, null) != null && !getStringSetting(SETTING_PROXY_HOST).isEmpty()) { proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(getStringSetting(SETTING_PROXY_HOST), getIntSetting(SETTING_PROXY_PORT))); } libratoApiTimeoutInMillis = getIntSetting(SETTING_LIBRATO_API_TIMEOUT_IN_MILLIS, DEFAULT_LIBRATO_API_TIMEOUT_IN_MILLIS); source = getStringSetting(SETTING_SOURCE, DEFAULT_SOURCE); source = getStrategy().resolveExpression(source); logger.info("Start Librato writer connected to '{}', proxy {} with user '{}' ...", url, proxy, user); } catch (MalformedURLException e) { throw new EmbeddedJmxTransException(e); } }
From source file:com.googlecode.jmxtrans.model.output.LibratoWriter.java
@JsonCreator public LibratoWriter(@JsonProperty("typeNames") ImmutableList<String> typeNames, @JsonProperty("booleanAsNumber") boolean booleanAsNumber, @JsonProperty("debug") Boolean debugEnabled, @JsonProperty("url") URL url, @JsonProperty("libratoApiTimeoutInMillis") Integer libratoApiTimeoutInMillis, @JsonProperty("username") String username, @JsonProperty("token") String token, @JsonProperty("proxyHost") String proxyHost, @JsonProperty("proxyPort") Integer proxyPort, @JsonProperty("settings") Map<String, Object> settings) throws MalformedURLException { super(typeNames, booleanAsNumber, debugEnabled, settings); logger.warn("LibratoWriter is deprecated. Please use LibratoWriterFactory instead."); this.url = MoreObjects.firstNonNull(url, new URL( MoreObjects.firstNonNull((String) this.getSettings().get(SETTING_URL), DEFAULT_LIBRATO_API_URL))); this.libratoApiTimeoutInMillis = MoreObjects.firstNonNull(libratoApiTimeoutInMillis, Settings.getIntSetting(getSettings(), SETTING_LIBRATO_API_TIMEOUT_IN_MILLIS, 1000)); this.username = MoreObjects.firstNonNull(username, (String) getSettings().get(SETTING_USERNAME)); this.token = MoreObjects.firstNonNull(token, (String) getSettings().get(SETTING_TOKEN)); this.basicAuthentication = Base64Variants.getDefaultVariant() .encode((this.username + ":" + this.token).getBytes(Charsets.US_ASCII)); this.proxyHost = proxyHost != null ? proxyHost : (String) getSettings().get(SETTING_PROXY_HOST); this.proxyPort = proxyPort != null ? proxyPort : Settings.getIntegerSetting(getSettings(), SETTING_PROXY_PORT, null); if (this.proxyHost != null && this.proxyPort != null) { this.proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(this.proxyHost, this.proxyPort)); } else {//w w w .ja va 2 s . co m this.proxy = null; } this.httpUserAgent = "jmxtrans-standalone/1 " + "(" + System.getProperty("java.vm.name") + "/" + System.getProperty("java.version") + "; " + System.getProperty("os.name") + "-" + System.getProperty("os.arch") + "/" + System.getProperty("os.version") + ")"; }
From source file:org.jmxtrans.embedded.output.CopperEggWriter.java
/** * Load settings/*w w w.j av a 2 s. c o m*/ */ @Override public void start() { config_location = DEFAULT_COPPEREGG_CONFIGURATION_PATH; String path = config_location.substring("classpath:".length()); long thisPID = getPID(); if (myPID == thisPID) { logger.info("Started from two threads with the same PID, {}", thisPID); return; } myPID = thisPID; try { String str = String.valueOf(myPID); url_str = getStringSetting(SETTING_URL, DEFAULT_COPPEREGG_API_URL); url = new URL(url_str); user = getStringSetting(SETTING_USERNAME); token = getStringSetting(SETTING_TOKEN); user = token; basicAuthentication = Base64Variants.getDefaultVariant() .encode((user + ":" + "U").getBytes(Charset.forName("US-ASCII"))); if (getStringSetting(SETTING_PROXY_HOST, null) != null && !getStringSetting(SETTING_PROXY_HOST).isEmpty()) { proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(getStringSetting(SETTING_PROXY_HOST), getIntSetting(SETTING_PROXY_PORT))); } coppereggApiTimeoutInMillis = getIntSetting(SETTING_COPPEREGG_API_TIMEOUT_IN_MILLIS, DEFAULT_COPPEREGG_API_TIMEOUT_IN_MILLIS); source = getStringSetting(SETTING_SOURCE, DEFAULT_SOURCE); source = getStrategy().resolveExpression(source); myhost = source; myPID_host = myhost + '.' + str; try { InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(path); if (in == null) { logger.warn("No file found for classpath:" + config_location); } else { read_config(in); } } catch (Exception e) { exceptionCounter.incrementAndGet(); logger.warn("Exception in start " + e); } ensure_metric_groups(); ensure_dashboards(); logger.info("jvm_os_groupID : {}", jvm_os_groupID); logger.info("jvm_gc_groupID : {}", jvm_gc_groupID); logger.info("jvm_runtime_groupID : {}", jvm_runtime_groupID); logger.info("jvm_class_groupID : {}", jvm_class_groupID); logger.info("jvm_thread_groupID : {}", jvm_thread_groupID); logger.info("heap_metric_groupID : {}", heap_metric_groupID); logger.info("nonheap_metric_groupID : {}", nonheap_metric_groupID); logger.info("tomcat_thread_pool_groupID : {}", tomcat_thread_pool_groupID); logger.info("tomcat_grp_groupID : {}", tomcat_grp_groupID); logger.info("tomcat_servlet_groupID : {}", tomcat_servlet_groupID); logger.info("tomcat_manager_groupID : {}", tomcat_manager_groupID); logger.info("tomcat_db_groupID : {}", tomcat_db_groupID); logger.info("jmxtrans_metric_groupID : {}", jmxtrans_metric_groupID); logger.info("app_groupID : {}", app_groupID); logger.info("app_sales_groupID : {}", app_sales_groupID); logger.info("Started CopperEggWriter Successfully on jvm '{}', connected to '{}', proxy {}", myPID_host, url, proxy); } catch (MalformedURLException e) { exceptionCounter.incrementAndGet(); throw new EmbeddedJmxTransException(e); } }
From source file:com.unboundid.scim2.common.PatchOpTestCase.java
/** * test binary methods.//from w w w .ja v a 2 s .co m * @throws Exception error */ @Test public void testBinaryPatchOps() throws Exception { byte[] ba1 = new byte[] { 0x00, 0x01, 0x02 }; byte[] ba2 = new byte[] { 0x02, 0x01, 0x00 }; PatchOperation patchOp = PatchOperation.addBinaryValues("path1", Lists.newArrayList(ba1, ba2)); Assert.assertEquals(patchOp.getOpType(), PatchOpType.ADD); JsonNode jsonNode = patchOp.getJsonNode(); Assert.assertTrue(jsonNode.isArray()); Assert.assertTrue( Arrays.equals(Base64Variants.getDefaultVariant().decode(jsonNode.get(0).textValue()), ba1)); Assert.assertTrue( Arrays.equals(Base64Variants.getDefaultVariant().decode(jsonNode.get(1).textValue()), ba2)); Assert.assertEquals(patchOp.getPath(), Path.fromString("path1")); byte[] ba3 = new byte[] { 0x03, 0x04, 0x05 }; byte[] ba4 = new byte[] { 0x05, 0x04, 0x03 }; patchOp = PatchOperation.addBinaryValues(Path.fromString("path1"), Lists.newArrayList(ba3, ba4)); Assert.assertEquals(patchOp.getOpType(), PatchOpType.ADD); jsonNode = patchOp.getJsonNode(); Assert.assertTrue(jsonNode.isArray()); Assert.assertTrue( Arrays.equals(Base64Variants.getDefaultVariant().decode(jsonNode.get(0).textValue()), ba3)); Assert.assertTrue( Arrays.equals(Base64Variants.getDefaultVariant().decode(jsonNode.get(1).textValue()), ba4)); Assert.assertEquals(patchOp.getPath(), Path.fromString("path1")); byte[] ba5 = new byte[] { 0x06, 0x07, 0x08 }; patchOp = PatchOperation.replace("path1", ba5); Assert.assertEquals(patchOp.getOpType(), PatchOpType.REPLACE); Assert.assertTrue(Arrays.equals(patchOp.getValue(byte[].class), ba5)); Assert.assertEquals(patchOp.getPath(), Path.fromString("path1")); byte[] ba6 = new byte[] { 0x09, 0x0a, 0x0b }; patchOp = PatchOperation.replace(Path.fromString("path1"), ba6); Assert.assertEquals(patchOp.getOpType(), PatchOpType.REPLACE); Assert.assertTrue(Arrays.equals(patchOp.getValue(byte[].class), ba6)); Assert.assertEquals(patchOp.getPath(), Path.fromString("path1")); }
From source file:com.unboundid.scim2.common.messages.PatchOperation.java
/** * Create a new add patch operation./*from w w w . j a v a2 s . c om*/ * * @param path The path targeted by this patch operation. The path * must not be {@code null}. * @param values The values to add. * * @return The new add patch operation. */ public static PatchOperation addBinaryValues(final Path path, final List<byte[]> values) { ArrayNode arrayNode = JsonUtils.getJsonNodeFactory().arrayNode(); for (byte[] value : values) { arrayNode.add(Base64Variants.getDefaultVariant().encode(value)); } return add(path, arrayNode); }
From source file:com.unboundid.scim2.common.messages.PatchOperation.java
/** * Create a new replace patch operation. * * @param path The path targeted by this patch operation. The path * must not be {@code null}. * Path string examples:/* w w w . j a v a2 s .c o m*/ * "{@code userName eq 'bjensen'}" * "{@code userName}" * @param value The value(s) to replace. The value(s) must not be {@code null}. * * @return The new replace patch operation. * @throws ScimException If the path is invalid. */ public static PatchOperation replace(final String path, final byte[] value) throws ScimException { String valueString = Base64Variants.getDefaultVariant().encode(value); return replace(path, valueString); }
From source file:com.unboundid.scim2.common.messages.PatchOperation.java
/** * Create a new replace patch operation. * * @param path The path targeted by this patch operation. The path * must not be {@code null}. * @param value The value(s) to replace. The value(s) must not be {@code null}. * * @return The new replace patch operation. *//*from w w w. j a v a 2s .co m*/ public static PatchOperation replace(final Path path, final byte[] value) { String valueString = Base64Variants.getDefaultVariant().encode(value); return replace(path, valueString); }
From source file:com.unboundid.scim2.server.utils.SchemaChecker.java
/** * Check an attribute value to see if it has the right type. * * @param prefix The issue prefix.//w w w .j a v a 2 s. c o m * @param node The attribute value. * @param path The attribute path. * @param attribute The attribute definition. * @param results The schema check results. * @param currentObjectNode The current resource. * @param isPartialReplace Whether this is a partial replace. * @param isPartialAdd Whether this is a partial add. * @throws ScimException If an error occurs. */ private void checkAttributeValue(final String prefix, final JsonNode node, final Path path, final AttributeDefinition attribute, final Results results, final ObjectNode currentObjectNode, final boolean isPartialReplace, final boolean isPartialAdd) throws ScimException { if (node.isNull()) { return; } // Check the node type. switch (attribute.getType()) { case STRING: case DATETIME: case BINARY: case REFERENCE: if (!node.isTextual()) { results.syntaxIssues.add(prefix + "Value for attribute " + path + " must be a JSON string"); return; } break; case BOOLEAN: if (!node.isBoolean()) { results.syntaxIssues.add(prefix + "Value for attribute " + path + " must be a JSON boolean"); return; } break; case DECIMAL: case INTEGER: if (!node.isNumber()) { results.syntaxIssues.add(prefix + "Value for attribute " + path + " must be a JSON number"); return; } break; case COMPLEX: if (!node.isObject()) { results.syntaxIssues.add(prefix + "Value for attribute " + path + " must be a JSON object"); return; } break; default: throw new RuntimeException("Unexpected attribute type " + attribute.getType()); } // If the node type checks out, check the actual value. switch (attribute.getType()) { case DATETIME: try { ISO8601Utils.parse(node.textValue(), new ParsePosition(0)); } catch (Exception e) { Debug.debug(Level.INFO, DebugType.EXCEPTION, "Invalid ISO8601 string during schema checking", e); results.syntaxIssues .add(prefix + "Value for attribute " + path + " is not a valid ISO8601 formatted string"); } break; case BINARY: try { Base64Variants.getDefaultVariant().decode(node.textValue()); } catch (Exception e) { Debug.debug(Level.INFO, DebugType.EXCEPTION, "Invalid base64 string during schema checking", e); results.syntaxIssues .add(prefix + "Value for attribute " + path + " is not a valid base64 encoded string"); } break; case REFERENCE: try { new URI(node.textValue()); } catch (Exception e) { Debug.debug(Level.INFO, DebugType.EXCEPTION, "Invalid URI string during schema checking", e); results.syntaxIssues.add(prefix + "Value for attribute " + path + " is not a valid URI string"); } break; case INTEGER: if (!node.isIntegralNumber()) { results.syntaxIssues.add(prefix + "Value for attribute " + path + " is not an integral number"); } break; case COMPLEX: checkObjectNode(prefix, path, attribute.getSubAttributes(), (ObjectNode) node, results, currentObjectNode, isPartialReplace, isPartialAdd, false); break; case STRING: // Check for canonical values if (attribute.getCanonicalValues() != null) { boolean found = false; for (String canonicalValue : attribute.getCanonicalValues()) { if (attribute.isCaseExact() ? canonicalValue.equals(node.textValue()) : StaticUtils.toLowerCase(canonicalValue) .equals(StaticUtils.toLowerCase(node.textValue()))) { found = true; break; } } if (!found) { results.syntaxIssues.add(prefix + "Value " + node.textValue() + " is not valid for attribute " + path + " because it " + "is not one of the canonical types: " + StaticUtils.collectionToString(attribute.getCanonicalValues(), ", ")); } } } // Special checking of the schemas attribute to ensure that // no undefined schemas are listed. if (attribute.equals(SchemaUtils.SCHEMAS_ATTRIBUTE_DEFINITION) && path.size() == 1) { boolean found = false; for (SchemaResource schemaExtension : resourceType.getSchemaExtensions().keySet()) { if (node.textValue().equals(schemaExtension.getId())) { found = true; break; } } if (!found) { found = node.textValue().equals(resourceType.getCoreSchema().getId()); } if (!found && !enabledOptions.contains(Option.ALLOW_UNDEFINED_ATTRIBUTES)) { results.syntaxIssues.add(prefix + "Schema URI " + node.textValue() + " is not a valid value for attribute " + path + " because it is " + "undefined as a core or schema extension for this resource type"); } } }
From source file:com.unboundid.scim2.common.GenericScimResource.java
private String getStringForBinary(final byte[] binary) throws ScimException { return Base64Variants.getDefaultVariant().encode(binary); }