Example usage for com.amazonaws.http HttpMethodName PATCH

List of usage examples for com.amazonaws.http HttpMethodName PATCH

Introduction

In this page you can find the example usage for com.amazonaws.http HttpMethodName PATCH.

Prototype

HttpMethodName PATCH

To view the source code for com.amazonaws.http HttpMethodName PATCH.

Click Source Link

Usage

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, final HttpMethodName methodName) {

    GenericApiGatewayRequestBuilder builder = new GenericApiGatewayRequestBuilder()
            .withResourcePath(resourcePath);
    final Map<String, List<String>> parameters = getParameters(context);
    builder = builder.withParameters(parameters);

    InputStream requestBody = null;
    switch (methodName) {
    case GET:/*ww  w  .jav  a2 s. c om*/
        builder = builder.withHttpMethod(HttpMethodName.GET);
        break;
    case POST:
        requestBody = getRequestBodyToSend(session, context, requestFlowFile);
        builder = builder.withHttpMethod(HttpMethodName.POST).withBody(requestBody);
        break;
    case PUT:
        requestBody = getRequestBodyToSend(session, context, requestFlowFile);
        builder = builder.withHttpMethod(HttpMethodName.PUT).withBody(requestBody);
        break;
    case PATCH:
        requestBody = getRequestBodyToSend(session, context, requestFlowFile);
        builder = builder.withHttpMethod(HttpMethodName.PATCH).withBody(requestBody);
        break;
    case HEAD:
        builder = builder.withHttpMethod(HttpMethodName.HEAD);
        break;
    case DELETE:
        builder = builder.withHttpMethod(HttpMethodName.DELETE);
        break;
    case OPTIONS:
        requestBody = getRequestBodyToSend(session, context, requestFlowFile);
        builder = builder.withHttpMethod(HttpMethodName.OPTIONS).withBody(requestBody);
        break;
    }

    builder = setHeaderProperties(context, builder, methodName, requestFlowFile);
    return builder.build();
}

From source file:org.apache.nifi.processors.aws.wag.AbstractAWSGatewayApiProcessor.java

License:Apache License

protected GenericApiGatewayRequestBuilder setHeaderProperties(final ProcessContext context,
        GenericApiGatewayRequestBuilder requestBuilder, HttpMethodName methodName,
        final FlowFile requestFlowFile) {

    Map<String, String> headers = new HashMap<>();
    for (String headerKey : dynamicPropertyNames) {
        String headerValue = context.getProperty(headerKey).evaluateAttributeExpressions(requestFlowFile)
                .getValue();/*w ww  .jav a2 s .com*/
        headers.put(headerKey, headerValue);
    }

    // iterate through the flowfile attributes, adding any attribute that
    // matches the attributes-to-send pattern. if the pattern is not set
    // (it's an optional property), ignore that attribute entirely
    if (regexAttributesToSend != null && requestFlowFile != null) {
        Map<String, String> attributes = requestFlowFile.getAttributes();
        Matcher m = regexAttributesToSend.matcher("");
        for (Map.Entry<String, String> entry : attributes.entrySet()) {
            String headerKey = trimToEmpty(entry.getKey());

            // don't include any of the ignored attributes
            if (IGNORED_ATTRIBUTES.contains(headerKey)) {
                continue;
            }

            // check if our attribute key matches the pattern
            // if so, include in the request as a header
            m.reset(headerKey);
            if (m.matches()) {
                String headerVal = trimToEmpty(entry.getValue());
                headers.put(headerKey, headerVal);
            }
        }
    }

    String contentType = context.getProperty(PROP_CONTENT_TYPE).evaluateAttributeExpressions(requestFlowFile)
            .getValue();
    boolean sendBody = context.getProperty(PROP_SEND_BODY).asBoolean();
    contentType = StringUtils.isBlank(contentType) ? DEFAULT_CONTENT_TYPE : contentType;
    if (methodName == HttpMethodName.PUT || methodName == HttpMethodName.POST
            || methodName == HttpMethodName.PATCH) {
        if (sendBody) {
            headers.put("Content-Type", contentType);
        }
    } else {
        headers.put("Content-Type", contentType);
    }

    if (!headers.isEmpty()) {
        requestBuilder = requestBuilder.withHeaders(headers);
    }

    return requestBuilder;
}