Search in sources :

Example 1 with HttpPostMultipartRequestDecoder

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();
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpPostMultipartRequestDecoder(io.netty.handler.codec.http.multipart.HttpPostMultipartRequestDecoder) DefaultHttpDataFactory(io.netty.handler.codec.http.multipart.DefaultHttpDataFactory)

Example 2 with HttpPostMultipartRequestDecoder

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);
}
Also used : HttpPostMultipartRequestDecoder(io.netty.handler.codec.http.multipart.HttpPostMultipartRequestDecoder) Test(org.junit.Test)

Example 3 with HttpPostMultipartRequestDecoder

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));
}
Also used : InterfaceHttpData(io.netty.handler.codec.http.multipart.InterfaceHttpData) HttpPostMultipartRequestDecoder(io.netty.handler.codec.http.multipart.HttpPostMultipartRequestDecoder) Test(org.junit.Test)

Aggregations

HttpPostMultipartRequestDecoder (io.netty.handler.codec.http.multipart.HttpPostMultipartRequestDecoder)3 Test (org.junit.Test)2 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)1 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)1 HttpRequest (io.netty.handler.codec.http.HttpRequest)1 DefaultHttpDataFactory (io.netty.handler.codec.http.multipart.DefaultHttpDataFactory)1 InterfaceHttpData (io.netty.handler.codec.http.multipart.InterfaceHttpData)1