Search in sources :

Example 1 with ErrorResponseBuilder

use of com.linkedin.restli.internal.server.response.ErrorResponseBuilder in project rest.li by linkedin.

the class TestCustomMethodAdapterProvider method initClass.

@BeforeClass
public void initClass() throws Exception {
    RestLiConfig config = new RestLiConfig();
    config.setMethodAdapterProvider(new DefaultMethodAdapterProvider(new ErrorResponseBuilder(ErrorResponseFormat.MESSAGE_AND_SERVICECODE)) {

        @Override
        public RestLiArgumentBuilder getArgumentBuilder(ResourceMethod resourceMethod) {
            // Override the behavior of the CREATE argument builder
            if (resourceMethod == ResourceMethod.CREATE) {
                return new CreateArgumentBuilder() {

                    @Override
                    public RestLiRequestData extractRequestData(RoutingResult routingResult, DataMap dataMap) {
                        // Always use the FRIENDLY record regardless of the actual data
                        return new RestLiRequestDataImpl.Builder().entity(FRIENDLY).build();
                    }
                };
            } else {
                return super.getArgumentBuilder(resourceMethod);
            }
        }
    });
    super.init(false, config);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) DefaultMethodAdapterProvider(com.linkedin.restli.internal.server.methods.DefaultMethodAdapterProvider) CreateArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.CreateArgumentBuilder) ErrorResponseBuilder(com.linkedin.restli.internal.server.response.ErrorResponseBuilder) RestLiRequestDataImpl(com.linkedin.restli.server.RestLiRequestDataImpl) RestLiArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.RestLiArgumentBuilder) RestLiConfig(com.linkedin.restli.server.RestLiConfig) ResourceMethod(com.linkedin.restli.common.ResourceMethod) DataMap(com.linkedin.data.DataMap) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with ErrorResponseBuilder

use of com.linkedin.restli.internal.server.response.ErrorResponseBuilder in project rest.li by linkedin.

the class TestRestLiMethodInvocation method setUp.

@BeforeTest
protected void setUp() {
    _scheduler = Executors.newSingleThreadScheduledExecutor();
    _engine = new EngineBuilder().setTaskExecutor(_scheduler).setTimerScheduler(_scheduler).build();
    _resourceFactory = new EasyMockResourceFactory();
    _errorResponseBuilder = new ErrorResponseBuilder();
    _methodAdapterProvider = new DefaultMethodAdapterProvider(_errorResponseBuilder);
    // Add filters to the invoker.
    _invoker = new RestLiMethodInvoker(_resourceFactory, _engine, ErrorResponseBuilder.DEFAULT_INTERNAL_ERROR_MESSAGE);
}
Also used : DefaultMethodAdapterProvider(com.linkedin.restli.internal.server.methods.DefaultMethodAdapterProvider) RestLiMethodInvoker(com.linkedin.restli.internal.server.RestLiMethodInvoker) ErrorResponseBuilder(com.linkedin.restli.internal.server.response.ErrorResponseBuilder) EngineBuilder(com.linkedin.parseq.EngineBuilder) BeforeTest(org.testng.annotations.BeforeTest)

Example 3 with ErrorResponseBuilder

use of com.linkedin.restli.internal.server.response.ErrorResponseBuilder in project rest.li by linkedin.

the class TestMultiplexedRequestHandlerImpl method createMultiplexer.

private static MultiplexedRequestHandlerImpl createMultiplexer(RestRequestHandler requestHandler, MultiplexerSingletonFilter multiplexerSingletonFilter, Set<String> individualRequestHeaderWhitelist, int maxRequestCount, MultiplexerRunMode multiplexerRunMode) {
    ExecutorService taskScheduler = Executors.newFixedThreadPool(1);
    ScheduledExecutorService timerScheduler = Executors.newSingleThreadScheduledExecutor();
    Engine engine = new EngineBuilder().setTaskExecutor(taskScheduler).setTimerScheduler(timerScheduler).build();
    return new MultiplexedRequestHandlerImpl(requestHandler, engine, maxRequestCount, individualRequestHeaderWhitelist, multiplexerSingletonFilter, multiplexerRunMode, new ErrorResponseBuilder());
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ErrorResponseBuilder(com.linkedin.restli.internal.server.response.ErrorResponseBuilder) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) EngineBuilder(com.linkedin.parseq.EngineBuilder) Engine(com.linkedin.parseq.Engine)

Aggregations

ErrorResponseBuilder (com.linkedin.restli.internal.server.response.ErrorResponseBuilder)3 EngineBuilder (com.linkedin.parseq.EngineBuilder)2 DefaultMethodAdapterProvider (com.linkedin.restli.internal.server.methods.DefaultMethodAdapterProvider)2 DataMap (com.linkedin.data.DataMap)1 Engine (com.linkedin.parseq.Engine)1 ResourceMethod (com.linkedin.restli.common.ResourceMethod)1 RestLiMethodInvoker (com.linkedin.restli.internal.server.RestLiMethodInvoker)1 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)1 CreateArgumentBuilder (com.linkedin.restli.internal.server.methods.arguments.CreateArgumentBuilder)1 RestLiArgumentBuilder (com.linkedin.restli.internal.server.methods.arguments.RestLiArgumentBuilder)1 RestLiConfig (com.linkedin.restli.server.RestLiConfig)1 RestLiRequestData (com.linkedin.restli.server.RestLiRequestData)1 RestLiRequestDataImpl (com.linkedin.restli.server.RestLiRequestDataImpl)1 ExecutorService (java.util.concurrent.ExecutorService)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 BeforeClass (org.testng.annotations.BeforeClass)1 BeforeTest (org.testng.annotations.BeforeTest)1