Search in sources :

Example 1 with HelloService

use of org.apache.cxf.service.factory.HelloService in project cxf by apache.

the class ClientServerTest method testClientServer.

@Test
public void testClientServer() {
    ctx = new ClassPathXmlApplicationContext(new String[] { "/org/apache/cxf/frontend/spring/rountrip.xml" });
    HelloService greeter = (HelloService) ctx.getBean("client");
    assertNotNull(greeter);
    String result = greeter.sayHello();
    assertEquals("We get the wrong sayHello result", "hello", result);
    Client c = ClientProxy.getClient(greeter);
    TestInterceptor out = new TestInterceptor();
    TestInterceptor in = new TestInterceptor();
    c.getRequestContext().put(Message.OUT_INTERCEPTORS, Arrays.asList(new Interceptor[] { out }));
    result = greeter.sayHello();
    assertTrue(out.wasCalled());
    out.reset();
    c.getRequestContext().put(Message.IN_INTERCEPTORS, Arrays.asList(new Interceptor[] { in }));
    result = greeter.sayHello();
    assertTrue(out.wasCalled());
    assertTrue(in.wasCalled());
    ctx.close();
    BusFactory.setDefaultBus(null);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) HelloService(org.apache.cxf.service.factory.HelloService) Client(org.apache.cxf.endpoint.Client) Interceptor(org.apache.cxf.interceptor.Interceptor) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) Test(org.junit.Test)

Example 2 with HelloService

use of org.apache.cxf.service.factory.HelloService in project cxf by apache.

the class SpringBeansTest method testClients.

@Test
public void testClients() throws Exception {
    AbstractFactoryBeanDefinitionParser.setFactoriesAreAbstract(false);
    ctx = new ClassPathXmlApplicationContext(new String[] { "/org/apache/cxf/frontend/spring/clients.xml" });
    Object bean = ctx.getBean("client1.proxyFactory");
    assertNotNull(bean);
    ClientProxyFactoryBean cpfbean = (ClientProxyFactoryBean) bean;
    BindingConfiguration bc = cpfbean.getBindingConfig();
    assertTrue(bc instanceof SoapBindingConfiguration);
    SoapBindingConfiguration sbc = (SoapBindingConfiguration) bc;
    assertTrue(sbc.getVersion() instanceof Soap12);
    HelloService greeter = (HelloService) ctx.getBean("client1");
    assertNotNull(greeter);
    Client client = ClientProxy.getClient(greeter);
    assertNotNull("expected ConduitSelector", client.getConduitSelector());
    assertTrue("unexpected ConduitSelector", client.getConduitSelector() instanceof NullConduitSelector);
    List<Interceptor<? extends Message>> inInterceptors = client.getInInterceptors();
    boolean saaj = false;
    boolean logging = false;
    for (Interceptor<? extends Message> i : inInterceptors) {
        if (i instanceof SAAJInInterceptor) {
            saaj = true;
        } else if (i instanceof LoggingInInterceptor) {
            logging = true;
        }
    }
    assertTrue(saaj);
    assertTrue(logging);
    saaj = false;
    logging = false;
    for (Interceptor<?> i : client.getOutInterceptors()) {
        if (i instanceof SAAJOutInterceptor) {
            saaj = true;
        } else if (i instanceof LoggingOutInterceptor) {
            logging = true;
        }
    }
    assertTrue(saaj);
    assertTrue(logging);
    ClientProxyFactoryBean clientProxyFactoryBean = (ClientProxyFactoryBean) ctx.getBean("client2.proxyFactory");
    assertNotNull(clientProxyFactoryBean);
    assertEquals("get the wrong transportId", clientProxyFactoryBean.getTransportId(), "http://cxf.apache.org/transports/local");
    assertEquals("get the wrong bindingId", clientProxyFactoryBean.getBindingId(), "http://cxf.apache.org/bindings/xformat");
    greeter = (HelloService) ctx.getBean("client2");
    assertNotNull(greeter);
    greeter = (HelloService) ctx.getBean("client3");
    assertNotNull(greeter);
    client = ClientProxy.getClient(greeter);
    EndpointInfo epi = client.getEndpoint().getEndpointInfo();
    AuthorizationPolicy ap = epi.getExtensor(AuthorizationPolicy.class);
    assertNotNull("The AuthorizationPolicy instance should not be null", ap);
    assertEquals("Get the wrong username", ap.getUserName(), "testUser");
    assertEquals("Get the wrong password", ap.getPassword(), "password");
}
Also used : Soap12(org.apache.cxf.binding.soap.Soap12) SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) Message(org.apache.cxf.message.Message) HelloService(org.apache.cxf.service.factory.HelloService) NullConduitSelector(org.apache.cxf.endpoint.NullConduitSelector) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) ClientProxyFactoryBean(org.apache.cxf.frontend.ClientProxyFactoryBean) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) Interceptor(org.apache.cxf.interceptor.Interceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) BindingConfiguration(org.apache.cxf.binding.BindingConfiguration) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) Test(org.junit.Test)

Aggregations

Client (org.apache.cxf.endpoint.Client)2 Interceptor (org.apache.cxf.interceptor.Interceptor)2 HelloService (org.apache.cxf.service.factory.HelloService)2 Test (org.junit.Test)2 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)2 BindingConfiguration (org.apache.cxf.binding.BindingConfiguration)1 Soap12 (org.apache.cxf.binding.soap.Soap12)1 SoapBindingConfiguration (org.apache.cxf.binding.soap.SoapBindingConfiguration)1 SAAJInInterceptor (org.apache.cxf.binding.soap.saaj.SAAJInInterceptor)1 SAAJOutInterceptor (org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor)1 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)1 NullConduitSelector (org.apache.cxf.endpoint.NullConduitSelector)1 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)1 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)1 ClientProxyFactoryBean (org.apache.cxf.frontend.ClientProxyFactoryBean)1 Message (org.apache.cxf.message.Message)1 AbstractPhaseInterceptor (org.apache.cxf.phase.AbstractPhaseInterceptor)1 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)1