org.apache.camel.ServiceStatus Java Examples

The following examples show how to use org.apache.camel.ServiceStatus. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CXFRSConsumerIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testCXFConsumer() throws Exception {

    CamelContext camelctx = contextRegistry.getCamelContext("cxfrs-undertow");
    Assert.assertNotNull("Expected cxfrs-undertow to not be null", camelctx);
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
    try {
        // The JAXRS Client API needs to see resteasy
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

        Client client = ClientBuilder.newClient();
        Object result = client.target("http://localhost:8080/cxfrestful/greet/hello/Kermit").request(MediaType.APPLICATION_JSON).get(String.class);
        Assert.assertEquals("Hello Kermit", result);
    } finally {
        Thread.currentThread().setContextClassLoader(tccl);
    }
}
 
Example #2
Source File: DirectVMSpringIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testSpringDirectVMComponent() throws Exception {
    CamelContext camelctxA = contextRegistry.getCamelContext("direct-vm-context-a");
    Assert.assertEquals(ServiceStatus.Started, camelctxA.getStatus());

    CamelContext camelctxB = contextRegistry.getCamelContext("direct-vm-context-b");
    Assert.assertEquals(ServiceStatus.Started, camelctxB.getStatus());

    MockEndpoint mockEndpoint = camelctxB.getEndpoint("mock:result", MockEndpoint.class);
    mockEndpoint.expectedBodiesReceived("Hello Kermit");

    ProducerTemplate template = camelctxA.createProducerTemplate();
    template.sendBody("direct:start", "Kermit");

    mockEndpoint.assertIsSatisfied();
}
 
Example #3
Source File: NettyIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeployedContext() throws Exception {

    ServiceName sname = CamelConstants.CAMEL_CONTEXT_REGISTRY_SERVICE_NAME;
    CamelContextRegistry registry = ServiceLocator.getRequiredService(sname, CamelContextRegistry.class);
    CamelContext camelctx = registry.getCamelContext("netty-context");
    Assert.assertNotNull("CamelContext not null", camelctx);
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

    PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
    pollingConsumer.start();

    Socket socket = new Socket(SOCKET_HOST, 7999);
    socket.setKeepAlive(true);
    PrintWriter out = new PrintWriter(socket.getOutputStream(), true);

    try {
        out.write("Kermit\n");
    } finally {
        out.close();
        socket.close();
    }

    String result = pollingConsumer.receive().getIn().getBody(String.class);
    Assert.assertEquals("Hello Kermit", result);
}
 
Example #4
Source File: SalesforceSpringIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testSalesforceQueryProducer() throws Exception {

    Assume.assumeTrue(hasSalesforceEnvVars());

    CamelContext camelctx = contextRegistry.getCamelContext("salesforce-context");
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

    ProducerTemplate template = camelctx.createProducerTemplate();

    QueryRecordsOpportunity oppRecords = template.requestBody("direct:opportunity", null, QueryRecordsOpportunity.class);
    Assert.assertNotNull("Expected query records result to not be null", oppRecords);
    Assert.assertTrue("Expected some records", oppRecords.getRecords().size() > 0);

    Opportunity oppItem = oppRecords.getRecords().get(0);
    Assert.assertNotNull("Expected Oportunity Id", oppItem.getId());
    Assert.assertNotNull("Expected Oportunity Name", oppItem.getName());

    QueryRecordsAccount accRecords = template.requestBody("direct:account", null, QueryRecordsAccount.class);
    Assert.assertNotNull("Expected query records result to not be null", accRecords);

    Account accItem = accRecords.getRecords().get(0);
    Assert.assertNotNull("Expected Account Id", accItem.getId());
    Assert.assertNotNull("Expected Account Number", accItem.getAccountNumber());
}
 
Example #5
Source File: HL7NettyIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testHl7NettyEncodeDecode() throws Exception {
    CamelContext camelctx = camelContextRegistry.getCamelContext("hl7-context");
    Assert.assertNotNull("Expected hl7-context to not be null", camelctx);
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

    String body = "MSH|^~\\&|MYSENDER|MYRECEIVER|MYAPPLICATION||200612211200||QRY^A19|1234|P|2.4\r";

    MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class);
    mockEndpoint.expectedBodiesReceived(body);

    ProducerTemplate template = camelctx.createProducerTemplate();
    template.sendBody("direct:start", body);

    mockEndpoint.assertIsSatisfied(5000);
}
 
Example #6
Source File: SpringContextBindingJaxWsTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testJaxWsServiceCamelJndiBindingsInjectable() throws Exception {
    try {
        deployer.deploy(SIMPLE_WAR);

        CamelContext camelctx = contextRegistry.getCamelContext("jndi-delayed-binding-spring-context");
        Assert.assertNotNull("Expected jndi-delayed-binding-spring-context to not be null", camelctx);
        Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

        QName qname = new QName("http://wildfly.camel.test.ws", "WebServiceEndpointImplService");
        Service service = Service.create(new URL("http://localhost:8080/simple/WebServiceEndpointImpl?wsdl"), qname);
        WebServiceEndpoint endpoint = service.getPort(WebServiceEndpoint.class);
        Assert.assertNotNull("Endpoint not null", endpoint);
        Assert.assertEquals("camelctxA,camelctxB,camelctxC", endpoint.getContextInjectionStatus());
    } finally {
        deployer.undeploy(SIMPLE_WAR);
    }
}
 
Example #7
Source File: SpringContextBindingJarTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testEjbCamelJndiBindingsInjectable() throws Exception {
    try {
        deployer.deploy(SIMPLE_JAR);

        CamelContext camelctx = contextRegistry.getCamelContext("jndi-delayed-binding-spring-context");
        Assert.assertNotNull("Expected jndi-delayed-binding-spring-context to not be null", camelctx);
        Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

        String dataDir = System.getProperty("jboss.server.data.dir");
        Path filePath = Paths.get(dataDir, "camel-context-status.txt");

        String result = new String(Files.readAllBytes(filePath));
        Assert.assertEquals("camelctxA,camelctxB,camelctxC", result);
    } finally {
        deployer.undeploy(SIMPLE_JAR);
    }
}
 
Example #8
Source File: SpringContextBindingDependenciesTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testCamelSpringDeploymentWaitsForJndiBindings() {
    CamelContext camelctx = contextRegistry.getCamelContext("jndi-binding-spring-context");
    Assert.assertNotNull("Expected jndi-binding-spring-context to not be null", camelctx);
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

    ContextNames.BindInfo bindInfo = bindInfoFor("java:/spring/binding/test");
    ServiceName serviceName = bindInfo.getBinderServiceName();
    ServiceController<?> controller = serviceContainer.getService(serviceName);

    Assert.assertNotNull("Expected controller to not be null", controller);
    ManagedReferenceFactory referenceFactory = (ManagedReferenceFactory) controller.getValue();
    DelayedBinderService binderService = (DelayedBinderService) referenceFactory.getReference().getInstance();

    // Make sure the DelayedBinderService did sleep
    Assert.assertTrue("Expected DelayedBinderService.getSleepStart() to be > 0", binderService.getSleepStart() > 0);

    // Verify that the camel context waited for the binding service to finish starting
    CamelContextStartupEventNotifier notifier = (CamelContextStartupEventNotifier) camelctx.getRegistry().lookupByName("contextStartupEventNotifier");
    long startupDelay = notifier.getStartupTime() - binderService.getSleepStart();
    Assert.assertTrue(startupDelay >= binderService.getSleepDelay());
}
 
Example #9
Source File: SpringContextBindingWarTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
private void deployResourceInjectionTest(String depName, String expectedResult) throws Exception {
    try {
        deployer.deploy(depName);

        CamelContext camelctx = contextRegistry.getCamelContext("jndi-delayed-binding-spring-context");
        Assert.assertNotNull("Expected jndi-delayed-binding-spring-context to not be null", camelctx);
        Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

        String contextPath = depName.replace(".war", "");

        HttpResponse response = HttpRequest.get("http://localhost:8080/" + contextPath).getResponse();
        Assert.assertEquals(expectedResult, response.getBody());
    } finally {
        deployer.undeploy(depName);
    }
}
 
Example #10
Source File: SpringContextBindingDependenciesEarTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testCamelSpringDeploymentWaitsForJndiBindings() {
    CamelContext camelctx = contextRegistry.getCamelContext("jndi-binding-spring-context");
    Assert.assertNotNull("Expected jndi-binding-spring-context to not be null", camelctx);
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

    BindInfo bindInfo = bindInfoFor("java:/spring/binding/test");
    ServiceName serviceName = bindInfo.getBinderServiceName();
    ServiceController<?> controller = serviceContainer.getService(serviceName);

    Assert.assertNotNull("Expected controller to not be null", controller);
    ManagedReferenceFactory referenceFactory = (ManagedReferenceFactory) controller.getValue();
    DelayedBinderService binderService = (DelayedBinderService) referenceFactory.getReference().getInstance();

    // Make sure the DelayedBinderService did sleep
    Assert.assertTrue("Expected DelayedBinderService.getSleepStart() to be > 0", binderService.getSleepStart() > 0);

    // Verify that the camel context waited for the binding service to finish starting
    CamelContextStartupEventNotifier notifier = (CamelContextStartupEventNotifier) camelctx.getRegistry().lookupByName("contextStartupEventNotifier");
    long startupDelay = notifier.getStartupTime() - binderService.getSleepStart();
    Assert.assertTrue(startupDelay >= binderService.getSleepDelay());
}
 
Example #11
Source File: SupervisingRouteControllerTest.java    From camel-spring-boot with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception {
    Assert.assertNotNull(context.getRouteController());
    Assert.assertTrue(context.getRouteController() instanceof SupervisingRouteController);

    SupervisingRouteController controller = context.getRouteController().adapt(SupervisingRouteController.class);

    // Wait for the controller to start the routes
    await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
        Assert.assertEquals(3, controller.getControlledRoutes().size());
        Assert.assertEquals(500, controller.getInitialDelay());

        Assert.assertEquals(ServiceStatus.Started, context.getRouteController().getRouteStatus("foo"));
        Assert.assertEquals(ServiceStatus.Started, context.getRouteController().getRouteStatus("bar"));
        Assert.assertEquals(ServiceStatus.Started, context.getRouteController().getRouteStatus("jetty"));
    });
}
 
Example #12
Source File: MicroProfileMetricsIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testMicroProfileMetricsEventNotifiers() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.getManagementStrategy().addEventNotifier(new MicroProfileMetricsCamelContextEventNotifier());
    camelctx.getManagementStrategy().addEventNotifier(new MicroProfileMetricsRouteEventNotifier());
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
                .to("log:end");
        }
    });
    bindMetricRegistry(camelctx);

    camelctx.start();
    try {
        assertSimpleMetricValue(camelctx, "camel.context.status", ServiceStatus.Started.ordinal());
        assertSimpleMetricValue(camelctx, "camel.route.running.count", 1);
    } finally {
        camelctx.stop();
    }
}
 
Example #13
Source File: CamelStreamer.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Stops the streamer.
 *
 * @throws IgniteException In cases if failed to stop the streamer.
 */
public void stop() throws IgniteException {
    // If the Camel Context is stopping or stopped, reject this call to stop.
    if (camelCtx.getStatus() == ServiceStatus.Stopped || camelCtx.getStatus() == ServiceStatus.Stopping)
        throw new IgniteException("Failed to stop Camel streamer (CamelContext already stopped or stopping).");

    // Stop Camel services.
    try {
        ServiceHelper.stopAndShutdownServices(camelCtx, endpoint, consumer);
    }
    catch (Exception e) {
        throw new IgniteException("Failed to stop Camel streamer [errMsg=" + e.getMessage() + ']');
    }

    U.log(log, "Stopped Camel streamer, formerly consuming from endpoint URI: " + endpointUri);
}
 
Example #14
Source File: IgniteCamelStreamerTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception
 */
@Test
public void testInvalidEndpointUri() throws Exception {
    streamer.setSingleTupleExtractor(singleTupleExtractor());
    streamer.setEndpointUri("abc");

    // Action time.
    try {
        streamer.start();
        fail("Streamer started; should have failed.");
    }
    catch (IgniteException ignored) {
        assertTrue(streamer.getCamelContext().getStatus() == ServiceStatus.Stopped);
        assertTrue(streamer.getCamelContext().getEndpointRegistry().size() == 0);
    }
}
 
Example #15
Source File: OIntegrationConfigStopBehavior.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Override
public void onConfigure(Component component) {
	super.onConfigure(component);
		ODocumentModel docModel=null;
		if(component.getDefaultModel() instanceof ODocumentModel){
			docModel = (ODocumentModel) component.getDefaultModel();
		}else if(component.getDefaultModel() instanceof IWrapModel){
			docModel = (ODocumentModel) ((IWrapModel<?>) component.getDefaultModel()).getWrappedModel();
		}
		if (docModel!=null && docModel.getObject()!=null){
			OIntegrationConfig config = new OIntegrationConfig(docModel.getObject());
			CamelContext context = config.getOrMakeContext(component);
			ServiceStatus status = context.getStatus();
			if (status.isStopped()){
				component.setEnabled(false);
			}else{
				component.setEnabled(true);
			}
		}
}
 
Example #16
Source File: CXFWSConsumerIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testCXFRoundtrip() throws Exception {

    CamelContext camelctx = contextRegistry.getCamelContext("cxfws-undertow");
    Assert.assertNotNull("Expected cxfws-undertow to not be null", camelctx);
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

    ProducerTemplate producer = camelctx.createProducerTemplate();
    String result = producer.requestBody("direct:start", "Kermit", String.class);
    Assert.assertEquals("Hello Kermit", result);
}
 
Example #17
Source File: CustomFailoverExceptionTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testExportedPaths() throws Exception {

    CamelContext camelctx = contextRegistry.getCamelContext("custom-failover-context");
    Assert.assertNotNull("Context not null", camelctx);
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

    String name = CustomFailoverException.class.getName();
    Assert.assertNotNull("Class resolved", camelctx.getClassResolver().resolveClass(name));
    Assert.assertNotNull("Class loaded", camelctx.getApplicationContextClassLoader().loadClass(name));
}
 
Example #18
Source File: PropertiesFromClasspathTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testExportedPaths() throws Exception {

    CamelContext camelctx = contextRegistry.getCamelContext("classpath-properties-context");
    Assert.assertNotNull("Context not null", camelctx);
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

    Assert.assertNotNull("From not null", camelctx.getEndpoint("file:camel-test/camel-from"));
    Assert.assertNotNull("To not null", camelctx.getEndpoint("file:camel-test/camel-to"));
}
 
Example #19
Source File: CDIIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
private CamelContext assertSingleCamelContext() {
    List<String> ctxnames = contextRegistry.getCamelContextNames();
    Assert.assertEquals("Expected single camel context: " + ctxnames, 1, ctxnames.size());
    CamelContext camelctx = contextRegistry.getCamelContext(ctxnames.iterator().next());
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());
    return camelctx;
}
 
Example #20
Source File: CXFWSSSLProducerIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testCxfWSSSLProducer() {
    CamelContext camelctx = contextRegistry.getCamelContext("cxfws-ssl-context");
    Assert.assertNotNull("Expected cxfrs-producer-context to not be null", camelctx);
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

    ProducerTemplate template = camelctx.createProducerTemplate();
    String result = template.requestBody("direct:start", "Kermit", String.class);
    Assert.assertEquals("Hello Kermit", result);
}
 
Example #21
Source File: CXFWSServerTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testCXFWsServer() throws Exception {
    CamelContext camelctx = contextRegistry.getCamelContext("cxf-server-context");
    Assert.assertNotNull("Expected cxf-server-context to not be null", camelctx);
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

    ProducerTemplate template = camelctx.createProducerTemplate();
    String result = template.requestBody("direct:start", "Kermit", String.class);
    Assert.assertEquals("Hello Kermit", result);
}
 
Example #22
Source File: CXFWSConsumerIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testCXFConsumer() throws Exception {

    CamelContext camelctx = contextRegistry.getCamelContext("cxfws-undertow");
    Assert.assertNotNull("Expected cxfws-undertow to not be null", camelctx);
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

    QName qname = new QName("http://wildfly.camel.test.cxf", "EndpointService");
    Service service = Service.create(new URL("http://localhost:8080/EndpointService/EndpointPort?wsdl"), qname);
    Endpoint endpoint = service.getPort(Endpoint.class);
    Assert.assertNotNull("Endpoint not null", endpoint);

    Assert.assertEquals("Hello Kermit", endpoint.echo("Kermit"));
}
 
Example #23
Source File: DozerSpringIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testBeanMapping() throws Exception {

    CamelContext camelctx = contextRegistry.getCamelContext("dozer-spring-context");
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

    String json = "{" + CustomerA.class.getName() + ":{firstName:John,lastName:Doe,street:Street,zip:1234}}";

    ProducerTemplate template = camelctx.createProducerTemplate();
    CustomerB customer = template.requestBody("direct:start", json, CustomerB.class);
    Assert.assertEquals("John", customer.getFirstName());
    Assert.assertEquals("Doe", customer.getLastName());
    Assert.assertEquals("Street", customer.getAddress().getStreet());
    Assert.assertEquals("1234", customer.getAddress().getZip());
}
 
Example #24
Source File: CDITransactionErrorHandlerIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
private CamelContext assertSingleCamelContext() {
    List<String> ctxnames = contextRegistry.getCamelContextNames();
    Assert.assertEquals("Expected single camel context: " + ctxnames, 1, ctxnames.size());
    CamelContext camelctx = contextRegistry.getCamelContext(ctxnames.iterator().next());
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());
    return camelctx;
}
 
Example #25
Source File: CDIContextCreationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testManualComponentConfig() throws InterruptedException {
    deployer.deploy(CDI_CONTEXT_C);
    try {
        CamelContext camelctx = assertSingleCamelContext();
        Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());
        MockEndpoint mock = camelctx.getEndpoint(RouteBuilderF.MOCK_RESULT_URI, MockEndpoint.class);
        Assert.assertTrue("All messages received", mock.await(5, TimeUnit.SECONDS));
    } finally {
        deployer.undeploy(CDI_CONTEXT_C);
    }
    Assert.assertEquals(Arrays.asList(), contextRegistry.getCamelContextNames());
}
 
Example #26
Source File: CXFRSServerTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testCxfJaxRsServer() throws Exception {
    CamelContext camelctx = contextRegistry.getCamelContext("cxfrs-server-context");
    Assert.assertNotNull("Expected cxfrs-server-context to not be null", camelctx);
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

    ProducerTemplate template = camelctx.createProducerTemplate();
    String result = template.requestBody("direct:start", null, String.class);
    Assert.assertEquals("Hello Kermit", result);
}
 
Example #27
Source File: MicroProfileHealthIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testMicroProfileHealthCamelContextStatusCheck() throws Exception {
    CamelContext camelctx = contextRegistry.getCamelContext("health-context");
    Assert.assertNotNull("Expected health-context to not be null", camelctx);
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

    String body = HttpRequest.get("http://localhost:9990/health").getResponse().getBody();
    Assert.assertTrue("Unexpected: " + body, body.contains("\"data\":{\"contextStatus\":\"Started\",\"name\":\"health-context\"}}"));
}
 
Example #28
Source File: CXFRSAsyncTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testCxfJaxRsServer() throws Exception {
    CamelContext camelctx = contextRegistry.getCamelContext("cxfrs-async-context");
    Assert.assertNotNull("Expected cxfrs-async-context to not be null", camelctx);
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

    ProducerTemplate template = camelctx.createProducerTemplate();
    String result = template.requestBody("direct:start", null, String.class);
    Assert.assertEquals("Hello Kermit", result);
}
 
Example #29
Source File: CXFRSSecureConsumerIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testCXFSecureConsumer() throws Exception {

    CamelContext camelctx = contextRegistry.getCamelContext("cxfrs-secure-undertow");
    Assert.assertNotNull("Expected cxfrs-secure-undertow to not be null", camelctx);
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
    try {
        // The JAXRS Client API needs to see resteasy
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

        // Force WildFly to generate a self-signed SSL cert & keystore
        HttpRequest.get("https://localhost:8443").throwExceptionOnFailure(false).getResponse();

        // Use the generated keystore
        String keystorePath = System.getProperty("jboss.server.config.dir") + "/application.keystore";
        System.setProperty("javax.net.ssl.trustStorePassword", "password");
        System.setProperty("javax.net.ssl.trustStore", keystorePath);

        Client client = ClientBuilder.newClient();

        Object result = client.target(SECURE_RS_ENDPOINT).request(MediaType.APPLICATION_JSON).get(String.class);
        Assert.assertEquals("Hello Kermit", result);

        // Verify that if we attempt to use HTTP, we get a 302 redirect to the HTTPS endpoint URL
        HttpResponse response = HttpRequest.get(INSECURE_RS_ENDPOINT)
            .throwExceptionOnFailure(false)
            .followRedirects(false)
            .getResponse();
        Assert.assertEquals(302, response.getStatusCode());
        Assert.assertEquals(response.getHeader("Location"), SECURE_RS_ENDPOINT);
    } finally {
        System.clearProperty("javax.net.ssl.trustStorePassword");
        System.clearProperty("javax.net.ssl.trustStore");
        Thread.currentThread().setContextClassLoader(tccl);
    }
}
 
Example #30
Source File: GangliaIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
private CamelContext assertSingleCamelContext() {
    List<String> ctxnames = contextRegistry.getCamelContextNames();
    Assert.assertEquals("Expected single camel context: " + ctxnames, 1, ctxnames.size());
    CamelContext camelctx = contextRegistry.getCamelContext(ctxnames.iterator().next());
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());
    return camelctx;
}