Search in sources :

Example 41 with Message

use of org.apache.cxf.message.Message in project cxf by apache.

the class EHCacheTokenStoreTest method init.

@BeforeClass
public static void init() {
    TokenStoreFactory tokenStoreFactory = new EHCacheTokenStoreFactory();
    Message message = new MessageImpl();
    message.put(SecurityConstants.CACHE_CONFIG_FILE, ClassLoaderUtils.getResource("cxf-ehcache.xml", EHCacheTokenStoreTest.class));
    message.setExchange(new ExchangeImpl());
    store = tokenStoreFactory.newTokenStore(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE, message);
}
Also used : Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) BeforeClass(org.junit.BeforeClass)

Example 42 with Message

use of org.apache.cxf.message.Message in project cxf by apache.

the class MemoryTokenStoreTest method init.

@BeforeClass
public static void init() {
    TokenStoreFactory tokenStoreFactory = new MemoryTokenStoreFactory();
    Message message = new MessageImpl();
    store = tokenStoreFactory.newTokenStore(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE, message);
}
Also used : Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) BeforeClass(org.junit.BeforeClass)

Example 43 with Message

use of org.apache.cxf.message.Message in project fabric8 by jboss-fuse.

the class FailOverClientServerTest method testClientServer.

@Test
public void testClientServer() throws Exception {
    assertNotNull(bus);
    // The bus is load the feature
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceBean(new HelloImpl());
    factory.setAddress("http://localhost:9000/fail/server");
    factory.setBus(bus);
    factory.create();
    factory = new JaxWsServerFactoryBean();
    factory.setServiceBean(new HelloImpl());
    factory.setAddress("http://localhost:9000/simple/server");
    factory.setBus(bus);
    factory.create();
    // sleep a while to let the service be published
    for (int i = 0; i < 100; i++) {
        if (!feature.getLoadBalanceStrategy().getAlternateAddressList().isEmpty()) {
            break;
        }
        Thread.sleep(100);
    }
    JaxWsProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean();
    clientFactory.setServiceClass(Hello.class);
    // The address is not the actual address that the client will access
    clientFactory.setAddress("http://someotherplace");
    List<AbstractFeature> features = new ArrayList<AbstractFeature>();
    // add the instance of FabricLoadBalancerFeature into features list
    features.add(feature);
    // we need to setup the feature on the clientfactory
    clientFactory.setFeatures(features);
    // set this interceptor to simulate the Transport level exception
    List<Interceptor<? extends Message>> outInterceptor = new ArrayList<Interceptor<? extends Message>>();
    outInterceptor.add(new TransportFailureInterceptor());
    clientFactory.setOutInterceptors(outInterceptor);
    Hello hello = clientFactory.create(Hello.class);
    String response = hello.sayHello();
    assertEquals("Get a wrong response", "Hello", response);
    response = hello.sayHello();
    assertEquals("Get a wrong response", "Hello", response);
}
Also used : Message(org.apache.cxf.message.Message) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) ArrayList(java.util.ArrayList) AbstractFeature(org.apache.cxf.feature.AbstractFeature) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) Interceptor(org.apache.cxf.interceptor.Interceptor) Test(org.junit.Test)

Example 44 with Message

use of org.apache.cxf.message.Message in project wildfly-camel by wildfly-extras.

the class CXFWSJAASAuthenticationIntegrationTest method configureCamelContext.

private CamelContext configureCamelContext(String password) throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    CxfComponent component = new CxfComponent(camelctx);
    CxfEndpoint consumerEndpoint = new CxfEndpoint("http://localhost:8080/webservices/greeting", component);
    consumerEndpoint.setServiceClass(Endpoint.class);
    List<Interceptor<? extends Message>> inInterceptors = consumerEndpoint.getInInterceptors();
    JAASLoginInterceptor interceptor = new JAASLoginInterceptor();
    interceptor.setContextName("other");
    inInterceptors.add(interceptor);
    CxfEndpoint producerEndpoint = new CxfEndpoint("http://localhost:8080/webservices/greeting", component);
    producerEndpoint.setServiceClass(Endpoint.class);
    producerEndpoint.setUsername("user1");
    producerEndpoint.setPassword(password);
    Map<String, Object> properties = producerEndpoint.getProperties();
    if (properties == null) {
        producerEndpoint.setProperties(new HashMap<>());
    }
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").to(producerEndpoint);
            from(consumerEndpoint).process(exchange -> {
                Object[] args = exchange.getIn().getBody(Object[].class);
                exchange.getOut().setBody("Hello " + args[0]);
            });
        }
    });
    return camelctx;
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) ShrinkWrap(org.jboss.shrinkwrap.api.ShrinkWrap) Interceptor(org.apache.cxf.interceptor.Interceptor) Arquillian(org.jboss.arquillian.junit.Arquillian) Message(org.apache.cxf.message.Message) RunWith(org.junit.runner.RunWith) CamelExecutionException(org.apache.camel.CamelExecutionException) HashMap(java.util.HashMap) Test(org.junit.Test) Endpoint(org.wildfly.camel.test.common.types.Endpoint) JAASLoginInterceptor(org.apache.cxf.interceptor.security.JAASLoginInterceptor) List(java.util.List) CxfEndpoint(org.apache.camel.component.cxf.CxfEndpoint) CamelAware(org.wildfly.extension.camel.CamelAware) RouteBuilder(org.apache.camel.builder.RouteBuilder) Deployment(org.jboss.arquillian.container.test.api.Deployment) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Map(java.util.Map) ProducerTemplate(org.apache.camel.ProducerTemplate) CxfComponent(org.apache.camel.component.cxf.CxfComponent) Assert(org.junit.Assert) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Message(org.apache.cxf.message.Message) RouteBuilder(org.apache.camel.builder.RouteBuilder) JAASLoginInterceptor(org.apache.cxf.interceptor.security.JAASLoginInterceptor) CxfEndpoint(org.apache.camel.component.cxf.CxfEndpoint) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelExecutionException(org.apache.camel.CamelExecutionException) CxfComponent(org.apache.camel.component.cxf.CxfComponent) Interceptor(org.apache.cxf.interceptor.Interceptor) JAASLoginInterceptor(org.apache.cxf.interceptor.security.JAASLoginInterceptor)

Example 45 with Message

use of org.apache.cxf.message.Message in project wildfly-camel by wildfly-extras.

the class CXFWSInterceptorTest method testCXFInterceptor.

@Test
public void testCXFInterceptor() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    CamelContext camelctx = new DefaultCamelContext();
    CxfComponent component = new CxfComponent(camelctx);
    CxfEndpoint cxfEndpoint = new CxfEndpoint("http://localhost:8080/EndpointService/EndpointPort", component);
    cxfEndpoint.setServiceClass(Endpoint.class);
    List<Interceptor<? extends Message>> inInterceptors = cxfEndpoint.getInInterceptors();
    inInterceptors.add(new CountDownInterceptor(latch));
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from(cxfEndpoint).setBody(constant("Hello ${body}"));
        }
    });
    camelctx.start();
    try {
        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);
        endpoint.echo("Kermit");
        Assert.assertTrue("Gave up waiting for CXF interceptor handleMessage", latch.await(5, TimeUnit.SECONDS));
    } finally {
        camelctx.stop();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) Message(org.apache.cxf.message.Message) RouteBuilder(org.apache.camel.builder.RouteBuilder) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) CxfEndpoint(org.apache.camel.component.cxf.CxfEndpoint) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) URL(java.net.URL) Endpoint(org.wildfly.camel.test.common.types.Endpoint) CxfEndpoint(org.apache.camel.component.cxf.CxfEndpoint) CxfComponent(org.apache.camel.component.cxf.CxfComponent) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) Test(org.junit.Test)

Aggregations

Message (org.apache.cxf.message.Message)1002 Test (org.junit.Test)507 MessageImpl (org.apache.cxf.message.MessageImpl)291 Exchange (org.apache.cxf.message.Exchange)199 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)169 Endpoint (org.apache.cxf.endpoint.Endpoint)91 Interceptor (org.apache.cxf.interceptor.Interceptor)87 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)85 ArrayList (java.util.ArrayList)83 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)76 List (java.util.List)75 IOException (java.io.IOException)73 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)73 Method (java.lang.reflect.Method)69 Bus (org.apache.cxf.Bus)69 QName (javax.xml.namespace.QName)62 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)55 HashMap (java.util.HashMap)53 Fault (org.apache.cxf.interceptor.Fault)51 ByteArrayInputStream (java.io.ByteArrayInputStream)49