Search in sources :

Example 11 with HttpServerFactory

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

the class TestHttp2Server method doSetup.

@Override
protected void doSetup() throws IOException {
    final TransportDispatcher dispatcher = new TransportDispatcherBuilder(_restOverStream).addRestHandler(URI.create("/error"), new ErrorHandler()).addRestHandler(URI.create("/headerEcho"), new HeaderEchoHandler()).addRestHandler(URI.create("/foobar"), new FoobarHandler(_scheduler)).build();
    _server = new HttpServerFactory(_servletType).createH2cServer(_port, dispatcher, _restOverStream);
    _server.start();
}
Also used : HttpServerFactory(com.linkedin.r2.transport.http.server.HttpServerFactory) TransportDispatcher(com.linkedin.r2.transport.common.bridge.server.TransportDispatcher) TransportDispatcherBuilder(com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder)

Example 12 with HttpServerFactory

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

the class TestHttpServer method doSetup.

@Override
protected void doSetup() throws IOException {
    final TransportDispatcher dispatcher = new TransportDispatcherBuilder(_restOverStream).addRestHandler(URI.create("/error"), new ErrorHandler()).addRestHandler(URI.create("/headerEcho"), new HeaderEchoHandler()).addRestHandler(URI.create("/foobar"), new FoobarHandler(_scheduler)).build();
    _server = new HttpServerFactory(_servletType).createServer(_port, dispatcher, _restOverStream);
    _server.start();
}
Also used : HttpServerFactory(com.linkedin.r2.transport.http.server.HttpServerFactory) TransportDispatcher(com.linkedin.r2.transport.common.bridge.server.TransportDispatcher) TransportDispatcherBuilder(com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder)

Example 13 with HttpServerFactory

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

the class TestMIMEChainingMultipleSources method setup.

@BeforeMethod
public void setup() throws IOException {
    _latch = new CountDownLatch(2);
    _clientFactory = new HttpClientFactory();
    _client = new TransportClientAdapter(_clientFactory.getClient(Collections.<String, String>emptyMap()));
    _server_A_client = new TransportClientAdapter(_clientFactory.getClient(Collections.<String, String>emptyMap()));
    final HttpServerFactory httpServerFactory = new HttpServerFactory();
    final ServerARequestHandler serverARequestHandler = new ServerARequestHandler();
    final TransportDispatcher serverATransportDispatcher = new TransportDispatcherBuilder().addStreamHandler(SERVER_A_URI, serverARequestHandler).build();
    final ServerBRequestHandler serverBRequestHandler = new ServerBRequestHandler();
    final TransportDispatcher serverBTransportDispatcher = new TransportDispatcherBuilder().addStreamHandler(SERVER_B_URI, serverBRequestHandler).build();
    _serverA = httpServerFactory.createServer(PORT_SERVER_A, serverATransportDispatcher, true);
    _serverB = httpServerFactory.createServer(PORT_SERVER_B, serverBTransportDispatcher, true);
    _serverA.start();
    _serverB.start();
}
Also used : HttpServerFactory(com.linkedin.r2.transport.http.server.HttpServerFactory) TransportClientAdapter(com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter) TransportDispatcher(com.linkedin.r2.transport.common.bridge.server.TransportDispatcher) CountDownLatch(java.util.concurrent.CountDownLatch) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory) TransportDispatcherBuilder(com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 14 with HttpServerFactory

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

the class RestLiExampleBasicServer method createServer.

public static HttpServer createServer() {
    // create Rest.li resource class information and initialize documentation generator
    // only the resource classes in the specified package names are visible for public
    final RestLiConfig config = new RestLiConfig();
    config.addResourcePackageNames("com.linkedin.restli.example.impl");
    config.setServerNodeUri(URI.create(getServerUrl()));
    config.setDocumentationRequestHandler(new DefaultDocumentationRequestHandler());
    // Create an instance of the Example Filter and add it to the config.
    RestLiExampleFilter filter = new RestLiExampleFilter();
    config.addFilter(filter);
    // demonstrate dynamic dependency injection
    final PhotoDatabase photoDb = new PhotoDatabaseImpl(10);
    final SimpleBeanProvider beanProvider = new SimpleBeanProvider();
    beanProvider.add("photoDb", photoDb);
    beanProvider.add("albumDb", new AlbumDatabaseImpl(10));
    beanProvider.add("albumEntryDb", new AlbumEntryDatabaseImpl(photoDb, 3));
    // using InjectMockResourceFactory to keep examples spring-free
    final ResourceFactory factory = new InjectMockResourceFactory(beanProvider);
    final TransportDispatcher dispatcher = new DelegatingTransportDispatcher(new RestLiServer(config, factory));
    return new HttpServerFactory(FilterChains.empty()).createServer(SERVER_PORT, dispatcher);
}
Also used : HttpServerFactory(com.linkedin.r2.transport.http.server.HttpServerFactory) RestLiServer(com.linkedin.restli.server.RestLiServer) SimpleBeanProvider(com.linkedin.restli.server.mock.SimpleBeanProvider) DelegatingTransportDispatcher(com.linkedin.restli.server.DelegatingTransportDispatcher) DefaultDocumentationRequestHandler(com.linkedin.restli.docgen.DefaultDocumentationRequestHandler) ResourceFactory(com.linkedin.restli.server.resources.ResourceFactory) InjectMockResourceFactory(com.linkedin.restli.server.mock.InjectMockResourceFactory) DelegatingTransportDispatcher(com.linkedin.restli.server.DelegatingTransportDispatcher) TransportDispatcher(com.linkedin.r2.transport.common.bridge.server.TransportDispatcher) PhotoDatabase(com.linkedin.restli.example.impl.PhotoDatabase) AlbumEntryDatabaseImpl(com.linkedin.restli.example.impl.AlbumEntryDatabaseImpl) AlbumDatabaseImpl(com.linkedin.restli.example.impl.AlbumDatabaseImpl) PhotoDatabaseImpl(com.linkedin.restli.example.impl.PhotoDatabaseImpl) InjectMockResourceFactory(com.linkedin.restli.server.mock.InjectMockResourceFactory) RestLiConfig(com.linkedin.restli.server.RestLiConfig)

Aggregations

HttpServerFactory (com.linkedin.r2.transport.http.server.HttpServerFactory)14 TransportDispatcher (com.linkedin.r2.transport.common.bridge.server.TransportDispatcher)13 TransportClientAdapter (com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter)8 HttpClientFactory (com.linkedin.r2.transport.http.client.HttpClientFactory)7 TransportDispatcherBuilder (com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder)6 BeforeClass (org.testng.annotations.BeforeClass)6 RequestContext (com.linkedin.r2.message.RequestContext)5 RestRequest (com.linkedin.r2.message.rest.RestRequest)5 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)5 HashMap (java.util.HashMap)5 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)4 StreamRequestHandler (com.linkedin.r2.transport.common.StreamRequestHandler)4 TransportCallback (com.linkedin.r2.transport.common.bridge.common.TransportCallback)4 Map (java.util.Map)4 ByteString (com.linkedin.data.ByteString)3 FilterChain (com.linkedin.r2.filter.FilterChain)3 RestResponse (com.linkedin.r2.message.rest.RestResponse)3 DrainReader (com.linkedin.r2.message.stream.entitystream.DrainReader)3 DelegatingTransportDispatcher (com.linkedin.restli.server.DelegatingTransportDispatcher)3 RestLiServer (com.linkedin.restli.server.RestLiServer)3