use of com.linkedin.restli.server.ParseqTraceDebugRequestHandler 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);
}
Aggregations