Search in sources :

Example 6 with ResponseStreamHandle

use of com.webpieces.http2.api.streaming.ResponseStreamHandle in project webpieces by deanhiller.

the class Level8NotifyClntListeners method sendRstToApp.

@Override
public XFuture<Void> sendRstToApp(Stream stream, CancelReason payload) {
    if (stream instanceof ClientStream) {
        ClientStream str = (ClientStream) stream;
        ResponseStreamHandle handler = str.getResponseListener();
        return handler.cancel(payload);
    }
    ClientPushStream str = (ClientPushStream) stream;
    PushStreamHandle handle = str.getPushStreamHandle();
    return handle.cancelPush(payload);
}
Also used : PushStreamHandle(com.webpieces.http2.api.streaming.PushStreamHandle) ResponseStreamHandle(com.webpieces.http2.api.streaming.ResponseStreamHandle)

Example 7 with ResponseStreamHandle

use of com.webpieces.http2.api.streaming.ResponseStreamHandle in project webpieces by deanhiller.

the class DefaultCorsProcessor method send403Response.

private void send403Response(ResponseStreamHandle responseStream, Http2Request request) {
    Http2Response response = new Http2Response();
    response.addHeader(new Http2Header(Http2HeaderName.STATUS, "403"));
    response.addHeader(new Http2Header(Http2HeaderName.VARY, "Origin"));
    sendResponse(responseStream, response);
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Example 8 with ResponseStreamHandle

use of com.webpieces.http2.api.streaming.ResponseStreamHandle in project webpieces by deanhiller.

the class JsonController method streaming.

public StreamRef streaming(ResponseStreamHandle handle) {
    XFuture<StreamRef> futureStream = new XFuture<>();
    XFuture<Boolean> authFuture = svc.authenticate("bobsmith");
    XFuture<StreamWriter> writer = authFuture.thenCompose(resp -> {
        StreamRef streamRef = client.stream(handle);
        futureStream.complete(streamRef);
        return streamRef.getWriter();
    });
    return new StreamRefProxy(writer, futureStream);
}
Also used : StreamRef(com.webpieces.http2.api.streaming.StreamRef) XFuture(org.webpieces.util.futures.XFuture) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter)

Example 9 with ResponseStreamHandle

use of com.webpieces.http2.api.streaming.ResponseStreamHandle in project webpieces by deanhiller.

the class ClientAsync method startWriteThread.

private Void startWriteThread(Http2Socket socket, int i, ResponseStreamHandle handler) {
    Thread t = new Thread(new Writer(socket, handler));
    t.setName("clientWriter" + i);
    t.start();
    return null;
}
Also used : StreamWriter(com.webpieces.http2.api.streaming.StreamWriter)

Example 10 with ResponseStreamHandle

use of com.webpieces.http2.api.streaming.ResponseStreamHandle in project webpieces by deanhiller.

the class ClientAsync method runAsyncClient.

public void runAsyncClient(InetSocketAddress svrAddress) {
    ResponseStreamHandle responseListener = new ResponseCounterListener();
    log.error("ASYNC " + protocol + " CLIENT: logging will log every 10 seconds as ERROR so it shows up in red");
    log.info("info messages automatically show up in black");
    List<Http2Socket> sockets = new ArrayList<>();
    for (int i = 0; i < config.getNumSockets(); i++) {
        try {
            log.info("connecting socket num=" + i);
            Http2Socket socket = client.createHttpSocket(new CloseListener());
            XFuture<Void> connect = socket.connect(svrAddress);
            connect.get(2, TimeUnit.SECONDS);
            sockets.add(socket);
        } catch (Throwable e) {
            throw SneakyThrow.sneak(e);
        }
    }
    for (int i = 0; i < config.getNumSockets(); i++) {
        Http2Socket socket = sockets.get(i);
        startWriteThread(socket, i, responseListener);
    }
}
Also used : ResponseStreamHandle(com.webpieces.http2.api.streaming.ResponseStreamHandle) ArrayList(java.util.ArrayList) Http2Socket(org.webpieces.http2client.api.Http2Socket)

Aggregations

ResponseStreamHandle (com.webpieces.http2.api.streaming.ResponseStreamHandle)5 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)5 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)4 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)2 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)2 PushStreamHandle (com.webpieces.http2.api.streaming.PushStreamHandle)2 StreamRef (com.webpieces.http2.api.streaming.StreamRef)2 RequestContext (org.webpieces.ctx.api.RequestContext)2 XFuture (org.webpieces.util.futures.XFuture)2 HeaderType (com.webpieces.http2.api.dto.lowlevel.lib.HeaderType)1 Http2HeaderName (com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName)1 PushPromiseListener (com.webpieces.http2.api.streaming.PushPromiseListener)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Locale (java.util.Locale)1 Set (java.util.Set)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 HttpMethod (org.webpieces.ctx.api.HttpMethod)1