Search in sources :

Example 1 with NettyCompositeByteArrayBody

use of org.asynchttpclient.netty.request.body.NettyCompositeByteArrayBody in project async-http-client by AsyncHttpClient.

the class NettyRequestFactory method body.

private NettyBody body(Request request, boolean connect) {
    NettyBody nettyBody = null;
    if (!connect) {
        Charset bodyCharset = withDefault(request.getCharset(), DEFAULT_CHARSET);
        if (request.getByteData() != null) {
            nettyBody = new NettyByteArrayBody(request.getByteData());
        } else if (request.getCompositeByteData() != null) {
            nettyBody = new NettyCompositeByteArrayBody(request.getCompositeByteData());
        } else if (request.getStringData() != null) {
            nettyBody = new NettyByteBufferBody(StringUtils.charSequence2ByteBuffer(request.getStringData(), bodyCharset));
        } else if (request.getByteBufferData() != null) {
            nettyBody = new NettyByteBufferBody(request.getByteBufferData());
        } else if (request.getStreamData() != null) {
            nettyBody = new NettyInputStreamBody(request.getStreamData());
        } else if (isNonEmpty(request.getFormParams())) {
            CharSequence contentType = null;
            if (!request.getHeaders().contains(CONTENT_TYPE)) {
                contentType = HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED;
            }
            nettyBody = new NettyByteBufferBody(urlEncodeFormParams(request.getFormParams(), bodyCharset), contentType);
        } else if (isNonEmpty(request.getBodyParts())) {
            nettyBody = new NettyMultipartBody(request.getBodyParts(), request.getHeaders(), config);
        } else if (request.getFile() != null) {
            nettyBody = new NettyFileBody(request.getFile(), config);
        } else if (request.getBodyGenerator() instanceof FileBodyGenerator) {
            FileBodyGenerator fileBodyGenerator = (FileBodyGenerator) request.getBodyGenerator();
            nettyBody = new NettyFileBody(fileBodyGenerator.getFile(), fileBodyGenerator.getRegionSeek(), fileBodyGenerator.getRegionLength(), config);
        } else if (request.getBodyGenerator() instanceof InputStreamBodyGenerator) {
            InputStreamBodyGenerator inStreamGenerator = InputStreamBodyGenerator.class.cast(request.getBodyGenerator());
            nettyBody = new NettyInputStreamBody(inStreamGenerator.getInputStream(), inStreamGenerator.getContentLength());
        } else if (request.getBodyGenerator() instanceof ReactiveStreamsBodyGenerator) {
            ReactiveStreamsBodyGenerator reactiveStreamsBodyGenerator = (ReactiveStreamsBodyGenerator) request.getBodyGenerator();
            nettyBody = new NettyReactiveStreamsBody(reactiveStreamsBodyGenerator.getPublisher(), reactiveStreamsBodyGenerator.getContentLength());
        } else if (request.getBodyGenerator() != null) {
            nettyBody = new NettyBodyBody(request.getBodyGenerator().createBody(), config);
        }
    }
    return nettyBody;
}
Also used : InputStreamBodyGenerator(org.asynchttpclient.request.body.generator.InputStreamBodyGenerator) NettyMultipartBody(org.asynchttpclient.netty.request.body.NettyMultipartBody) NettyInputStreamBody(org.asynchttpclient.netty.request.body.NettyInputStreamBody) Charset(java.nio.charset.Charset) NettyCompositeByteArrayBody(org.asynchttpclient.netty.request.body.NettyCompositeByteArrayBody) FileBodyGenerator(org.asynchttpclient.request.body.generator.FileBodyGenerator) NettyByteBufferBody(org.asynchttpclient.netty.request.body.NettyByteBufferBody) NettyByteArrayBody(org.asynchttpclient.netty.request.body.NettyByteArrayBody) ReactiveStreamsBodyGenerator(org.asynchttpclient.request.body.generator.ReactiveStreamsBodyGenerator) NettyBodyBody(org.asynchttpclient.netty.request.body.NettyBodyBody) NettyBody(org.asynchttpclient.netty.request.body.NettyBody) NettyFileBody(org.asynchttpclient.netty.request.body.NettyFileBody) NettyReactiveStreamsBody(org.asynchttpclient.netty.request.body.NettyReactiveStreamsBody)

Aggregations

Charset (java.nio.charset.Charset)1 NettyBody (org.asynchttpclient.netty.request.body.NettyBody)1 NettyBodyBody (org.asynchttpclient.netty.request.body.NettyBodyBody)1 NettyByteArrayBody (org.asynchttpclient.netty.request.body.NettyByteArrayBody)1 NettyByteBufferBody (org.asynchttpclient.netty.request.body.NettyByteBufferBody)1 NettyCompositeByteArrayBody (org.asynchttpclient.netty.request.body.NettyCompositeByteArrayBody)1 NettyFileBody (org.asynchttpclient.netty.request.body.NettyFileBody)1 NettyInputStreamBody (org.asynchttpclient.netty.request.body.NettyInputStreamBody)1 NettyMultipartBody (org.asynchttpclient.netty.request.body.NettyMultipartBody)1 NettyReactiveStreamsBody (org.asynchttpclient.netty.request.body.NettyReactiveStreamsBody)1 FileBodyGenerator (org.asynchttpclient.request.body.generator.FileBodyGenerator)1 InputStreamBodyGenerator (org.asynchttpclient.request.body.generator.InputStreamBodyGenerator)1 ReactiveStreamsBodyGenerator (org.asynchttpclient.request.body.generator.ReactiveStreamsBodyGenerator)1