use of com.linkedin.restli.server.resources.BaseResource in project incubator-gobblin by apache.
the class FlowStatusTest method setUp.
@BeforeClass
public void setUp() throws Exception {
ConfigBuilder configBuilder = ConfigBuilder.create();
JobStatusRetriever jobStatusRetriever = new TestJobStatusRetriever();
final FlowStatusGenerator flowStatusGenerator = FlowStatusGenerator.builder().jobStatusRetriever(jobStatusRetriever).build();
Injector injector = Guice.createInjector(new Module() {
@Override
public void configure(Binder binder) {
binder.bind(FlowStatusGenerator.class).annotatedWith(Names.named(FlowStatusResource.FLOW_STATUS_GENERATOR_INJECT_NAME)).toInstance(flowStatusGenerator);
}
});
_server = EmbeddedRestliServer.builder().resources(Lists.<Class<? extends BaseResource>>newArrayList(FlowStatusResource.class)).injector(injector).build();
_server.startAsync();
_server.awaitRunning();
_client = new FlowStatusClient(String.format("http://localhost:%s/", _server.getPort()));
messageJoiner = Joiner.on(FlowStatusResource.MESSAGE_SEPARATOR);
}
use of com.linkedin.restli.server.resources.BaseResource in project rest.li by linkedin.
the class TestRestLiMethodInvocation method getMockResource.
private <R> R getMockResource(Class<R> resourceClass) {
R resource = _resourceFactory.getMock(resourceClass);
EasyMock.reset(resource);
EasyMock.makeThreadSafe(resource, true);
if (BaseResource.class.isAssignableFrom(resourceClass)) {
BaseResource baseResource = (BaseResource) resource;
baseResource.setContext((ResourceContext) EasyMock.anyObject());
EasyMock.expectLastCall().once();
}
return resource;
}
use of com.linkedin.restli.server.resources.BaseResource in project rest.li by linkedin.
the class RestLiMethodInvoker method invoke.
/**
* Invokes the method with the specified callback and arguments built from the request.
*
* @param requestData
* {@link RestLiRequestData}
* @param invocableMethod
* {@link RoutingResult}
* @param restLiArgumentBuilder
* {@link RestLiArgumentBuilder}
* @param callback
* {@link RequestExecutionCallback}
* @param requestExecutionReportBuilder
* {@link RequestExecutionReportBuilder}
*/
public void invoke(final RestLiRequestData requestData, final RoutingResult invocableMethod, final RestLiArgumentBuilder restLiArgumentBuilder, final RequestExecutionCallback<Object> callback, final RequestExecutionReportBuilder requestExecutionReportBuilder) {
try {
ResourceMethodDescriptor resourceMethodDescriptor = invocableMethod.getResourceMethod();
Object resource = _resourceFactory.create(resourceMethodDescriptor.getResourceModel().getResourceClass());
//Acquire a handle on the ResourceContext when setting it in order to obtain any response attachments that need to
//be streamed back.
final ServerResourceContext resourceContext;
resourceContext = (ServerResourceContext) invocableMethod.getContext();
if (BaseResource.class.isAssignableFrom(resource.getClass())) {
((BaseResource) resource).setContext(resourceContext);
}
Object[] args = restLiArgumentBuilder.buildArguments(requestData, invocableMethod);
// Now invoke the resource implementation.
doInvoke(resourceMethodDescriptor, callback, requestExecutionReportBuilder, resource, resourceContext, args);
} catch (Exception e) {
callback.onError(e, requestExecutionReportBuilder == null ? null : requestExecutionReportBuilder.build(), ((ServerResourceContext) invocableMethod.getContext()).getRequestAttachmentReader(), //Technically response attachments
invocableMethod.getContext().getResponseAttachments());
//could exist here. One possible way is if there is a runtime exception during response
//construction after the rest.li response filter chain has been completed.
}
}
use of com.linkedin.restli.server.resources.BaseResource in project incubator-gobblin by apache.
the class FlowConfigTest method setUp.
@BeforeClass
public void setUp() throws Exception {
ConfigBuilder configBuilder = ConfigBuilder.create();
_testDirectory = Files.createTempDir();
configBuilder.addPrimitive(ConfigurationKeys.JOB_CONFIG_FILE_DIR_KEY, _testDirectory.getAbsolutePath()).addPrimitive(ConfigurationKeys.SPECSTORE_FS_DIR_KEY, TEST_SPEC_STORE_DIR);
cleanUpDir(TEST_SPEC_STORE_DIR);
Config config = configBuilder.build();
final FlowCatalog flowCatalog = new FlowCatalog(config);
flowCatalog.startAsync();
flowCatalog.awaitRunning();
Injector injector = Guice.createInjector(new Module() {
@Override
public void configure(Binder binder) {
binder.bind(FlowCatalog.class).annotatedWith(Names.named("flowCatalog")).toInstance(flowCatalog);
// indicate that we are in unit testing since the resource is being blocked until flow catalog changes have
// been made
binder.bindConstant().annotatedWith(Names.named("readyToUse")).to(Boolean.TRUE);
}
});
_server = EmbeddedRestliServer.builder().resources(Lists.<Class<? extends BaseResource>>newArrayList(FlowConfigsResource.class)).injector(injector).build();
_server.startAsync();
_server.awaitRunning();
_client = new FlowConfigClient(String.format("http://localhost:%s/", _server.getPort()));
}
use of com.linkedin.restli.server.resources.BaseResource in project incubator-gobblin by apache.
the class RestliServiceBasedLimiterTest method createAndStartServer.
private RestliServer createAndStartServer(Config baseConfig, int port) {
ThrottlingGuiceServletConfig guiceServletConfig = new ThrottlingGuiceServletConfig();
guiceServletConfig.initialize(baseConfig.withFallback(ConfigFactory.parseMap(ImmutableMap.of(ThrottlingGuiceServletConfig.LISTENING_PORT, Integer.toString(port)))));
Injector injector = guiceServletConfig.getInjector();
EmbeddedRestliServer server = EmbeddedRestliServer.builder().resources(Lists.<Class<? extends BaseResource>>newArrayList(LimiterServerResource.class)).injector(injector).port(port).build();
server.startAsync();
server.awaitRunning();
return new RestliServer(server, guiceServletConfig);
}
Aggregations