use of io.netty.handler.codec.http.multipart.HttpPostMultipartRequestDecoder in project riposte by Nike-Inc.
the class RequestInfoImpl method getMultipartParts.
/**
* {@inheritDoc}
*/
@Override
public synchronized List<InterfaceHttpData> getMultipartParts() {
if (!isMultipartRequest() || !isCompleteRequestWithAllChunks())
return null;
if (multipartData == null) {
byte[] contentBytes = getRawContentBytes();
HttpRequest fullHttpRequestForMultipartDecoder = (contentBytes == null) ? new DefaultFullHttpRequest(getProtocolVersion(), getMethod(), getUri()) : new DefaultFullHttpRequest(getProtocolVersion(), getMethod(), getUri(), Unpooled.wrappedBuffer(contentBytes));
fullHttpRequestForMultipartDecoder.headers().add(getHeaders());
multipartData = new HttpPostMultipartRequestDecoder(new DefaultHttpDataFactory(false), fullHttpRequestForMultipartDecoder, getContentCharset());
}
return multipartData.getBodyHttpDatas();
}
use of io.netty.handler.codec.http.multipart.HttpPostMultipartRequestDecoder in project riposte by Nike-Inc.
the class RequestInfoImplTest method releaseMultipartData_works_as_expected_and_does_nothing_on_subsequent_calls.
@Test
public void releaseMultipartData_works_as_expected_and_does_nothing_on_subsequent_calls() {
// given
RequestInfoImpl<?> requestInfo = RequestInfoImpl.dummyInstanceForUnknownRequests();
requestInfo.multipartDataIsDestroyed = false;
HttpPostMultipartRequestDecoder multipartDataMock = mock(HttpPostMultipartRequestDecoder.class);
requestInfo.multipartData = multipartDataMock;
// when
requestInfo.releaseMultipartData();
// then
assertThat(requestInfo.multipartDataIsDestroyed, is(true));
verify(multipartDataMock).destroy();
// and when subsequent calls come in
requestInfo.releaseMultipartData();
// then nothing else happened
verifyNoMoreInteractions(multipartDataMock);
}
use of io.netty.handler.codec.http.multipart.HttpPostMultipartRequestDecoder 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