Search in sources :

Example 6 with Attribute

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.multipart.Attribute in project netty by netty.

the class HttpUploadServerHandler method writeHttpData.

private void writeHttpData(InterfaceHttpData data) {
    if (data.getHttpDataType() == HttpDataType.Attribute) {
        Attribute attribute = (Attribute) data;
        String value;
        try {
            value = attribute.getValue();
        } catch (IOException e1) {
            // Error while reading data from File, only print name and error
            e1.printStackTrace();
            responseContent.append("\r\nBODY Attribute: " + attribute.getHttpDataType().name() + ": " + attribute.getName() + " Error while reading value: " + e1.getMessage() + "\r\n");
            return;
        }
        if (value.length() > 100) {
            responseContent.append("\r\nBODY Attribute: " + attribute.getHttpDataType().name() + ": " + attribute.getName() + " data too long\r\n");
        } else {
            responseContent.append("\r\nBODY Attribute: " + attribute.getHttpDataType().name() + ": " + attribute + "\r\n");
        }
    } else {
        responseContent.append("\r\nBODY FileUpload: " + data.getHttpDataType().name() + ": " + data + "\r\n");
        if (data.getHttpDataType() == HttpDataType.FileUpload) {
            FileUpload fileUpload = (FileUpload) data;
            if (fileUpload.isCompleted()) {
                if (fileUpload.length() < 10000) {
                    responseContent.append("\tContent of file\r\n");
                    try {
                        responseContent.append(fileUpload.getString(fileUpload.getCharset()));
                    } catch (IOException e1) {
                        // do nothing for the example
                        e1.printStackTrace();
                    }
                    responseContent.append("\r\n");
                } else {
                    responseContent.append("\tFile too long to be printed out:" + fileUpload.length() + "\r\n");
                }
            // fileUpload.isInMemory();// tells if the file is in Memory
            // or on File
            // fileUpload.renameTo(dest); // enable to move into another
            // File dest
            // decoder.removeFileUploadFromClean(fileUpload); //remove
            // the File of to delete file
            } else {
                responseContent.append("\tFile to be continued but should not!\r\n");
            }
        }
    }
}
Also used : Attribute(io.netty.handler.codec.http.multipart.Attribute) DiskAttribute(io.netty.handler.codec.http.multipart.DiskAttribute) IOException(java.io.IOException) DiskFileUpload(io.netty.handler.codec.http.multipart.DiskFileUpload) FileUpload(io.netty.handler.codec.http.multipart.FileUpload)

Example 7 with Attribute

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.multipart.Attribute in project vert.x by eclipse.

the class Http2ServerRequest method handleEnd.

void handleEnd(MultiMap trailers) {
    HttpEventHandler handler;
    synchronized (conn) {
        streamEnded = true;
        ended = true;
        if (postRequestDecoder != null) {
            try {
                postRequestDecoder.offer(LastHttpContent.EMPTY_LAST_CONTENT);
                while (postRequestDecoder.hasNext()) {
                    InterfaceHttpData data = postRequestDecoder.next();
                    if (data instanceof Attribute) {
                        Attribute attr = (Attribute) data;
                        try {
                            formAttributes().add(attr.getName(), attr.getValue());
                        } catch (Exception e) {
                            // Will never happen, anyway handle it somehow just in case
                            handleException(e);
                        } finally {
                            attr.release();
                        }
                    }
                }
            } catch (HttpPostRequestDecoder.EndOfDataDecoderException e) {
            // ignore this as it is expected
            } catch (Exception e) {
                handleException(e);
            } finally {
                postRequestDecoder.destroy();
            }
        }
        handler = eventHandler;
    }
    if (handler != null) {
        handler.handleEnd();
    }
}
Also used : Attribute(io.netty.handler.codec.http.multipart.Attribute) InterfaceHttpData(io.netty.handler.codec.http.multipart.InterfaceHttpData) HttpPostRequestDecoder(io.netty.handler.codec.http.multipart.HttpPostRequestDecoder) URISyntaxException(java.net.URISyntaxException) StreamResetException(io.vertx.core.http.StreamResetException) ClosedChannelException(java.nio.channels.ClosedChannelException) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException)

Example 8 with Attribute

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.multipart.Attribute in project dubbo by alibaba.

the class HttpCommandDecoder method decode.

public static CommandContext decode(HttpRequest request) {
    CommandContext commandContext = null;
    if (request != null) {
        QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.getUri());
        String path = queryStringDecoder.path();
        String[] array = path.split("/");
        if (array.length == 2) {
            String name = array[1];
            // process GET request and POST request separately. Check url for GET, and check body for POST
            if (request.getMethod() == HttpMethod.GET) {
                if (queryStringDecoder.parameters().isEmpty()) {
                    commandContext = CommandContextFactory.newInstance(name);
                    commandContext.setHttp(true);
                } else {
                    List<String> valueList = new ArrayList<String>();
                    for (List<String> values : queryStringDecoder.parameters().values()) {
                        valueList.addAll(values);
                    }
                    commandContext = CommandContextFactory.newInstance(name, valueList.toArray(new String[] {}), true);
                }
            } else if (request.getMethod() == HttpMethod.POST) {
                HttpPostRequestDecoder httpPostRequestDecoder = new HttpPostRequestDecoder(request);
                List<String> valueList = new ArrayList<String>();
                for (InterfaceHttpData interfaceHttpData : httpPostRequestDecoder.getBodyHttpDatas()) {
                    if (interfaceHttpData.getHttpDataType() == InterfaceHttpData.HttpDataType.Attribute) {
                        Attribute attribute = (Attribute) interfaceHttpData;
                        try {
                            valueList.add(attribute.getValue());
                        } catch (IOException ex) {
                            throw new RuntimeException(ex);
                        }
                    }
                }
                if (valueList.isEmpty()) {
                    commandContext = CommandContextFactory.newInstance(name);
                    commandContext.setHttp(true);
                } else {
                    commandContext = CommandContextFactory.newInstance(name, valueList.toArray(new String[] {}), true);
                }
            }
        }
    }
    return commandContext;
}
Also used : CommandContext(org.apache.dubbo.qos.command.CommandContext) Attribute(io.netty.handler.codec.http.multipart.Attribute) ArrayList(java.util.ArrayList) IOException(java.io.IOException) HttpPostRequestDecoder(io.netty.handler.codec.http.multipart.HttpPostRequestDecoder) QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) InterfaceHttpData(io.netty.handler.codec.http.multipart.InterfaceHttpData) List(java.util.List) ArrayList(java.util.ArrayList)

Example 9 with Attribute

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.multipart.Attribute in project moco by dreamhead.

the class FormsRequestExtractor method doExtractForms.

private ImmutableMap<String, String> doExtractForms(final HttpPostRequestDecoder decoder) throws IOException {
    List<InterfaceHttpData> bodyHttpDatas = decoder.getBodyHttpDatas();
    Map<String, String> forms = newHashMap();
    for (InterfaceHttpData data : bodyHttpDatas) {
        if (data.getHttpDataType() == InterfaceHttpData.HttpDataType.Attribute) {
            Attribute attribute = (Attribute) data;
            forms.put(attribute.getName(), attribute.getValue());
        }
    }
    return copyOf(forms);
}
Also used : Attribute(io.netty.handler.codec.http.multipart.Attribute) InterfaceHttpData(io.netty.handler.codec.http.multipart.InterfaceHttpData)

Example 10 with Attribute

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.multipart.Attribute in project vert.x by eclipse.

the class Http2ServerRequestImpl method handleEnd.

void handleEnd(MultiMap trailers) {
    ended = true;
    conn.reportBytesRead(bytesRead);
    if (postRequestDecoder != null) {
        try {
            postRequestDecoder.offer(LastHttpContent.EMPTY_LAST_CONTENT);
            while (postRequestDecoder.hasNext()) {
                InterfaceHttpData data = postRequestDecoder.next();
                if (data instanceof Attribute) {
                    Attribute attr = (Attribute) data;
                    try {
                        formAttributes().add(attr.getName(), attr.getValue());
                    } catch (Exception e) {
                        // Will never happen, anyway handle it somehow just in case
                        handleException(e);
                    }
                }
            }
        } catch (HttpPostRequestDecoder.EndOfDataDecoderException e) {
        // ignore this as it is expected
        } catch (Exception e) {
            handleException(e);
        } finally {
            postRequestDecoder.destroy();
        }
    }
    if (endHandler != null) {
        endHandler.handle(null);
    }
}
Also used : Attribute(io.netty.handler.codec.http.multipart.Attribute) InterfaceHttpData(io.netty.handler.codec.http.multipart.InterfaceHttpData) HttpPostRequestDecoder(io.netty.handler.codec.http.multipart.HttpPostRequestDecoder) URISyntaxException(java.net.URISyntaxException) StreamResetException(io.vertx.core.http.StreamResetException) ClosedChannelException(java.nio.channels.ClosedChannelException) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException)

Aggregations

Attribute (io.netty.handler.codec.http.multipart.Attribute)10 InterfaceHttpData (io.netty.handler.codec.http.multipart.InterfaceHttpData)9 HttpPostRequestDecoder (io.netty.handler.codec.http.multipart.HttpPostRequestDecoder)8 IOException (java.io.IOException)8 Path (java.nio.file.Path)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 QueryStringDecoder (io.netty.handler.codec.http.QueryStringDecoder)3 HttpRequest (org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest)3 FileUpload (io.netty.handler.codec.http.multipart.FileUpload)2 StreamResetException (io.vertx.core.http.StreamResetException)2 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 ClosedChannelException (java.nio.channels.ClosedChannelException)2 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)2 DefaultFullHttpRequest (org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest)2 Attribute (org.apache.flink.shaded.netty4.io.netty.handler.codec.http.multipart.Attribute)2 CommandContext (com.alibaba.dubbo.qos.command.CommandContext)1 ByteBuf (io.netty.buffer.ByteBuf)1 io.netty.handler.codec.http (io.netty.handler.codec.http)1