Search in sources :

Example 1 with RouterResponseHandler

use of org.webpieces.router.api.RouterResponseHandler in project webpieces by deanhiller.

the class WebpiecesStreamHandle method incomingRequest.

@Override
public StreamRef incomingRequest(Http2Request headers, ResponseStream stream) {
    RouterResponseHandler handler = new RouterResponseHandlerImpl(stream);
    StreamRef ref = routingService.incomingRequest(headers, handler);
    return ref;
}
Also used : StreamRef(com.webpieces.http2.api.streaming.StreamRef) RouterResponseHandler(org.webpieces.router.api.RouterResponseHandler)

Example 2 with RouterResponseHandler

use of org.webpieces.router.api.RouterResponseHandler in project webpieces by deanhiller.

the class RouterServiceImpl method incomingRequest.

@Override
public StreamRef incomingRequest(Http2Request req, RouterResponseHandler handler) {
    // ******************************************************************************************
    // DO NOT ADD CODE HERE OR ABOVE THIS METHOD in RouterService.  This is our CATCH-ALL point so
    // ANY code above that is not protected from our catch and respond to clients
    // ******************************************************************************************
    String txId = generate();
    // I do NOT like doing Guice creation on the request path(Dagger creation would probably be ok) BUT this
    // is very worth it AND customers can swap out these critical classes if they need to quickly temporarily fix a bug while
    // we work on the bug.  We can easily give customers bug fixes like add binder.bind(ClassWithBug.class).to(BugFixCode.class)
    ProxyStreamHandle proxyHandler = proxyProvider.get();
    proxyHandler.init(handler, req);
    MDC.put("txId", txId);
    // top level handler...
    try {
        RouterStreamRef streamRef = incomingRequestProtected(req, proxyHandler);
        XFuture<StreamWriter> writer = streamRef.getWriter().thenApply(w -> new TxStreamWriter(txId, w));
        XFuture<StreamWriter> finalWriter = writer.handle((r, t) -> {
            if (t == null)
                return XFuture.completedFuture(r);
            XFuture<StreamWriter> fut = proxyHandler.topLevelFailure(req, t);
            return fut;
        }).thenCompose(Function.identity());
        return new RouterStreamRef("routerSevcTop", finalWriter, streamRef);
    } finally {
        MDC.remove("txId");
    }
}
Also used : RouterCookie(org.webpieces.ctx.api.RouterCookie) Provider(javax.inject.Provider) UriInfo(org.webpieces.ctx.api.UriInfo) LoggerFactory(org.slf4j.LoggerFactory) RouterConfig(org.webpieces.router.api.RouterConfig) HashMap(java.util.HashMap) Random(java.util.Random) Singleton(javax.inject.Singleton) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Function(java.util.function.Function) ContentType(org.webpieces.ctx.api.ContentType) ArrayList(java.util.ArrayList) ParsedContentType(com.webpieces.http2.api.subparsers.ParsedContentType) HashSet(java.util.HashSet) Inject(javax.inject.Inject) RouterRequest(org.webpieces.ctx.api.RouterRequest) Locale(java.util.Locale) AcceptType(com.webpieces.http2.api.subparsers.AcceptType) Map(java.util.Map) Logger(org.slf4j.Logger) RouterStreamHandle(org.webpieces.router.api.RouterStreamHandle) UrlEncodedParser(org.webpieces.util.urlparse.UrlEncodedParser) Set(java.util.Set) RouterService(org.webpieces.router.api.RouterService) Injector(com.google.inject.Injector) ProxyStreamHandle(org.webpieces.router.impl.proxyout.ProxyStreamHandle) List(java.util.List) HttpMethod(org.webpieces.ctx.api.HttpMethod) XFuture(org.webpieces.util.futures.XFuture) AcceptMediaType(org.webpieces.ctx.api.AcceptMediaType) StreamRef(com.webpieces.http2.api.streaming.StreamRef) MDC(org.slf4j.MDC) FileMeta(org.webpieces.router.impl.compression.FileMeta) RouterResponseHandler(org.webpieces.router.api.RouterResponseHandler) Entry(java.util.Map.Entry) ObjectStringConverter(org.webpieces.router.api.extensions.ObjectStringConverter) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) HeaderPriorityParser(com.webpieces.http2.api.subparsers.HeaderPriorityParser) Http2HeaderName(com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName) HeaderPriorityParserImpl(com.webpieces.http2.impl.subparsers.HeaderPriorityParserImpl) Arguments(org.webpieces.util.cmdline2.Arguments) RouterStreamRef(org.webpieces.router.impl.routeinvoker.RouterStreamRef) Http2Headers(com.webpieces.http2.api.dto.highlevel.Http2Headers) XFuture(org.webpieces.util.futures.XFuture) ProxyStreamHandle(org.webpieces.router.impl.proxyout.ProxyStreamHandle) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) RouterStreamRef(org.webpieces.router.impl.routeinvoker.RouterStreamRef)

Aggregations

StreamRef (com.webpieces.http2.api.streaming.StreamRef)2 RouterResponseHandler (org.webpieces.router.api.RouterResponseHandler)2 Injector (com.google.inject.Injector)1 Http2Headers (com.webpieces.http2.api.dto.highlevel.Http2Headers)1 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)1 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)1 Http2HeaderName (com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName)1 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)1 AcceptType (com.webpieces.http2.api.subparsers.AcceptType)1 HeaderPriorityParser (com.webpieces.http2.api.subparsers.HeaderPriorityParser)1 ParsedContentType (com.webpieces.http2.api.subparsers.ParsedContentType)1 HeaderPriorityParserImpl (com.webpieces.http2.impl.subparsers.HeaderPriorityParserImpl)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Random (java.util.Random)1