Search in sources :

Example 26 with SimpleRegistry

use of org.apache.camel.impl.SimpleRegistry in project opennms by OpenNMS.

the class EchoRpcIT method checkDefinedTimeout.

@Test(timeout = 60000)
public void checkDefinedTimeout() throws Exception {
    System.getProperties().setProperty(CamelRpcClientPreProcessor.CAMEL_JMS_REQUEST_TIMEOUT_PROPERTY, "12345");
    SimpleRegistry registry = new SimpleRegistry();
    CamelContext context = new DefaultCamelContext(registry);
    context.addComponent("queuingservice", queuingservice);
    CamelRpcRequest<EchoRequest, EchoResponse> wrapper = new CamelRpcRequest<>(new EchoRpcModule(), new EchoRequest());
    CamelRpcClientPreProcessor camelRpcClientPreProcessor = new CamelRpcClientPreProcessor();
    DefaultExchange defaultExchange = new DefaultExchange(context);
    defaultExchange.getIn().setBody(wrapper);
    camelRpcClientPreProcessor.process(defaultExchange);
    context.stop();
    assertEquals(12345L, defaultExchange.getIn().getHeader(CamelRpcConstants.CAMEL_JMS_REQUEST_TIMEOUT_HEADER));
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) EchoResponse(org.opennms.core.rpc.echo.EchoResponse) DefaultExchange(org.apache.camel.impl.DefaultExchange) EchoRpcModule(org.opennms.core.rpc.echo.EchoRpcModule) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 27 with SimpleRegistry

use of org.apache.camel.impl.SimpleRegistry in project opennms by OpenNMS.

the class EchoRpcIT method futureFailsWithRemoteExecutionExceptionWhenExecutingRemotely.

/**
     * Verifies that the future fails with a {@code RemoteExecutionException} when
     * if an error occurs when executing remotely.
     */
@Test(timeout = 60000)
public void futureFailsWithRemoteExecutionExceptionWhenExecutingRemotely() throws Exception {
    assertNotEquals(REMOTE_LOCATION_NAME, identity.getLocation());
    EchoRpcModule echoRpcModule = new EchoRpcModule();
    SimpleRegistry registry = new SimpleRegistry();
    CamelContext context = new DefaultCamelContext(registry);
    context.addComponent("queuingservice", queuingservice);
    context.start();
    CamelRpcServerRouteManager routeManager = new CamelRpcServerRouteManager(context, new MockMinionIdentity(REMOTE_LOCATION_NAME));
    routeManager.bind(echoRpcModule);
    EchoRequest request = new EchoRequest("Oops!");
    request.shouldThrow(true);
    request.setLocation(REMOTE_LOCATION_NAME);
    try {
        echoClient.execute(request).get();
        fail();
    } catch (ExecutionException e) {
        assertTrue(e.getCause().getMessage(), e.getCause().getMessage().contains("Oops!"));
        assertEquals(RemoteExecutionException.class, e.getCause().getClass());
    }
    routeManager.unbind(echoRpcModule);
    context.stop();
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) RemoteExecutionException(org.opennms.core.rpc.api.RemoteExecutionException) EchoRpcModule(org.opennms.core.rpc.echo.EchoRpcModule) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) RemoteExecutionException(org.opennms.core.rpc.api.RemoteExecutionException) ExecutionException(java.util.concurrent.ExecutionException) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 28 with SimpleRegistry

use of org.apache.camel.impl.SimpleRegistry in project opennms by OpenNMS.

the class EchoRpcIT method checkUndefinedTimeout.

@Test(timeout = 60000)
public void checkUndefinedTimeout() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    CamelContext context = new DefaultCamelContext(registry);
    context.addComponent("queuingservice", queuingservice);
    CamelRpcRequest<EchoRequest, EchoResponse> wrapper = new CamelRpcRequest<>(new EchoRpcModule(), new EchoRequest());
    CamelRpcClientPreProcessor camelRpcClientPreProcessor = new CamelRpcClientPreProcessor();
    DefaultExchange defaultExchange = new DefaultExchange(context);
    defaultExchange.getIn().setBody(wrapper);
    camelRpcClientPreProcessor.process(defaultExchange);
    context.stop();
    assertEquals(CamelRpcClientPreProcessor.CAMEL_JMS_REQUEST_TIMEOUT_DEFAULT, defaultExchange.getIn().getHeader(CamelRpcConstants.CAMEL_JMS_REQUEST_TIMEOUT_HEADER));
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) EchoResponse(org.opennms.core.rpc.echo.EchoResponse) DefaultExchange(org.apache.camel.impl.DefaultExchange) EchoRpcModule(org.opennms.core.rpc.echo.EchoRpcModule) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) EchoRequest(org.opennms.core.rpc.echo.EchoRequest) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 29 with SimpleRegistry

use of org.apache.camel.impl.SimpleRegistry in project opennms by OpenNMS.

the class NCSPathProviderTest method setUp.

@Before
public void setUp() throws Exception {
    NCSPathRouteUtil pathUtil = new NCSPathRouteUtil(new MockNCSComponentRepository(), new MockNodeDao());
    SimpleRegistry registry = new SimpleRegistry();
    registry.put("pathProviderUtil", pathUtil);
    CamelContext camel = new DefaultCamelContext(registry);
    camel.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").setHeader(Exchange.HTTP_URI, simple("http://localhost:10346/ncs-provider/api/space/nsas/service-management/services/884779")).to("http://dummyhost").beanRef("pathProviderUtil", "getServiceName").setHeader(Exchange.HTTP_URI, simple("http://localhost:10346/ncs-provider/api/space/nsas/eline-ptp/service-management/services/884779/servicepath?deviceA=${header.deviceA}&deviceZ=${header.deviceZ}")).to("http://dummyhost").beanRef("pathProviderUtil", "createPath");
        }
    });
    camel.start();
    m_ncsPathService = new NCSPathProviderService(camel);
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) NCSPathRouteUtil(org.opennms.features.topology.plugins.ncs.support.NCSPathRouteUtil) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Before(org.junit.Before)

Example 30 with SimpleRegistry

use of org.apache.camel.impl.SimpleRegistry in project camel by apache.

the class XmlRpcEndpointTest method createRegistry.

protected Registry createRegistry() {
    SimpleRegistry answer = new SimpleRegistry();
    // Binding the client configurer
    answer.put("myClientConfigurer", new MyClientConfigurer());
    return answer;
}
Also used : SimpleRegistry(org.apache.camel.impl.SimpleRegistry)

Aggregations

SimpleRegistry (org.apache.camel.impl.SimpleRegistry)64 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)61 CamelContext (org.apache.camel.CamelContext)40 Test (org.junit.Test)31 RouteBuilder (org.apache.camel.builder.RouteBuilder)14 Before (org.junit.Before)8 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)5 EchoRequest (org.opennms.core.rpc.echo.EchoRequest)5 EchoRpcModule (org.opennms.core.rpc.echo.EchoRpcModule)5 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)4 Component (org.apache.camel.Component)4 Exchange (org.apache.camel.Exchange)4 DummyRestConsumerFactory (org.apache.camel.component.rest.DummyRestConsumerFactory)4 DefaultExchange (org.apache.camel.impl.DefaultExchange)4 EchoResponse (org.opennms.core.rpc.echo.EchoResponse)4 HashMap (java.util.HashMap)3 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)3 SjmsComponent (org.apache.camel.component.sjms.SjmsComponent)3 Config (com.hazelcast.config.Config)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2