use of com.linkedin.restli.server.resources.PrototypeResourceFactory in project rest.li by linkedin.
the class RestliServlet method buildR2ServletFromServletParams.
private AbstractR2Servlet buildR2ServletFromServletParams(ServletConfig servletConfig) {
ResourceFactory resourceFactory = new PrototypeResourceFactory();
RestLiConfig config = new RestLiConfig();
config.setResourcePackageNamesSet(getResourcePackageSet(servletConfig));
final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(getParseqThreadPoolSize(servletConfig));
Engine engine = new EngineBuilder().setTaskExecutor(scheduler).setTimerScheduler(scheduler).build();
DelegatingTransportDispatcher dispatcher = new DelegatingTransportDispatcher(new RestLiServer(config, resourceFactory, engine));
boolean useAsync = getUseAsync(servletConfig);
long asyncTimeOut = getAsyncTimeout(servletConfig);
if (useAsync && servletConfig.getServletContext().getMajorVersion() < 3) {
throw new IllegalArgumentException("This servlet is configured with useAsync=true, but the current servlet " + "context does not support the required Servlet API 3.0.");
}
if (!useAsync) {
log.info("Initializing Rest.li with a thread based request handling. Set useAsync=true on a Servlet API 3.0 container to enable Rest.li's async servlet.");
return new RAPServlet(dispatcher);
} else {
log.info("Initializing Rest.li with an async request handling enabled.");
return new AsyncR2Servlet(dispatcher, asyncTimeOut);
}
}
use of com.linkedin.restli.server.resources.PrototypeResourceFactory in project rest.li by linkedin.
the class TestCharacterEncoding method testQueryParamValueEncoding.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "protocolVersions")
public void testQueryParamValueEncoding(ProtocolVersion protocolVersion) {
RestLiConfig config = new RestLiConfig();
config.setResourcePackageNames(QueryParamMockCollection.class.getPackage().getName());
RestLiServer server = new RestLiServer(config, new PrototypeResourceFactory(), null);
for (char c = 0; c < 256; ++c) {
final String testValue = String.valueOf(c);
GetRequest<EmptyRecord> req = new GetRequestBuilder<String, EmptyRecord>(QueryParamMockCollection.RESOURCE_NAME, EmptyRecord.class, new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), Collections.<String, DynamicRecordMetadata>emptyMap(), Collections.<String, DynamicRecordMetadata>emptyMap(), String.class, null, null, EmptyRecord.class, Collections.<String, CompoundKey.TypeInfo>emptyMap()), RestliRequestOptions.DEFAULT_OPTIONS).id("dummy").setParam(QueryParamMockCollection.VALUE_KEY, testValue).build();
RestRequest restRequest = new RestRequestBuilder(RestliUriBuilderUtil.createUriBuilder(req, protocolVersion).build()).setMethod(req.getMethod().getHttpMethod().toString()).build();
// N.B. since QueryParamMockCollection is implemented using the synchronous rest.li interface,
// RestLiServer.handleRequest() will invoke the application resource *and* the callback
// *synchronously*, ensuring that the all instances of the callback are invoked before the
// loop terminates.
server.handleRequest(restRequest, new RequestContext(), new Callback<RestResponse>() {
@Override
public void onError(Throwable e) {
Assert.fail();
}
@Override
public void onSuccess(RestResponse result) {
try {
DataMap data = new JacksonDataCodec().readMap(result.getEntity().asInputStream());
Assert.assertEquals(data.get(QueryParamMockCollection.VALUE_KEY), testValue);
Assert.assertEquals(QueryParamMockCollection._lastQueryParamValue, testValue);
} catch (IOException e) {
Assert.fail();
}
}
});
}
}
Aggregations