All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.networknt.rule.encoder.RequestBodyUtf8EncodingTransformAction Maven / Gradle / Ivy

package com.networknt.rule.encoder;

import com.networknt.rule.IAction;
import com.networknt.rule.RuleActionValue;
import com.networknt.rule.RuleConstants;
import com.networknt.utility.ModuleRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;
import java.util.Map;

/**
 * This action is used to transform the request body encoding from one encoding to UTF-8 encoding.
 * As the RequestTransformInterceptor has already converted the body stream into UTF-8 encoding, here
 * we just need to change the declaration in the body string if it is an XML string.
 *
 * @author Steve Hu
 */
public class RequestBodyUtf8EncodingTransformAction implements IAction {
    private static final Logger logger = LoggerFactory.getLogger(RequestBodyUtf8EncodingTransformAction.class);
    public static final String REQUEST_BODY = "requestBody";
    public static final String UTF8 = "UTF-8";

    public RequestBodyUtf8EncodingTransformAction() {
        if(logger.isInfoEnabled()) logger.info("RequestBodyUtf8EncodingTransformAction is constructed");
        ModuleRegistry.registerPlugin(
                RequestBodyUtf8EncodingTransformAction.class.getPackage().getImplementationTitle(),
                RequestBodyUtf8EncodingTransformAction.class.getPackage().getImplementationVersion(),
                null,
                RequestBodyUtf8EncodingTransformAction.class.getName(),
                null,
                null);
    }

    @Override
    public void performAction(Map objMap, Map resultMap, Collection actionValues) {
        // get the body from the objMap and create a new body in the resultMap.
        resultMap.put(RuleConstants.RESULT, true);
        String requestBody = (String)objMap.get(REQUEST_BODY);
        if(logger.isTraceEnabled()) logger.trace("original requestBody = {}", requestBody);
        if(requestBody.startsWith("




© 2015 - 2024 Weber Informatics LLC | Privacy Policy