public static String replaceTokens(String input, Multimap<String, ?> tokenValues) { for (Entry<String, ?> tokenValue : tokenValues.entries()) { Pattern pattern = TOKEN_TO_PATTERN.getUnchecked(tokenValue.getKey()); input = replaceAll(input, pattern, tokenValue.getValue().toString()); } return input; } }
public static String replaceTokens(String input, Multimap<String, ?> tokenValues) { for (Entry<String, ?> tokenValue : tokenValues.entries()) { Pattern pattern = TOKEN_TO_PATTERN.getUnchecked(tokenValue.getKey()); input = replaceAll(input, pattern, tokenValue.getValue().toString()); } return input; } }
private void appendCanonicalizedHeaders(HttpRequest request, StringBuilder toSign) { // TreeSet == Sort the headers alphabetically. Set<String> headers = Sets.newTreeSet(request.getHeaders().keySet()); for (String header : headers) { if (header.startsWith("x-ms-")) { toSign.append(header.toLowerCase()).append(":"); for (String value : request.getHeaders().get(header)) { toSign.append(Strings2.replaceAll(value, NEWLINE_PATTERN, "")).append(","); } toSign.deleteCharAt(toSign.lastIndexOf(",")); toSign.append("\n"); } } }
@Override public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) { String name = checkNotNull(postParams.get("name"), "name parameter not present").toString(); String protocol = checkNotNull(postParams.get("protocol"), "protocol parameter not present").toString(); String port = checkNotNull(postParams.get("port"), "port parameter not present").toString(); String enabled = checkNotNull(postParams.get("enabled"), "enabled parameter not present").toString(); String description = (String) postParams.get("description"); String payload = Strings2.replaceTokens(xmlTemplate, ImmutableMap.of("name", name, "protocol", protocol, "port", port, "enabled", enabled, "ns", ns)); try { payload = Strings2.replaceAll(payload, Patterns.TOKEN_TO_PATTERN.get("description"), description == null ? "" : String.format("\n\t<Description>%s</Description>", description)); payload = Strings2.replaceAll(payload, Patterns.TOKEN_TO_PATTERN.get("monitor"), getMonitorString(postParams)); } catch (ExecutionException e) { Throwables.propagate(e); } return stringBinder.bindToRequest(request, payload); }
@Override public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) { String ipAddress = checkNotNull(postParams.get("ipAddress"), "ipAddress parameter not present").toString(); String name = checkNotNull(postParams.get("name"), "name parameter not present").toString(); String port = checkNotNull(postParams.get("port"), "port parameter not present").toString(); String enabled = checkNotNull(postParams.get("enabled"), "enabled parameter not present").toString(); String description = (String) postParams.get("description"); String payload = Strings2.replaceTokens(xmlTemplate, ImmutableMap.of("name", name, "ipAddress", ipAddress, "port", port, "enabled", enabled, "ns", ns)); try { payload = Strings2.replaceAll(payload, Patterns.TOKEN_TO_PATTERN.get("description"), description == null ? "" : String.format("\n <Description>%s</Description>", description)); } catch (ExecutionException e) { Throwables.propagate(e); } return stringBinder.bindToRequest(request, payload); }
private void appendCanonicalizedHeaders(HttpRequest request, StringBuilder toSign) { // TreeSet == Sort the headers alphabetically. Set<String> headers = Sets.newTreeSet(request.getHeaders().keySet()); for (String header : headers) { if (header.startsWith("x-emc-") && !header.equals(AtmosHeaders.SIGNATURE)) { // Convert all header names to lowercase. toSign.append(header.toLowerCase()).append(":"); // For headers with values that span multiple lines, convert them into one line by // replacing any // newline characters and extra embedded white spaces in the value. for (String value : request.getHeaders().get(header)) { value = Strings2.replaceAll(value, TWO_SPACE_PATTERN, " "); value = Strings2.replaceAll(value, NEWLINE_PATTERN, ""); toSign.append(value).append(' '); } toSign.deleteCharAt(toSign.lastIndexOf(" ")); // Concatenate all headers together, using newlines (\n) separating each header from the // next one. toSign.append("\n"); } } // There should be no terminating newline character at the end of the last header. if (toSign.charAt(toSign.length() - 1) == '\n') toSign.deleteCharAt(toSign.length() - 1); }
private void appendCanonicalizedHeaders(HttpRequest request, StringBuilder toSign) { // TreeSet == Sort the headers alphabetically. Set<String> headers = Sets.newTreeSet(request.getHeaders().keySet()); for (String header : headers) { if (header.startsWith("x-emc-") && !header.equals(AtmosHeaders.SIGNATURE)) { // Convert all header names to lowercase. toSign.append(header.toLowerCase()).append(":"); // For headers with values that span multiple lines, convert them into one line by // replacing any // newline characters and extra embedded white spaces in the value. for (String value : request.getHeaders().get(header)) { value = Strings2.replaceAll(value, TWO_SPACE_PATTERN, " "); value = Strings2.replaceAll(value, NEWLINE_PATTERN, ""); toSign.append(value).append(' '); } toSign.deleteCharAt(toSign.lastIndexOf(" ")); // Concatenate all headers together, using newlines (\n) separating each header from the // next one. toSign.append("\n"); } } // There should be no terminating newline character at the end of the last header. if (toSign.charAt(toSign.length() - 1) == '\n') toSign.deleteCharAt(toSign.length() - 1); }
public GetOptions apply(org.jclouds.http.options.GetOptions[] from) { checkNotNull(from, "options"); org.jclouds.blobstore.options.GetOptions to = new org.jclouds.blobstore.options.GetOptions(); if (from.length != 0) { if (from[0].getIfMatch() != null) { to.ifETagMatches(Strings2.replaceAll(from[0].getIfMatch(), '"', "")); } if (from[0].getIfModifiedSince() != null) { Date time = dateService.rfc822DateParse(from[0].getIfModifiedSince()); to.ifModifiedSince(time); } if (from[0].getIfNoneMatch() != null) { to.ifETagDoesntMatch(Strings2.replaceAll(from[0].getIfNoneMatch(), '"', "")); } if (from[0].getIfUnmodifiedSince() != null) { Date time = dateService.rfc822DateParse(from[0].getIfUnmodifiedSince()); to.ifUnmodifiedSince(time); } for (String range : from[0].getRanges()) { String[] firstLast = range.split("\\-"); to.range(Long.parseLong(firstLast[0]), Long.parseLong(firstLast[1])); } } return to; }
public GetOptions apply(org.jclouds.http.options.GetOptions[] from) { checkNotNull(from, "options"); org.jclouds.blobstore.options.GetOptions to = new org.jclouds.blobstore.options.GetOptions(); if (from.length != 0) { if (from[0].getIfMatch() != null) { to.ifETagMatches(Strings2.replaceAll(from[0].getIfMatch(), '"', "")); } if (from[0].getIfModifiedSince() != null) { Date time = dateService.rfc822DateParse(from[0].getIfModifiedSince()); to.ifModifiedSince(time); } if (from[0].getIfNoneMatch() != null) { to.ifETagDoesntMatch(Strings2.replaceAll(from[0].getIfNoneMatch(), '"', "")); } if (from[0].getIfUnmodifiedSince() != null) { Date time = dateService.rfc822DateParse(from[0].getIfUnmodifiedSince()); to.ifUnmodifiedSince(time); } for (String range : from[0].getRanges()) { String[] firstLast = range.split("\\-"); to.range(Long.parseLong(firstLast[0]), Long.parseLong(firstLast[1])); } } return to; }
String currentETag = currentOrNull(currentText); builder.eTag(currentETag); currentETag = Strings2.replaceAll(currentETag, '"', ""); if (!MULTIPART_BLOB_ETAG.matcher(currentETag).matches()) { builder.contentMD5(base16().lowerCase().decode(currentETag));
String currentETag = currentOrNull(currentText); builder.eTag(currentETag); currentETag = Strings2.replaceAll(currentETag, '"', ""); if (!MULTIPART_BLOB_ETAG.matcher(currentETag).matches()) { builder.contentMD5(base16().lowerCase().decode(currentETag));