Search in sources :

Example 1 with HttpServer

use of com.linkedin.r2.transport.http.server.HttpServer in project rest.li by linkedin.

the class RestLiIntTestServer method createServer.

public static HttpServer createServer(final Engine engine, int port, boolean useAsyncServletApi, int asyncTimeOut, List<? extends Filter> filters, final FilterChain filterChain, final boolean forceUseRestServer) {
    RestLiConfig config = new RestLiConfig();
    config.addResourcePackageNames(RESOURCE_PACKAGE_NAMES);
    config.setServerNodeUri(URI.create("http://localhost:" + port));
    config.setDocumentationRequestHandler(new DefaultDocumentationRequestHandler());
    config.addDebugRequestHandlers(new ParseqTraceDebugRequestHandler());
    config.setFilters(filters);
    GroupMembershipMgr membershipMgr = new HashGroupMembershipMgr();
    GroupMgr groupMgr = new HashMapGroupMgr(membershipMgr);
    GroupsRestApplication app = new GroupsRestApplication(groupMgr, membershipMgr);
    SimpleBeanProvider beanProvider = new SimpleBeanProvider();
    beanProvider.add("GroupsRestApplication", app);
    //using InjectMockResourceFactory to keep examples spring-free
    ResourceFactory factory = new InjectMockResourceFactory(beanProvider);
    //Todo this will have to change further to accomodate streaming tests - this is temporary
    final TransportDispatcher dispatcher;
    if (forceUseRestServer) {
        dispatcher = new DelegatingTransportDispatcher(new RestLiServer(config, factory, engine));
    } else {
        final StreamRequestHandler streamRequestHandler = new RestLiServer(config, factory, engine);
        dispatcher = new TransportDispatcher() {

            @Override
            public void handleRestRequest(RestRequest req, Map<String, String> wireAttrs, RequestContext requestContext, TransportCallback<RestResponse> callback) {
                throw new UnsupportedOperationException("This server only accepts streaming");
            }

            @Override
            public void handleStreamRequest(StreamRequest req, Map<String, String> wireAttrs, RequestContext requestContext, TransportCallback<StreamResponse> callback) {
                try {
                    streamRequestHandler.handleRequest(req, requestContext, new TransportCallbackAdapter<>(callback));
                } catch (Exception e) {
                    final Exception ex = RestException.forError(RestStatus.INTERNAL_SERVER_ERROR, e);
                    callback.onResponse(TransportResponseImpl.<StreamResponse>error(ex));
                }
            }
        };
    }
    return new HttpServerFactory(filterChain).createServer(port, HttpServerFactory.DEFAULT_CONTEXT_PATH, HttpServerFactory.DEFAULT_THREAD_POOL_SIZE, dispatcher, useAsyncServletApi ? HttpJettyServer.ServletType.ASYNC_EVENT : HttpJettyServer.ServletType.RAP, asyncTimeOut, !forceUseRestServer);
}
Also used : HttpServerFactory(com.linkedin.r2.transport.http.server.HttpServerFactory) TransportCallbackAdapter(com.linkedin.r2.transport.common.bridge.server.TransportCallbackAdapter) DelegatingTransportDispatcher(com.linkedin.restli.server.DelegatingTransportDispatcher) DefaultDocumentationRequestHandler(com.linkedin.restli.docgen.DefaultDocumentationRequestHandler) DelegatingTransportDispatcher(com.linkedin.restli.server.DelegatingTransportDispatcher) TransportDispatcher(com.linkedin.r2.transport.common.bridge.server.TransportDispatcher) ParseqTraceDebugRequestHandler(com.linkedin.restli.server.ParseqTraceDebugRequestHandler) HashGroupMembershipMgr(com.linkedin.restli.examples.groups.server.impl.HashGroupMembershipMgr) GroupMembershipMgr(com.linkedin.restli.examples.groups.server.api.GroupMembershipMgr) HashMapGroupMgr(com.linkedin.restli.examples.groups.server.impl.HashMapGroupMgr) GroupsRestApplication(com.linkedin.restli.examples.groups.server.rest.impl.GroupsRestApplication) RequestContext(com.linkedin.r2.message.RequestContext) RestLiServer(com.linkedin.restli.server.RestLiServer) SimpleBeanProvider(com.linkedin.restli.server.mock.SimpleBeanProvider) RestResponse(com.linkedin.r2.message.rest.RestResponse) StreamResponse(com.linkedin.r2.message.stream.StreamResponse) InjectMockResourceFactory(com.linkedin.restli.server.mock.InjectMockResourceFactory) ResourceFactory(com.linkedin.restli.server.resources.ResourceFactory) RestException(com.linkedin.r2.message.rest.RestException) IOException(java.io.IOException) StreamRequest(com.linkedin.r2.message.stream.StreamRequest) HashMapGroupMgr(com.linkedin.restli.examples.groups.server.impl.HashMapGroupMgr) GroupMgr(com.linkedin.restli.examples.groups.server.api.GroupMgr) StreamRequestHandler(com.linkedin.r2.transport.common.StreamRequestHandler) RestRequest(com.linkedin.r2.message.rest.RestRequest) InjectMockResourceFactory(com.linkedin.restli.server.mock.InjectMockResourceFactory) HashGroupMembershipMgr(com.linkedin.restli.examples.groups.server.impl.HashGroupMembershipMgr) RestLiConfig(com.linkedin.restli.server.RestLiConfig)

Example 2 with HttpServer

use of com.linkedin.r2.transport.http.server.HttpServer in project rest.li by linkedin.

the class HttpServerFactory method createH2cServer.

public HttpServer createH2cServer(int port, String contextPath, int threadPoolSize, TransportDispatcher transportDispatcher, HttpJettyServer.ServletType servletType, int serverTimeout, boolean restOverStream) {
    final TransportDispatcher filterDispatcher = new FilterChainDispatcher(transportDispatcher, _filters);
    final HttpDispatcher dispatcher = HttpDispatcherFactory.create((filterDispatcher));
    return new H2cJettyServer(port, contextPath, threadPoolSize, dispatcher, servletType, serverTimeout, restOverStream);
}
Also used : FilterChainDispatcher(com.linkedin.r2.filter.transport.FilterChainDispatcher) TransportDispatcher(com.linkedin.r2.transport.common.bridge.server.TransportDispatcher)

Example 3 with HttpServer

use of com.linkedin.r2.transport.http.server.HttpServer in project rest.li by linkedin.

the class HttpServerFactory method createH2cServer.

public HttpServer createH2cServer(int port, String contextPath, int threadPoolSize, TransportDispatcher transportDispatcher, boolean restOverStream) {
    final TransportDispatcher filterDispatcher = new FilterChainDispatcher(transportDispatcher, _filters);
    final HttpDispatcher dispatcher = HttpDispatcherFactory.create((filterDispatcher));
    return new H2cJettyServer(port, contextPath, threadPoolSize, dispatcher, restOverStream);
}
Also used : FilterChainDispatcher(com.linkedin.r2.filter.transport.FilterChainDispatcher) TransportDispatcher(com.linkedin.r2.transport.common.bridge.server.TransportDispatcher)

Example 4 with HttpServer

use of com.linkedin.r2.transport.http.server.HttpServer in project rest.li by linkedin.

the class HttpServerFactory method createHttpsServer.

public HttpServer createHttpsServer(int port, int sslPort, String keyStore, String keyStorePassword, String contextPath, int threadPoolSize, TransportDispatcher transportDispatcher, HttpJettyServer.ServletType servletType, int asyncTimeOut, boolean restOverStream) {
    final TransportDispatcher filterDispatcher = new FilterChainDispatcher(transportDispatcher, _filters);
    final HttpDispatcher dispatcher = HttpDispatcherFactory.create((filterDispatcher));
    return new HttpsJettyServer(port, sslPort, keyStore, keyStorePassword, contextPath, threadPoolSize, dispatcher, servletType, asyncTimeOut, restOverStream);
}
Also used : FilterChainDispatcher(com.linkedin.r2.filter.transport.FilterChainDispatcher) TransportDispatcher(com.linkedin.r2.transport.common.bridge.server.TransportDispatcher)

Example 5 with HttpServer

use of com.linkedin.r2.transport.http.server.HttpServer in project rest.li by linkedin.

the class Https1NettyServerProvider method createServer.

@Override
public Server createServer(FilterChain filters, int port, TransportDispatcher dispatcher) throws Exception {
    Server httpServer = new Http1NettyServerProvider().createServer(filters, SslContextUtil.getHttpPortFromHttps(port));
    Server httpsServer = new HttpNettyServerBuilder().port(port).filters(filters).transportDispatcher(dispatcher).sslContext(SslContextUtil.getContext()).build();
    // start both an http and https server
    return new HttpAndHttpsServer(httpServer, httpsServer);
}
Also used : Server(com.linkedin.r2.transport.common.Server) RestEchoServer(com.linkedin.r2.sample.echo.rest.RestEchoServer) HttpNettyServerBuilder(com.linkedin.r2.transport.http.server.HttpNettyServerBuilder)

Aggregations

TransportDispatcher (com.linkedin.r2.transport.common.bridge.server.TransportDispatcher)11 FilterChainDispatcher (com.linkedin.r2.filter.transport.FilterChainDispatcher)7 HttpServer (com.linkedin.r2.transport.http.server.HttpServer)6 HttpServerFactory (com.linkedin.r2.transport.http.server.HttpServerFactory)4 DelegatingTransportDispatcher (com.linkedin.restli.server.DelegatingTransportDispatcher)4 RestLiServer (com.linkedin.restli.server.RestLiServer)4 InjectMockResourceFactory (com.linkedin.restli.server.mock.InjectMockResourceFactory)4 ResourceFactory (com.linkedin.restli.server.resources.ResourceFactory)4 DefaultDocumentationRequestHandler (com.linkedin.restli.docgen.DefaultDocumentationRequestHandler)3 SimpleBeanProvider (com.linkedin.restli.server.mock.SimpleBeanProvider)3 Engine (com.linkedin.parseq.Engine)2 EngineBuilder (com.linkedin.parseq.EngineBuilder)2 GroupMembershipMgr (com.linkedin.restli.examples.groups.server.api.GroupMembershipMgr)2 GroupMgr (com.linkedin.restli.examples.groups.server.api.GroupMgr)2 HashGroupMembershipMgr (com.linkedin.restli.examples.groups.server.impl.HashGroupMembershipMgr)2 HashMapGroupMgr (com.linkedin.restli.examples.groups.server.impl.HashMapGroupMgr)2 GroupsRestApplication (com.linkedin.restli.examples.groups.server.rest.impl.GroupsRestApplication)2 ParseqTraceDebugRequestHandler (com.linkedin.restli.server.ParseqTraceDebugRequestHandler)2 RestLiConfig (com.linkedin.restli.server.RestLiConfig)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2