List of usage examples for com.amazonaws.http HttpMethodName fromValue
public static HttpMethodName fromValue(String value)
From source file:com.eucalyptus.ws.handlers.IoInternalHmacHandler.java
License:Open Source License
private SignableRequest<?> wrapRequest(final FullHttpRequest request) { return new SignableRequest() { @Override/*from www . ja v a 2 s . co m*/ public Map<String, String> getHeaders() { return request.headers().entries().stream() .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } @Override public String getResourcePath() { return request.getUri(); } @Override public Map<String, List<String>> getParameters() { return Collections.emptyMap(); } @Override public URI getEndpoint() { return URI.create("http://" + request.headers().get(HttpHeaders.Names.HOST)); } @Override public HttpMethodName getHttpMethod() { return HttpMethodName.fromValue(request.getMethod().name()); } @Override public int getTimeOffset() { return 0; } @Override public InputStream getContent() { return new ByteBufInputStream(request.content().slice()); } @Override public InputStream getContentUnwrapped() { return getContent(); } @Override public ReadLimitInfo getReadLimitInfo() { return () -> request.content().readableBytes(); } @Override public Object getOriginalRequestObject() { throw new RuntimeException("Not supported"); } @Override public void addHeader(final String s, final String s1) { request.headers().set(s, s1); } @Override public void addParameter(final String s, final String s1) { throw new RuntimeException("Not supported"); } @Override public void setContent(final InputStream inputStream) { throw new RuntimeException("Not supported"); } }; }
From source file:com.streamsets.pipeline.lib.aws.AwsRequestSigningApacheInterceptor.java
License:Apache License
/** * {@inheritDoc}//from w ww . j a v a 2 s . c om */ @Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { URIBuilder uriBuilder; try { uriBuilder = new URIBuilder(request.getRequestLine().getUri()); } catch (URISyntaxException e) { throw new IOException("Invalid URI", e); } // Copy Apache HttpRequest to AWS DefaultRequest DefaultRequest<?> signableRequest = new DefaultRequest<>(service); HttpHost host = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST); if (host != null) { signableRequest.setEndpoint(URI.create(host.toURI())); } final HttpMethodName httpMethod = HttpMethodName.fromValue(request.getRequestLine().getMethod()); signableRequest.setHttpMethod(httpMethod); try { signableRequest.setResourcePath(uriBuilder.build().getRawPath()); } catch (URISyntaxException e) { throw new IOException("Invalid URI", e); } if (request instanceof HttpEntityEnclosingRequest) { HttpEntityEnclosingRequest httpEntityEnclosingRequest = (HttpEntityEnclosingRequest) request; if (httpEntityEnclosingRequest.getEntity() != null) { signableRequest.setContent(httpEntityEnclosingRequest.getEntity().getContent()); } } signableRequest.setParameters(nvpToMapParams(uriBuilder.getQueryParams())); signableRequest.setHeaders(headerArrayToMap(request.getAllHeaders())); // Sign it signer.sign(signableRequest, awsCredentialsProvider.getCredentials()); // Now copy everything back request.setHeaders(mapToHeaderArray(signableRequest.getHeaders())); if (request instanceof HttpEntityEnclosingRequest) { HttpEntityEnclosingRequest httpEntityEnclosingRequest = (HttpEntityEnclosingRequest) request; if (httpEntityEnclosingRequest.getEntity() != null) { BasicHttpEntity basicHttpEntity = new BasicHttpEntity(); basicHttpEntity.setContent(signableRequest.getContent()); httpEntityEnclosingRequest.setEntity(basicHttpEntity); } } }
From source file:org.apache.nifi.processors.aws.wag.AbstractAWSGatewayApiProcessor.java
License:Apache License
@Override protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) { final List<ValidationResult> results = new ArrayList<>(3); results.addAll(super.customValidate(validationContext)); final boolean querySet = validationContext.getProperty(PROP_QUERY_PARAMS).isSet(); if (querySet) { String input = validationContext.getProperty(PROP_QUERY_PARAMS).getValue(); // if we have expressions, we don't do further validation if (!(validationContext.isExpressionLanguageSupported(PROP_QUERY_PARAMS.getName()) && validationContext.isExpressionLanguagePresent(input))) { try { final String evaluatedInput = validationContext.newPropertyValue(input) .evaluateAttributeExpressions().getValue(); // user is not expected to encode, that will be done by the aws client // but we may need to when validating final String encodedInput = URLEncoder.encode(evaluatedInput, "UTF-8"); final String url = String.format("http://www.foo.com?%s", encodedInput); new URL(url); results.add(new ValidationResult.Builder().subject(PROP_QUERY_PARAMS.getName()).input(input) .explanation("Valid URL params").valid(true).build()); } catch (final Exception e) { results.add(new ValidationResult.Builder().subject(PROP_QUERY_PARAMS.getName()).input(input) .explanation("Not a valid set of URL params").valid(false).build()); }//w w w. j a v a 2 s . c o m } } String method = trimToEmpty(validationContext.getProperty(PROP_METHOD).getValue()).toUpperCase(); // if there are expressions do not validate if (!(validationContext.isExpressionLanguageSupported(PROP_METHOD.getName()) && validationContext.isExpressionLanguagePresent(method))) { try { HttpMethodName methodName = HttpMethodName.fromValue(method); } catch (IllegalArgumentException e) { results.add(new ValidationResult.Builder().subject(PROP_METHOD.getName()).input(method) .explanation("Unsupported METHOD").valid(false).build()); } } return results; }
From source file:org.apache.nifi.processors.aws.wag.AbstractAWSGatewayApiProcessor.java
License:Apache License
protected GenericApiGatewayRequest configureRequest(final ProcessContext context, final ProcessSession session, final String resourcePath, final FlowFile requestFlowFile) { String method = trimToEmpty(//from w ww .j av a2 s . co m context.getProperty(PROP_METHOD).evaluateAttributeExpressions(requestFlowFile).getValue()) .toUpperCase(); HttpMethodName methodName = HttpMethodName.fromValue(method); return configureRequest(context, session, resourcePath, requestFlowFile, methodName); }