Search in sources :

Example 1 with MixedAttribute

use of io.netty.handler.codec.http.multipart.MixedAttribute in project asterixdb by apache.

the class PostRequest method create.

public static IServletRequest create(FullHttpRequest request) throws IOException {
    List<String> names = new ArrayList<>();
    List<String> values = new ArrayList<>();
    HttpPostRequestDecoder decoder = null;
    try {
        decoder = new HttpPostRequestDecoder(request);
    } catch (Exception e) {
        //ignore. this means that the body of the POST request does not have key value pairs
        LOGGER.log(Level.WARNING, "Failed to decode a post message. Fix the API not to have queries as POST body", e);
    }
    if (decoder != null) {
        try {
            List<InterfaceHttpData> bodyHttpDatas = decoder.getBodyHttpDatas();
            for (InterfaceHttpData data : bodyHttpDatas) {
                if (data.getHttpDataType().equals(InterfaceHttpData.HttpDataType.Attribute)) {
                    Attribute attr = (MixedAttribute) data;
                    names.add(data.getName());
                    values.add(attr.getValue());
                }
            }
        } finally {
            decoder.destroy();
        }
    }
    return new PostRequest(request, new QueryStringDecoder(request.uri()).parameters(), names, values);
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) Attribute(io.netty.handler.codec.http.multipart.Attribute) MixedAttribute(io.netty.handler.codec.http.multipart.MixedAttribute) InterfaceHttpData(io.netty.handler.codec.http.multipart.InterfaceHttpData) ArrayList(java.util.ArrayList) MixedAttribute(io.netty.handler.codec.http.multipart.MixedAttribute) HttpPostRequestDecoder(io.netty.handler.codec.http.multipart.HttpPostRequestDecoder) IOException(java.io.IOException)

Aggregations

QueryStringDecoder (io.netty.handler.codec.http.QueryStringDecoder)1 Attribute (io.netty.handler.codec.http.multipart.Attribute)1 HttpPostRequestDecoder (io.netty.handler.codec.http.multipart.HttpPostRequestDecoder)1 InterfaceHttpData (io.netty.handler.codec.http.multipart.InterfaceHttpData)1 MixedAttribute (io.netty.handler.codec.http.multipart.MixedAttribute)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1