@Override public IRequest setQueryParam(String key, String value) { request.param(key, value); return this; }
@Override public InputStream establishSharedSession(String sharedSessionName) throws IOException { if (logger.isInfoEnabled()) { logger.info(ROPUtil.getLogConnect(url, username, true, sharedSessionName)); } try { ContentResponse response = httpClient.newRequest(url) .method(HttpMethod.POST) .param(ROPConstants.OPERATION_PARAMETER, ROPConstants.ESTABLISH_SHARED_SESSION_OPERATION) .param(ROPConstants.SESSION_NAME_PARAMETER, sharedSessionName) .timeout(readTimeout, TimeUnit.SECONDS) .send(); return new ByteArrayInputStream(response.getContent()); } catch (Exception e) { if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); } throw new IOException("Exception while establishing shared session: " + sharedSessionName, e); } }
@Override public InputStream establishSession() throws IOException { if (logger.isInfoEnabled()) { logger.info(ROPUtil.getLogConnect(url, username, true)); } try { ContentResponse response = httpClient.newRequest(url) .method(HttpMethod.POST) .param(ROPConstants.OPERATION_PARAMETER, ROPConstants.ESTABLISH_SESSION_OPERATION) .timeout(readTimeout, TimeUnit.SECONDS) .send(); return new ByteArrayInputStream(response.getContent()); } catch (Exception e) { if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); } throw new IOException("Exception while establishing session", e); } }
private Request createHttpRequest(OAuthTokenRequest request) { Request httpRequest = httpClient.newRequest(request.getUrl()) .timeout(request.getRequestTimeout(), TimeUnit.MILLISECONDS) .method(HttpMethod.POST) .header(HttpHeader.KEEP_ALIVE, "true") .header(HttpHeader.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED.toString()) .param(OAuthTokenRequest.Param.GRANT_TYPE, request.getGrantType()) .param(OAuthTokenRequest.Param.SCOPE, request.getScope()) .param(OAuthTokenRequest.Param.CLIENT_ID, request.getClientId()) .param(OAuthTokenRequest.Param.CLIENT_SECRET, request.getClientSecret()); if (OAuthTokenRequest.GrantTypeValue.RESOURCE_OWNER_USERNAME_PASSWORD.equals(request.getGrantType())) { httpRequest .param(OAuthTokenRequest.Param.USERNAME, request.getUsername()) .param(OAuthTokenRequest.Param.PASSWORD, request.getPassword()); } return httpRequest; }
private Request createHttpRequest(OAuthTokenRequest request) { Request httpRequest = httpClient.newRequest(request.getUrl()) .timeout(request.getRequestTimeout(), TimeUnit.MILLISECONDS) .method(HttpMethod.POST) .header(HttpHeader.KEEP_ALIVE, "true") .header(HttpHeader.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED.toString()) .param(OAuthTokenRequest.Param.GRANT_TYPE, request.getGrantType()) .param(OAuthTokenRequest.Param.SCOPE, request.getScope()) .param(OAuthTokenRequest.Param.CLIENT_ID, request.getClientId()) .param(OAuthTokenRequest.Param.CLIENT_SECRET, request.getClientSecret()); if (OAuthTokenRequest.GrantTypeValue.RESOURCE_OWNER_USERNAME_PASSWORD.equals(request.getGrantType())) { httpRequest .param(OAuthTokenRequest.Param.USERNAME, request.getUsername()) .param(OAuthTokenRequest.Param.PASSWORD, request.getPassword()); } return httpRequest; }
private Request prepareRequest(HttpRequest request) { Request httpRequest = httpClient.newRequest(request.getUri()) .timeout(metadata.getReadTimeout(), TimeUnit.MILLISECONDS) .method(request.getHttpMethod().method()); byte[] entity = request.getEntity(); if(entity != null){ httpRequest = httpRequest.content(new BytesContentProvider(entity),request.getContentType()); } Joiner joiner = Joiner.on(",").skipNulls(); Map<String, Collection<String>> headers = request.getHeaders(); for (Map.Entry<String, Collection<String>> stringCollectionEntry : headers.entrySet()) { String key = stringCollectionEntry.getKey(); Collection<String> stringCollection = stringCollectionEntry.getValue(); String value = joiner.join(stringCollection); httpRequest = httpRequest.header(key, value); } for (Map.Entry<String, Collection<String>> stringCollectionEntry : request.getQueryParams().entrySet()) { String key = stringCollectionEntry.getKey(); Collection<String> stringCollection = stringCollectionEntry.getValue(); String value = joiner.join(stringCollection); httpRequest = httpRequest.param(key, value); } return httpRequest; } }
private void configureQueryParameters(Request request) { try { Config queryParameters = params.parseNestedOrGetEmpty("query"); for (String name : queryParameters.getKeys()) { request.param( UserSecretTemplate.of(name).format(context.getSecrets()), UserSecretTemplate.of(queryParameters.get(name, String.class)).format(context.getSecrets())); } } catch (ConfigException e) { Optional<String> query = params.getOptional("query", String.class) .transform(s -> UserSecretTemplate.of(s).format(context.getSecrets())); if (query.isPresent()) { List<NameValuePair> parameters = URLEncodedUtils.parse(query.get(), UTF_8); for (NameValuePair parameter : parameters) { request.param(parameter.getName(), parameter.getValue()); } } } }
if(parameters.size() > 0) { for(Parameter parameter : parameters) { jettyRequest.param(parameter.getName(), parameter.getValue());