Search in sources :

Example 1 with HTTPException

use of org.apache.cxf.transport.http.HTTPException in project camel by apache.

the class CxfEndpointBeansTest method testCxfBusConfiguration.

@Test
public void testCxfBusConfiguration() throws Exception {
    // get the camelContext from application context
    ProducerTemplate template = context.createProducerTemplate();
    Exchange reply = template.request("cxf:bean:serviceEndpoint", new Processor() {

        public void process(final Exchange exchange) {
            final List<String> params = new ArrayList<String>();
            params.add("hello");
            exchange.getIn().setBody(params);
            exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "echo");
        }
    });
    Exception ex = reply.getException();
    assertTrue("Should get the fault here", ex instanceof org.apache.cxf.interceptor.Fault || ex instanceof HTTPException);
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Processor(org.apache.camel.Processor) HTTPException(org.apache.cxf.transport.http.HTTPException) ArrayList(java.util.ArrayList) List(java.util.List) HTTPException(org.apache.cxf.transport.http.HTTPException) Test(org.junit.Test)

Example 2 with HTTPException

use of org.apache.cxf.transport.http.HTTPException in project camel by apache.

the class CxfEndpointBeansRouterTest method testCxfBusConfiguration.

@Test
public void testCxfBusConfiguration() throws Exception {
    // get the camelContext from application context
    CamelContext camelContext = ctx.getBean("camel", CamelContext.class);
    ProducerTemplate template = camelContext.createProducerTemplate();
    Exchange reply = template.request("cxf:bean:serviceEndpoint", new Processor() {

        public void process(final Exchange exchange) {
            final List<String> params = new ArrayList<String>();
            params.add("hello");
            exchange.getIn().setBody(params);
            exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "echo");
        }
    });
    Exception ex = reply.getException();
    assertTrue("Should get the fault here", ex instanceof org.apache.cxf.interceptor.Fault || ex instanceof HTTPException);
}
Also used : CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Processor(org.apache.camel.Processor) HTTPException(org.apache.cxf.transport.http.HTTPException) ArrayList(java.util.ArrayList) List(java.util.List) HTTPException(org.apache.cxf.transport.http.HTTPException) Test(org.junit.Test)

Example 3 with HTTPException

use of org.apache.cxf.transport.http.HTTPException in project cxf by apache.

the class DigestAuthTest method testNoAuth.

@Test
public void testNoAuth() throws Exception {
    URL wsdl = getClass().getResource("../greeting.wsdl");
    assertNotNull("WSDL is null", wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull("Service is null", service);
    Greeter mortimer = service.getPort(mortimerQ, Greeter.class);
    assertNotNull("Port is null", mortimer);
    TestUtil.setAddress(mortimer, "http://localhost:" + PORT + "/digestauth/greeter");
    try {
        String answer = mortimer.sayHi();
        Assert.fail("Unexpected reply (" + answer + "). Should throw exception");
    } catch (Exception e) {
        Throwable cause = e.getCause();
        Assert.assertEquals(HTTPException.class, cause.getClass());
        HTTPException he = (HTTPException) cause;
        Assert.assertEquals(401, he.getResponseCode());
    }
}
Also used : SOAPService(org.apache.hello_world.services.SOAPService) HTTPException(org.apache.cxf.transport.http.HTTPException) Greeter(org.apache.hello_world.Greeter) URL(java.net.URL) HTTPException(org.apache.cxf.transport.http.HTTPException) Test(org.junit.Test)

Aggregations

HTTPException (org.apache.cxf.transport.http.HTTPException)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Exchange (org.apache.camel.Exchange)2 Processor (org.apache.camel.Processor)2 ProducerTemplate (org.apache.camel.ProducerTemplate)2 URL (java.net.URL)1 CamelContext (org.apache.camel.CamelContext)1 Greeter (org.apache.hello_world.Greeter)1 SOAPService (org.apache.hello_world.services.SOAPService)1