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");
}
}
}
}
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();
}
}
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;
}
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);
}
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);
}
}
Aggregations