use of io.netty.handler.codec.http.multipart.InterfaceHttpData 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 io.netty.handler.codec.http.multipart.InterfaceHttpData 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 io.netty.handler.codec.http.multipart.InterfaceHttpData 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);
}
}
use of io.netty.handler.codec.http.multipart.InterfaceHttpData in project android by JetBrains.
the class GoogleCrashTest method checkServerReceivesPostedData.
@Ignore
@Test
public void checkServerReceivesPostedData() throws Exception {
String expectedReportId = "deadcafe";
Map<String, String> attributes = new ConcurrentHashMap<>();
myTestServer.setResponseSupplier(httpRequest -> {
if (httpRequest.method() != HttpMethod.POST) {
return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST);
}
HttpPostRequestDecoder requestDecoder = new HttpPostRequestDecoder(httpRequest);
try {
for (InterfaceHttpData httpData : requestDecoder.getBodyHttpDatas()) {
if (httpData instanceof Attribute) {
Attribute attr = (Attribute) httpData;
attributes.put(attr.getName(), attr.getValue());
}
}
} catch (IOException e) {
return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST);
} finally {
requestDecoder.destroy();
}
return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(expectedReportId.getBytes(UTF_8)));
});
CrashReport report = CrashReport.Builder.createForException(ourIndexNotReadyException).setProduct("AndroidStudioTestProduct").setVersion("1.2.3.4").build();
CompletableFuture<String> reportId = myReporter.submit(report);
assertEquals(expectedReportId, reportId.get());
// assert that the server get the expected data
assertEquals("AndroidStudioTestProduct", attributes.get(GoogleCrash.KEY_PRODUCT_ID));
assertEquals("1.2.3.4", attributes.get(GoogleCrash.KEY_VERSION));
// Note: the exception message should have been elided
assertEquals("com.intellij.openapi.project.IndexNotReadyException: <elided>\n" + STACK_TRACE, attributes.get(GoogleCrash.KEY_EXCEPTION_INFO));
List<String> descriptions = Arrays.asList("2.3.0.0\n1.8.0_73-b02", "2.3.0.1\n1.8.0_73-b02");
report = CrashReport.Builder.createForCrashes(descriptions).setProduct("AndroidStudioTestProduct").setVersion("1.2.3.4").build();
attributes.clear();
reportId = myReporter.submit(report);
assertEquals(expectedReportId, reportId.get());
// check that the crash count and descriptions made through
assertEquals(descriptions.size(), Integer.parseInt(attributes.get("numCrashes")));
assertEquals("2.3.0.0\n1.8.0_73-b02\n\n2.3.0.1\n1.8.0_73-b02", attributes.get("crashDesc"));
Path testData = Paths.get(AndroidTestBase.getTestDataPath());
List<String> threadDump = Files.readAllLines(testData.resolve(Paths.get("threadDumps", "1.txt")), UTF_8);
report = CrashReport.Builder.createForPerfReport("td.txt", Joiner.on('\n').join(threadDump)).build();
attributes.clear();
reportId = myReporter.submit(report);
assertEquals(expectedReportId, reportId.get());
assertEquals(threadDump.stream().collect(Collectors.joining("\n")), attributes.get("td.txt"));
}
use of io.netty.handler.codec.http.multipart.InterfaceHttpData in project riposte by Nike-Inc.
the class RequestInfoImplTest method getMultipartParts_returns_data_from_multipartData.
@Test
public void getMultipartParts_returns_data_from_multipartData() {
// given
RequestInfoImpl<?> requestInfo = RequestInfoImpl.dummyInstanceForUnknownRequests();
Whitebox.setInternalState(requestInfo, "isMultipart", true);
requestInfo.isCompleteRequestWithAllChunks = true;
HttpPostMultipartRequestDecoder multipartDataMock = mock(HttpPostMultipartRequestDecoder.class);
List<InterfaceHttpData> dataListMock = mock(List.class);
doReturn(dataListMock).when(multipartDataMock).getBodyHttpDatas();
requestInfo.multipartData = multipartDataMock;
// when
List<InterfaceHttpData> result = requestInfo.getMultipartParts();
// then
assertThat(result, is(dataListMock));
}
Aggregations