use of com.linkedin.restli.server.RestLiServer 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();
}
}
});
}
}
use of com.linkedin.restli.server.RestLiServer in project rest.li by linkedin.
the class TestMultiplexerRunMode method testMultiplexedAsyncGetRequest.
@Test(dataProvider = "multiplexerConfigurations")
public void testMultiplexedAsyncGetRequest(MultiplexerRunMode multiplexerRunMode) throws URISyntaxException, IOException, InterruptedException {
RestLiConfig config = new RestLiConfig();
config.addResourcePackageNames("com.linkedin.restli.server.multiplexer.resources");
config.setMultiplexerRunMode(multiplexerRunMode);
CountingEngine engine = engine();
RestLiServer server = new RestLiServer(config, resourceFactory(), engine);
IndividualRequest r0 = individualRequest("/users/0", null, Collections.<String, IndividualRequest>emptyMap());
IndividualRequest r1 = individualRequest("/users/1", null, Collections.<String, IndividualRequest>emptyMap());
IndividualRequest r2 = individualRequest("/users/2", null, ImmutableMap.of("0", r0, "1", r1));
// request is seq(par(r0, r1), r2)
RestRequest request = muxRestRequest(ImmutableMap.of("2", r2));
CountDownLatch latch = new CountDownLatch(1);
server.handleRequest(request, new RequestContext(), callback(latch));
assertTrue(latch.await(5, TimeUnit.SECONDS));
if (multiplexerRunMode == MultiplexerRunMode.SINGLE_PLAN) {
assertEquals(engine.plansStarted(), 1);
} else {
// in MULTIPLE_PLANS mode: 1 task for multiplexed request itself + 3 individual tasks r0, r1, r2
assertEquals(engine.plansStarted(), 1 + 3);
}
}
use of com.linkedin.restli.server.RestLiServer 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);
}
Aggregations