Search in sources :

Example 1 with OutputStreamMulti

use of io.helidon.common.reactive.OutputStreamMulti in project helidon by oracle.

the class HelidonEntity method submit.

/**
 * Convert Jersey {@code OutputStream} to an entity based on the client request use case and submits to the provided
 * {@code WebClientRequestBuilder}.
 * @param type the type of the Helidon entity.
 * @param requestContext Jersey {@link ClientRequest} providing the entity {@code OutputStream}.
 * @param requestBuilder Helidon {@code WebClientRequestBuilder} which is used to submit the entity
 * @param executorService {@link ExecutorService} that fills the entity instance for Helidon with data from Jersey
 *                      {@code OutputStream}.
 * @return Helidon Client response completion stage.
 */
static CompletionStage<WebClientResponse> submit(HelidonEntityType type, ClientRequest requestContext, WebClientRequestBuilder requestBuilder, ExecutorService executorService) {
    CompletionStage<WebClientResponse> stage = null;
    if (type != null) {
        final int bufferSize = requestContext.resolveProperty(ClientProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, 8192);
        switch(type) {
            case BYTE_ARRAY_OUTPUT_STREAM:
                final ByteArrayOutputStream baos = new ByteArrayOutputStream(bufferSize);
                requestContext.setStreamProvider(contentLength -> baos);
                ((ProcessingRunnable) requestContext::writeEntity).run();
                stage = requestBuilder.submit(baos);
                break;
            case READABLE_BYTE_CHANNEL:
                final OutputStreamChannel channel = new OutputStreamChannel(bufferSize);
                requestContext.setStreamProvider(contentLength -> channel);
                executorService.execute((ProcessingRunnable) requestContext::writeEntity);
                stage = requestBuilder.submit(channel);
                break;
            case OUTPUT_STREAM_MULTI:
                final OutputStreamMulti publisher = IoMulti.outputStreamMulti();
                requestContext.setStreamProvider(contentLength -> publisher);
                executorService.execute((ProcessingRunnable) () -> {
                    requestContext.writeEntity();
                    publisher.close();
                });
                stage = requestBuilder.submit(Multi.create(publisher).map(DataChunk::create));
                break;
            default:
        }
    }
    return stage;
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) OutputStreamMulti(io.helidon.common.reactive.OutputStreamMulti) DataChunk(io.helidon.common.http.DataChunk) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with OutputStreamMulti

use of io.helidon.common.reactive.OutputStreamMulti in project metro-jax-ws by eclipse-ee4j.

the class HelidonConnectionImpl method getOutput.

@Override
public OutputStream getOutput() throws IOException {
    OutputStreamMulti os = IoMulti.outputStreamMulti();
    res.send(os.map(byteBuffer -> DataChunk.create(false, true, byteBuffer)));
    return os;
}
Also used : DataChunk(io.helidon.common.http.DataChunk) Context(io.helidon.common.context.Context) MediaType(io.helidon.common.http.MediaType) ArrayList(java.util.ArrayList) WSEndpoint(com.sun.xml.ws.api.server.WSEndpoint) PortAddressResolver(com.sun.xml.ws.api.server.PortAddressResolver) WSHTTPConnection(com.sun.xml.ws.transport.http.WSHTTPConnection) WsservletMessages(com.sun.xml.ws.resources.WsservletMessages) Parameters(io.helidon.common.http.Parameters) Map(java.util.Map) ServerResponse(io.helidon.webserver.ServerResponse) HaInfo(com.sun.xml.ws.api.ha.HaInfo) OutputStream(java.io.OutputStream) WebServiceContextDelegate(com.sun.xml.ws.api.server.WebServiceContextDelegate) IoMulti(io.helidon.common.reactive.IoMulti) MethodHandles(java.lang.invoke.MethodHandles) Set(java.util.Set) IOException(java.io.IOException) Logger(java.util.logging.Logger) OutputStreamMulti(io.helidon.common.reactive.OutputStreamMulti) ServerRequest(io.helidon.webserver.ServerRequest) List(java.util.List) Principal(java.security.Principal) Packet(com.sun.xml.ws.api.message.Packet) DataChunkInputStream(io.helidon.media.common.DataChunkInputStream) HttpAdapter(com.sun.xml.ws.transport.http.HttpAdapter) InputStream(java.io.InputStream) OutputStreamMulti(io.helidon.common.reactive.OutputStreamMulti)

Aggregations

DataChunk (io.helidon.common.http.DataChunk)2 OutputStreamMulti (io.helidon.common.reactive.OutputStreamMulti)2 HaInfo (com.sun.xml.ws.api.ha.HaInfo)1 Packet (com.sun.xml.ws.api.message.Packet)1 PortAddressResolver (com.sun.xml.ws.api.server.PortAddressResolver)1 WSEndpoint (com.sun.xml.ws.api.server.WSEndpoint)1 WebServiceContextDelegate (com.sun.xml.ws.api.server.WebServiceContextDelegate)1 WsservletMessages (com.sun.xml.ws.resources.WsservletMessages)1 HttpAdapter (com.sun.xml.ws.transport.http.HttpAdapter)1 WSHTTPConnection (com.sun.xml.ws.transport.http.WSHTTPConnection)1 Context (io.helidon.common.context.Context)1 MediaType (io.helidon.common.http.MediaType)1 Parameters (io.helidon.common.http.Parameters)1 IoMulti (io.helidon.common.reactive.IoMulti)1 DataChunkInputStream (io.helidon.media.common.DataChunkInputStream)1 WebClientResponse (io.helidon.webclient.WebClientResponse)1 ServerRequest (io.helidon.webserver.ServerRequest)1 ServerResponse (io.helidon.webserver.ServerResponse)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1