当前位置: 首页>>代码示例>>Java>>正文


Java CamelExecutionException.getCause方法代码示例

本文整理汇总了Java中org.apache.camel.CamelExecutionException.getCause方法的典型用法代码示例。如果您正苦于以下问题:Java CamelExecutionException.getCause方法的具体用法?Java CamelExecutionException.getCause怎么用?Java CamelExecutionException.getCause使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.camel.CamelExecutionException的用法示例。


在下文中一共展示了CamelExecutionException.getCause方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testGuestAuth

import org.apache.camel.CamelExecutionException; //导入方法依赖的package包/类
@Test
public void testGuestAuth() throws Exception {
    // username:password is guest:secret
    String auth = "Basic Z3Vlc3Q6c2VjcmV0";
    String out = template.requestBodyAndHeader("netty-http:http://localhost:" + port + "/foo/guest/hello", "Hello Guest", "Authorization", auth, String.class);
    assertEquals("Bye /foo/guest/hello", out);

    // accessing admin is restricted for guest user
    try {
        template.requestBodyAndHeader("netty-http:http://localhost:" + port + "/foo/admin/users", "Hello Admin", "Authorization", auth, String.class);
        fail("Should send back 401");
    } catch (CamelExecutionException e) {
        NettyHttpOperationFailedException cause = (NettyHttpOperationFailedException) e.getCause();
        assertEquals(401, cause.getStatusCode());
    }

    // but we can access foo as that is any roles
    out = template.requestBodyAndHeader("netty-http:http://localhost:" + port + "/foo", "Hello Foo", "Authorization", auth, String.class);
    assertEquals("Bye /foo", out);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:SpringNettyHttpBasicAuthTest.java

示例2: testGuestAuth

import org.apache.camel.CamelExecutionException; //导入方法依赖的package包/类
@Test
public void testGuestAuth() throws Exception {
    // username:password is guest:secret
    String auth = "Basic Z3Vlc3Q6c2VjcmV0";
    String out = template.requestBodyAndHeader("netty4-http:http://localhost:" + port + "/foo/guest/hello", "Hello Guest", "Authorization", auth, String.class);
    assertEquals("Bye /foo/guest/hello", out);

    // but we can access foo as that is any roles
    out = template.requestBodyAndHeader("netty4-http:http://localhost:" + port + "/foo", "Hello Foo", "Authorization", auth, String.class);
    assertEquals("Bye /foo", out);
    
    // accessing admin is restricted for guest user
    try {
        template.requestBodyAndHeader("netty4-http:http://localhost:" + port + "/foo/admin/users", "Hello Admin", "Authorization", auth, String.class);
        fail("Should send back 401");
    } catch (CamelExecutionException e) {
        NettyHttpOperationFailedException cause = (NettyHttpOperationFailedException) e.getCause();
        assertEquals(401, cause.getStatusCode());
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:SpringNettyHttpBasicAuthTest.java

示例3: testUnmarshallWithValidationException

import org.apache.camel.CamelExecutionException; //导入方法依赖的package包/类
@Test
public void testUnmarshallWithValidationException() throws Exception {
    String xml = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>")
        .append("<person xmlns=\"person.jaxb.converter.camel.apache.org\" />")
        .toString();
    
    try {
        template.sendBody("direct:unmarshall", xml);
        fail("CamelExecutionException expected");
    } catch (CamelExecutionException e) {
        Throwable cause = e.getCause();
        assertIsInstanceOf(IOException.class, cause);
        assertTrue(cause.getMessage().contains("javax.xml.bind.UnmarshalException"));
        assertTrue(cause.getMessage().contains("org.xml.sax.SAXParseException"));
        assertTrue(cause.getMessage().contains("cvc-complex-type.2.4.b"));
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:JaxbDataFormatSchemaValidationSpringTest.java

示例4: validateShouldFailWithRedefinedDefaultGroup

import org.apache.camel.CamelExecutionException; //导入方法依赖的package包/类
@Test
public void validateShouldFailWithRedefinedDefaultGroup() throws Exception {
    if (isPlatform("aix")) {
        // cannot run on aix
        return;
    }

    final String url = "bean-validator://x";
    final Car car = new CarWithRedefinedDefaultGroup(null, "D-A");
    
    try {
        template.requestBody(url, car);
        fail("should throw exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(BeanValidationException.class, e.getCause());
        
        BeanValidationException exception = (BeanValidationException) e.getCause();
        Set<ConstraintViolation<Object>> constraintViolations = exception.getConstraintViolations();
        
        assertEquals(1, constraintViolations.size());
        ConstraintViolation<Object> constraintViolation = constraintViolations.iterator().next();
        assertEquals("licensePlate", constraintViolation.getPropertyPath().toString());
        assertEquals("D-A", constraintViolation.getInvalidValue());
        assertEquals("size must be between 5 and 14", constraintViolation.getMessage());
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:BeanValidatorRouteTest.java

示例5: testApexCall

import org.apache.camel.CamelExecutionException; //导入方法依赖的package包/类
@Test
public void testApexCall() throws Exception {
    try {
        doTestApexCall("");
        doTestApexCall("Xml");
    } catch (CamelExecutionException e) {
        if (e.getCause() instanceof SalesforceException) {
            SalesforceException cause = (SalesforceException) e.getCause();
            if (cause.getStatusCode() == HttpStatus.NOT_FOUND_404) {
                LOG.error("Make sure test REST resource MerchandiseRestResource.apxc has been loaded: "
                    + e.getMessage());
            }
        }
        throw e;
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:RestApiIntegrationTest.java

示例6: testFail

import org.apache.camel.CamelExecutionException; //导入方法依赖的package包/类
public void testFail() throws Exception {
    try {
        template.sendBody("direct:fail", "Hello World");
        fail("Should throw an exception");
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(AmbiguousMethodCallException.class, e.getCause());
        AmbiguousMethodCallException ace = (AmbiguousMethodCallException) e.getCause();
        assertEquals(2, ace.getMethods().size());
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:BeanWithMethodHeaderTest.java

示例7: testAdminAuth

import org.apache.camel.CamelExecutionException; //导入方法依赖的package包/类
@Test
public void testAdminAuth() throws Exception {
    try {
        template.requestBody("netty-http:http://localhost:" + port + "/foo", "Hello Foo", String.class);
        fail("Should send back 401");
    } catch (CamelExecutionException e) {
        NettyHttpOperationFailedException cause = (NettyHttpOperationFailedException) e.getCause();
        assertEquals(401, cause.getStatusCode());
    }

    mockEndpoint.reset();
    mockEndpoint.expectedBodiesReceived("Hello Public", "Hello Foo", "Hello Admin");

    // public do not need authentication
    String out = template.requestBody("netty-http:http://localhost:" + port + "/foo/public/welcome", "Hello Public", String.class);
    assertEquals("Bye /foo/public/welcome", out);

    // username:password is scott:secret
    String auth = "Basic c2NvdHQ6c2VjcmV0";
    out = template.requestBodyAndHeader("netty-http:http://localhost:" + port + "/foo", "Hello Foo", "Authorization", auth, String.class);
    assertEquals("Bye /foo", out);

    out = template.requestBodyAndHeader("netty-http:http://localhost:" + port + "/foo/admin/users", "Hello Admin", "Authorization", auth, String.class);
    assertEquals("Bye /foo/admin/users", out);

    mockEndpoint.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:28,代码来源:SpringNettyHttpBasicAuthTest.java

示例8: testAdminAuth

import org.apache.camel.CamelExecutionException; //导入方法依赖的package包/类
@Test
public void testAdminAuth() throws Exception {
    mockEndpoint.reset();
    
    mockEndpoint.expectedBodiesReceived("Hello Public", "Hello Foo", "Hello Admin");

    // public do not need authentication
    String out = template.requestBody("netty4-http:http://localhost:" + port + "/foo/public/welcome", "Hello Public", String.class);
    assertEquals("Bye /foo/public/welcome", out);

    // username:password is scott:secret
    String auth = "Basic c2NvdHQ6c2VjcmV0";
    out = template.requestBodyAndHeader("netty4-http:http://localhost:" + port + "/foo", "Hello Foo", "Authorization", auth, String.class);
    assertEquals("Bye /foo", out);

    out = template.requestBodyAndHeader("netty4-http:http://localhost:" + port + "/foo/admin/users", "Hello Admin", "Authorization", auth, String.class);
    assertEquals("Bye /foo/admin/users", out);

    mockEndpoint.assertIsSatisfied();
    
    try {
        template.requestBody("netty4-http:http://localhost:" + port + "/foo", "Hello Foo", String.class);
        fail("Should send back 401");
    } catch (CamelExecutionException e) {
        NettyHttpOperationFailedException cause = (NettyHttpOperationFailedException) e.getCause();
        assertEquals(401, cause.getStatusCode());
    }

    
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:31,代码来源:SpringNettyHttpBasicAuthTest.java

示例9: testMarshallWithValidationException

import org.apache.camel.CamelExecutionException; //导入方法依赖的package包/类
@Test
public void testMarshallWithValidationException() throws Exception {
    try {
        template.sendBody("direct:marshall", new Person());
        fail("CamelExecutionException expected");
    } catch (CamelExecutionException e) {
        Throwable cause = e.getCause();
        assertIsInstanceOf(IOException.class, cause);
        assertTrue(cause.getMessage().contains("javax.xml.bind.MarshalException"));
        assertTrue(cause.getMessage().contains("org.xml.sax.SAXParseException"));
        assertTrue(cause.getMessage().contains("cvc-complex-type.2.4.a"));
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:14,代码来源:JaxbDataFormatSchemaValidationSpringTest.java

示例10: test1

import org.apache.camel.CamelExecutionException; //导入方法依赖的package包/类
@Test
public void test1() throws Exception {
    try {
        // Send a String body that need to be converted to an InputStream
        template.sendBody("direct:start", "42");
    } catch (CamelExecutionException e) {
        // unwrap Exception
        throw (Exception) e.getCause();
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:CamelSpringBootShutdownTest.java

示例11: test2

import org.apache.camel.CamelExecutionException; //导入方法依赖的package包/类
@Test
public void test2() throws Exception {
    try {
        // Starts a Thread to close the context in 500 ms
        new DelayedCloser(context, 500).start();
        // Send the same body, and let the context be closed before the processing happens
        template.sendBody("direct:start", "42");
    } catch (CamelExecutionException e) {
        // unwrap Exception
        throw (Exception) e.getCause();
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:13,代码来源:CamelSpringBootShutdownTest.java

示例12: testRetryFailure

import org.apache.camel.CamelExecutionException; //导入方法依赖的package包/类
@Test
public void testRetryFailure() throws Exception {
    SalesforceComponent sf = context().getComponent("salesforce", SalesforceComponent.class);
    String accessToken = sf.getSession().getAccessToken();

    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setSslContext(new SSLContextParameters().createSSLContext());
    HttpClient httpClient = new HttpClient(sslContextFactory);
    httpClient.setConnectTimeout(60000);
    httpClient.start();

    String uri = sf.getLoginConfig().getLoginUrl() + "/services/oauth2/revoke?token=" + accessToken;
    Request logoutGet = httpClient.newRequest(uri)
        .method(HttpMethod.GET)
        .timeout(1, TimeUnit.MINUTES);

    ContentResponse response = logoutGet.send();
    assertEquals(HttpStatus.OK_200, response.getStatus());

    // set component config to bad password to cause relogin attempts to fail
    final String password = sf.getLoginConfig().getPassword();
    sf.getLoginConfig().setPassword("bad_password");

    try {
        doTestGetGlobalObjects("");
        fail("Expected CamelExecutionException!");
    } catch (CamelExecutionException e) {
        if (e.getCause() instanceof SalesforceException) {
            SalesforceException cause = (SalesforceException) e.getCause();
            assertEquals("Expected 400 on authentication retry failure", HttpStatus.BAD_REQUEST_400, cause.getStatusCode());
        } else {
            fail("Expected SalesforceException!");
        }
    } finally {
        // reset password and retries to allow other tests to pass
        sf.getLoginConfig().setPassword(password);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:39,代码来源:RestApiIntegrationTest.java

示例13: messageAckOnExceptionWhereNoAutoAckTest

import org.apache.camel.CamelExecutionException; //导入方法依赖的package包/类
@Test
public void messageAckOnExceptionWhereNoAutoAckTest() throws Exception {
    Map<String, Object> headers = new HashMap<>();
    headers.put(RabbitMQConstants.EXCHANGE_NAME, EXCHANGE_NO_ACK);
    headers.put(RabbitMQConstants.ROUTING_KEY, ROUTING_KEY);

    resultEndpoint.expectedMessageCount(1);

    try {
        String reply = template.requestBodyAndHeaders("direct:rabbitMQNoAutoAck", "testMessage", headers, String.class);
        fail("This should have thrown an exception");
    } catch (CamelExecutionException e) {
        if (!(e.getCause() instanceof IllegalStateException)) {
            throw e;
        }
    }

    resultEndpoint.assertIsSatisfied();
    resultEndpoint.reset();

    resultEndpoint.expectedMessageCount(0);

    context.stop(); //On restarting the camel context, if the message was not acknowledged the message would be reprocessed
    context.start();

    resultEndpoint.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:28,代码来源:RabbitMQInOutIntTest.java


注:本文中的org.apache.camel.CamelExecutionException.getCause方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。