Refine search![Refine arrow](//d16xvuom8mr9m8.cloudfront.net/code/public/images/refine-arrow.226bef887e7b1c430d6d498717d9d561.svg)
private void appendPayloadMetadata(HttpRequest request, StringBuilder buffer) { buffer.append( Strings.nullToEmpty(request.getPayload() == null ? null : request.getPayload().getContentMetadata() .getContentType())).append("\n"); }
public HttpRequest filter(HttpRequest request) { checkNotNull(request.getPayload(), "request is not ready to wrap; payload not present"); Credentials current = creds.get(); String body = request.getPayload().getRawContent().toString(); Payload wrappedPayload = Payloads.newStringPayload(new StringBuilder() .append(format(SOAP_PREFIX, current.identity, current.credential)).append(body).append(SOAP_SUFFIX) .toString()); wrappedPayload.getContentMetadata().setContentType("application/xml"); return request.toBuilder().payload(wrappedPayload).build(); } }
@Test void testBuildCanonicalizedStringSetsVersion() { HttpRequest filtered = staticCredentialsFilter.filter(request); assertEquals(filtered.getPayload().getRawContent(), "Action=DescribeImages&ImageId.1=ami-2bb65342&Signature=ugnt4m2eHE7Ka/vXTr9EhKZq7bhxOfvW0y4pAEqF97w%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=apiVersion&AWSAccessKeyId=identity"); }
private void appendPayloadMetadata(HttpRequest request, StringBuilder buffer) { buffer.append( Strings.nullToEmpty(request.getPayload() == null ? null : request.getPayload().getContentMetadata() .getContentType())).append("\n"); }
public HttpRequest filter(HttpRequest request) { checkNotNull(request.getPayload(), "request is not ready to wrap; payload not present"); Credentials current = creds.get(); String body = request.getPayload().getRawContent().toString(); Payload wrappedPayload = Payloads.newStringPayload(new StringBuilder() .append(format(SOAP_PREFIX, current.identity, current.credential)).append(body).append(SOAP_SUFFIX) .toString()); wrappedPayload.getContentMetadata().setContentType("application/xml"); return request.toBuilder().payload(wrappedPayload).build(); } }
public void testAlarmNamesBinder() throws Exception { HttpRequest request = binder.bindToRequest(request(), ImmutableSet.of("TestAlarmName1", "TestAlarmName2")); Assert.assertEquals(request.getPayload().getRawContent(), "AlarmNames.member.1=TestAlarmName1&AlarmNames.member.2=TestAlarmName2"); }
private void appendPayloadMetadata(HttpRequest request, StringBuilder buffer) { buffer.append( HttpUtils.nullToEmpty(request.getPayload() == null ? null : request.getPayload().getContentMetadata() .getContentMD5())).append("\n"); buffer.append( Strings.nullToEmpty(request.getPayload() == null ? null : request.getPayload().getContentMetadata() .getContentType())).append("\n"); }
public HttpRequest filter(HttpRequest request) { checkNotNull(request.getPayload(), "request is not ready to wrap; payload not present"); Credentials current = creds.get(); String body = request.getPayload().getRawContent().toString(); Payload wrappedPayload = Payloads.newStringPayload(new StringBuilder() .append(format(SOAP_PREFIX, current.identity, current.credential)).append(body).append(SOAP_SUFFIX) .toString()); wrappedPayload.getContentMetadata().setContentType("application/xml"); return request.toBuilder().payload(wrappedPayload).build(); } }
public void test() { HttpRequest request = HttpRequest.builder().method("POST").endpoint("http://localhost").build(); request = binder.bindToRequest(request, ImmutableList.builder().add("alpha").add("omega").build()); assertEquals(request.getPayload().getRawContent(), "ResourceId.1=alpha&ResourceId.2=omega"); }
private void appendPayloadMetadata(HttpRequest request, StringBuilder buffer) { buffer.append(utils.valueOrEmpty(request.getPayload() == null ? null : request.getPayload().getContentMetadata().getContentMD5())) .append("\n"); buffer.append(utils.valueOrEmpty(request.getPayload() == null ? null : request.getPayload().getContentMetadata().getContentType())) .append("\n"); }
public HttpRequest filter(HttpRequest request) { checkNotNull(request.getPayload(), "request is not ready to wrap; payload not present"); Credentials current = creds.get(); String body = request.getPayload().getRawContent().toString(); Payload wrappedPayload = Payloads.newStringPayload(new StringBuilder() .append(format(SOAP_PREFIX, current.identity, current.credential)).append(body).append(SOAP_SUFFIX) .toString()); wrappedPayload.getContentMetadata().setContentType("application/xml"); return request.toBuilder().payload(wrappedPayload).build(); } }
public void test() { HttpRequest request = HttpRequest.builder().method("POST").endpoint("http://localhost").build(); request = binder.bindToRequest(request, ImmutableMultimap.<String, String> builder() .put("resource-type", "instance") .put("key", "stack") .putAll("value", "Test", "Production") .build()); assertEquals( request.getPayload().getRawContent(), "Filter.1.Name=resource-type&Filter.1.Value.1=instance&Filter.2.Name=key&Filter.2.Value.1=stack&Filter.3.Name=value&Filter.3.Value.1=Test&Filter.3.Value.2=Production"); }
@Override protected HttpUriRequest convert(HttpRequest request) throws IOException { HttpUriRequest returnVal = apacheHCUtils.convertToApacheRequest(request); if (request.getPayload() != null && request.getPayload().getContentMetadata().getContentMD5() != null){ String md5 = base64().encode(asByteSource(request.getPayload().getInput()).hash(md5()).asBytes()); returnVal.addHeader("Content-MD5", md5); } return returnVal; }
private HttpRequest createSoapRequest(HttpRequest request) { Payload oldPayload = request.getPayload(); ContentMetadata oldMetadata = oldPayload.getContentMetadata(); String body = SOAP_PREFIX.concat(oldPayload.getRawContent().toString()).concat(SOAP_SUFFIX); Payload newPayload = Payloads.newStringPayload(body); HttpUtils.copy(oldMetadata, newPayload.getContentMetadata()); newPayload.getContentMetadata().setContentLength(Long.valueOf(body.getBytes().length)); // resize, add prefix/suffix length return request.toBuilder().payload(newPayload).build(); }
@Test public void testFactoryCorrect() throws SecurityException, NoSuchMethodException { BindToJsonPayloadWrappedWith binder = injector.getInstance(BindToJsonPayloadWrappedWith.Factory.class).create( "envelope"); HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://momma").build(); request = binder.bindToRequest(request, ImmutableMap.of("imageName", "foo", "serverId", "2")); assertEquals(request.getPayload().getRawContent(), "{\"envelope\":{\"imageName\":\"foo\",\"serverId\":\"2\"}}"); }
@Override public <R extends HttpRequest> R bindToRequest(R request, Object payload) { checkArgument(payload instanceof Server, "this binder is only valid for Server!"); Server create = Server.class.cast(payload); Map<String, String> map = createServerRequestToMap.apply(create); request.setPayload(listOfMapsToListOfKeyValuesDelimitedByBlankLines.apply(ImmutableSet.of(map))); request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN); return request; } }
public void testSimple() throws IOException { HttpRequest request = HttpRequest.builder().method("POST").endpoint("https://host/drives/create").build(); i.getInstance(BindServerToPlainTextString.class).bindToRequest(request, SERVER); assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN); assertEquals(request.getPayload().getRawContent(), CREATED_SERVER); }
public void testApplyInputStream() throws IOException { HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://test").build(); BindNoBucketLoggingToXmlPayload binder = injector.getInstance(BindNoBucketLoggingToXmlPayload.class); request = binder.bindToRequest(request, "bucket"); assertEquals(request.getPayload().getRawContent(), "<BucketLoggingStatus xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"/>"); } }
@Override public <R extends HttpRequest> R bindToRequest(R request, Object payload) { checkArgument(payload instanceof Drive, "this binder is only valid for Drive!"); Drive create = Drive.class.cast(payload); Map<String, String> map = createDriveRequestToMap.apply(create); request.setPayload(listOfMapsToListOfKeyValuesDelimitedByBlankLines.apply(ImmutableSet.of(map))); request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN); return request; } }
public void testSimple() throws IOException { HttpRequest request = HttpRequest.builder().method("POST").endpoint("https://host/drives/create").build(); FN.bindToRequest(request, SERVER); assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN); assertEquals(request.getPayload().getRawContent(), CREATED_SERVER); }