public boolean handlesPayloadType(final Request request) { return isNonEmpty(request.getFormParams()); }
if (isNonEmpty(request.getFormParams())) { StringBuilder sb = new StringBuilder(128); for (Param param : request.getFormParams()) { String name = URLEncoder.encode(param.getName(), charset); String value = URLEncoder.encode(param.getValue(), charset);
} else if (isNonEmpty(request.getFormParams())) { String formBody = AsyncHttpProviderUtils.urlEncodeFormParams0(request.getFormParams()).toString(); urlConnection.setRequestProperty("Content-Length", String.valueOf(formBody.length())); urlConnection.setFixedLengthStreamingMode(formBody.length());
@Override public void calculateAndAddSignature(Request request, RequestBuilderBase<?> requestBuilder) { String nonce = generateNonce(); long timestamp = generateTimestamp(); String signature = calculateSignature(request.getMethod(), request.getUri(), timestamp, nonce, request.getFormParams(), request.getQueryParams()); String headerValue = constructAuthHeader(signature, nonce, timestamp); requestBuilder.setHeader(HEADER_AUTHORIZATION, headerValue); }
@Override public List<Param> getFormParams() { return delegate.getFormParams(); }
public RequestImpl(Request prototype) { if (prototype != null) { this.method = prototype.getMethod(); this.uri = prototype.getUri(); this.address = prototype.getInetAddress(); this.localAddress = prototype.getLocalAddress(); this.headers = new FluentCaseInsensitiveStringsMap(prototype.getHeaders()); this.cookies = new ArrayList<>(prototype.getCookies()); this.byteData = prototype.getByteData(); this.compositeByteData = prototype.getCompositeByteData(); this.stringData = prototype.getStringData(); this.streamData = prototype.getStreamData(); this.bodyGenerator = prototype.getBodyGenerator(); this.formParams = prototype.getFormParams() == null ? null : new ArrayList<>(prototype.getFormParams()); this.parts = prototype.getParts() == null ? null : new ArrayList<>(prototype.getParts()); this.virtualHost = prototype.getVirtualHost(); this.length = prototype.getContentLength(); this.proxyServer = prototype.getProxyServer(); this.realm = prototype.getRealm(); this.file = prototype.getFile(); this.followRedirects = prototype.getFollowRedirect(); this.requestTimeout = prototype.getRequestTimeout(); this.rangeOffset = prototype.getRangeOffset(); this.charset = prototype.getBodyEncoding(); this.connectionPoolPartitioning = prototype.getConnectionPoolPartitioning(); this.nameResolver = prototype.getNameResolver(); } }
public boolean handlesPayloadType(final Request request) { return isNonEmpty(request.getFormParams()); }
public boolean handlesPayloadType(final Request request) { return isNonEmpty(request.getFormParams()); }
public boolean handlesBodyType(final Request request) { return isNonEmpty(request.getFormParams()); }
nettyBody = new NettyInputStreamBody(request.getStreamData()); else if (isNonEmpty(request.getFormParams())) { contentType = HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED; nettyBody = new NettyByteBufferBody(urlEncodeFormParams(request.getFormParams(), bodyCharset), contentType);
if (keepBody) { requestBuilder.setBodyEncoding(request.getBodyEncoding()); if (MiscUtils.isNonEmpty(request.getFormParams())) requestBuilder.setFormParams(request.getFormParams()); else if (request.getStringData() != null) requestBuilder.setBody(request.getStringData());
@Override public void calculateAndAddSignature(Request request, RequestBuilderBase<?> requestBuilder) { String nonce = generateNonce(); long timestamp = System.currentTimeMillis() / 1000L; String signature = calculateSignature(request.getMethod(), request.getURI(), timestamp, nonce, request.getFormParams(), request.getQueryParams()); String headerValue = constructAuthHeader(signature, nonce, timestamp); requestBuilder.setHeader(HEADER_AUTHORIZATION, headerValue); }
@Override public void calculateAndAddSignature(Request request, RequestBuilderBase<?> requestBuilder) { String nonce = generateNonce(); long timestamp = generateTimestamp(); String signature = calculateSignature(request.getMethod(), request.getUri(), timestamp, nonce, request.getFormParams(), request.getQueryParams()); String headerValue = constructAuthHeader(signature, nonce, timestamp); requestBuilder.setHeader(HEADER_AUTHORIZATION, headerValue); }
@Override public void calculateAndAddSignature(Request request, RequestBuilderBase<?> requestBuilder) { String nonce = generateNonce(); long timestamp = generateTimestamp(); String signature = calculateSignature(request.getMethod(), request.getUri(), timestamp, nonce, request.getFormParams(), request.getQueryParams()); String headerValue = constructAuthHeader(signature, nonce, timestamp); requestBuilder.setHeader(HEADER_AUTHORIZATION, headerValue); }
public RequestImpl(Request prototype) { if (prototype != null) { this.method = prototype.getMethod(); this.uri = prototype.getURI(); this.address = prototype.getInetAddress(); this.localAddress = prototype.getLocalAddress(); this.headers = new FluentCaseInsensitiveStringsMap(prototype.getHeaders()); this.cookies = new ArrayList<Cookie>(prototype.getCookies()); this.byteData = prototype.getByteData(); this.stringData = prototype.getStringData(); this.streamData = prototype.getStreamData(); this.bodyGenerator = prototype.getBodyGenerator(); this.formParams = prototype.getFormParams() == null ? null : new ArrayList<Param>(prototype.getFormParams()); this.parts = prototype.getParts() == null ? null : new ArrayList<Part>(prototype.getParts()); this.virtualHost = prototype.getVirtualHost(); this.length = prototype.getContentLength(); this.proxyServer = prototype.getProxyServer(); this.realm = prototype.getRealm(); this.file = prototype.getFile(); this.followRedirects = prototype.getFollowRedirect(); this.requestTimeout = prototype.getRequestTimeout(); this.rangeOffset = prototype.getRangeOffset(); this.charset = prototype.getBodyEncoding(); this.connectionPoolKeyStrategy = prototype.getConnectionPoolKeyStrategy(); } }
public RequestImpl(Request prototype) { if (prototype != null) { this.method = prototype.getMethod(); this.uri = prototype.getUri(); this.address = prototype.getInetAddress(); this.localAddress = prototype.getLocalAddress(); this.headers = new FluentCaseInsensitiveStringsMap(prototype.getHeaders()); this.cookies = new ArrayList<>(prototype.getCookies()); this.byteData = prototype.getByteData(); this.compositeByteData = prototype.getCompositeByteData(); this.stringData = prototype.getStringData(); this.streamData = prototype.getStreamData(); this.bodyGenerator = prototype.getBodyGenerator(); this.formParams = prototype.getFormParams() == null ? null : new ArrayList<>(prototype.getFormParams()); this.parts = prototype.getParts() == null ? null : new ArrayList<>(prototype.getParts()); this.virtualHost = prototype.getVirtualHost(); this.length = prototype.getContentLength(); this.proxyServer = prototype.getProxyServer(); this.realm = prototype.getRealm(); this.file = prototype.getFile(); this.followRedirects = prototype.getFollowRedirect(); this.requestTimeout = prototype.getRequestTimeout(); this.rangeOffset = prototype.getRangeOffset(); this.charset = prototype.getBodyEncoding(); this.connectionPoolPartitioning = prototype.getConnectionPoolPartitioning(); this.nameResolver = prototype.getNameResolver(); } }
public RequestImpl(Request prototype) { if (prototype != null) { this.method = prototype.getMethod(); this.uri = prototype.getUri(); this.address = prototype.getInetAddress(); this.localAddress = prototype.getLocalAddress(); this.headers = new FluentCaseInsensitiveStringsMap(prototype.getHeaders()); this.cookies = new ArrayList<>(prototype.getCookies()); this.byteData = prototype.getByteData(); this.compositeByteData = prototype.getCompositeByteData(); this.stringData = prototype.getStringData(); this.streamData = prototype.getStreamData(); this.bodyGenerator = prototype.getBodyGenerator(); this.formParams = prototype.getFormParams() == null ? null : new ArrayList<>(prototype.getFormParams()); this.parts = prototype.getParts() == null ? null : new ArrayList<>(prototype.getParts()); this.virtualHost = prototype.getVirtualHost(); this.length = prototype.getContentLength(); this.proxyServer = prototype.getProxyServer(); this.realm = prototype.getRealm(); this.file = prototype.getFile(); this.followRedirects = prototype.getFollowRedirect(); this.requestTimeout = prototype.getRequestTimeout(); this.rangeOffset = prototype.getRangeOffset(); this.charset = prototype.getBodyEncoding(); this.connectionPoolPartitioning = prototype.getConnectionPoolPartitioning(); this.nameResolver = prototype.getNameResolver(); } }
private void testSignatureBaseStringWithEncodableOAuthToken(Request request) { ConsumerKey consumer = new ConsumerKey("9djdj82h48djs9d2", CONSUMER_SECRET); RequestToken user = new RequestToken("kkk9d7dh3k39sjv7", TOKEN_SECRET); OAuthSignatureCalculator calc = new OAuthSignatureCalculator(consumer, user); String signatureBaseString = calc.signatureBaseString(// request.getMethod(),// request.getUri(),// 137131201,// "ZLc92RAkooZcIO/0cctl0Q==",// request.getFormParams(),// request.getQueryParams()).toString(); assertEquals(signatureBaseString, "POST&" // + "http%3A%2F%2Fexample.com%2Frequest" // + "&a2%3Dr%2520b%26"// + "a3%3D2%2520q%26" + "a3%3Da%26"// + "b5%3D%253D%25253D%26"// + "c%2540%3D%26"// + "c2%3D%26"// + "oauth_consumer_key%3D9djdj82h48djs9d2%26"// + "oauth_nonce%3DZLc92RAkooZcIO%252F0cctl0Q%253D%253D%26"// + "oauth_signature_method%3DHMAC-SHA1%26"// + "oauth_timestamp%3D137131201%26"// + "oauth_token%3Dkkk9d7dh3k39sjv7%26"// + "oauth_version%3D1.0"); }
private void testSignatureBaseString(Request request) { ConsumerKey consumer = new ConsumerKey("9djdj82h48djs9d2", CONSUMER_SECRET); RequestToken user = new RequestToken("kkk9d7dh3k39sjv7", TOKEN_SECRET); OAuthSignatureCalculator calc = new OAuthSignatureCalculator(consumer, user); String signatureBaseString = calc.signatureBaseString(// request.getMethod(),// request.getUri(),// 137131201,// "7d8f3e4a",// request.getFormParams(),// request.getQueryParams()).toString(); assertEquals(signatureBaseString, "POST&" // + "http%3A%2F%2Fexample.com%2Frequest" // + "&a2%3Dr%2520b%26"// + "a3%3D2%2520q%26" + "a3%3Da%26"// + "b5%3D%253D%25253D%26"// + "c%2540%3D%26"// + "c2%3D%26"// + "oauth_consumer_key%3D9djdj82h48djs9d2%26"// + "oauth_nonce%3D7d8f3e4a%26"// + "oauth_signature_method%3DHMAC-SHA1%26"// + "oauth_timestamp%3D137131201%26"// + "oauth_token%3Dkkk9d7dh3k39sjv7%26"// + "oauth_version%3D1.0"); }
private NettyBody body(Request request, HttpMethod method) throws IOException { NettyBody nettyBody = null; if (method != HttpMethod.CONNECT) { Charset bodyCharset = request.getBodyEncoding() == null ? DEFAULT_CHARSET : Charset.forName(request.getBodyEncoding()); if (request.getByteData() != null) nettyBody = new NettyByteArrayBody(request.getByteData()); else if (request.getStringData() != null) nettyBody = new NettyByteArrayBody(request.getStringData().getBytes(bodyCharset)); else if (request.getStreamData() != null) nettyBody = new NettyInputStreamBody(request.getStreamData()); else if (isNonEmpty(request.getFormParams())) { String contentType = null; if (!request.getHeaders().containsKey(HttpHeaders.Names.CONTENT_TYPE)) contentType = HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED; nettyBody = new NettyByteArrayBody(computeBodyFromParams(request.getFormParams(), bodyCharset), contentType); } else if (isNonEmpty(request.getParts())) nettyBody = new NettyMultipartBody(request.getParts(), request.getHeaders(), nettyConfig); else if (request.getFile() != null) nettyBody = new NettyFileBody(request.getFile(), nettyConfig); else if (request.getBodyGenerator() instanceof FileBodyGenerator) { FileBodyGenerator fileBodyGenerator = (FileBodyGenerator) request.getBodyGenerator(); nettyBody = new NettyFileBody(fileBodyGenerator.getFile(), fileBodyGenerator.getRegionSeek(), fileBodyGenerator.getRegionLength(), nettyConfig); } else if (request.getBodyGenerator() instanceof InputStreamBodyGenerator) nettyBody = new NettyInputStreamBody(InputStreamBodyGenerator.class.cast(request.getBodyGenerator()).getInputStream()); else if (request.getBodyGenerator() != null) nettyBody = new NettyBodyBody(request.getBodyGenerator().createBody(), nettyConfig); } return nettyBody; }