Search in sources :

Example 16 with ClientFactoryBean

use of org.apache.cxf.frontend.ClientFactoryBean in project camel by apache.

the class CxfConsumerTest method testInvokingServiceFromCXFClient.

// END SNIPPET: example
@Test
public void testInvokingServiceFromCXFClient() throws Exception {
    ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
    ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
    clientBean.setAddress(SIMPLE_ENDPOINT_ADDRESS);
    clientBean.setServiceClass(HelloService.class);
    clientBean.setBus(BusFactory.newInstance().createBus());
    HelloService client = (HelloService) proxyFactory.create();
    String result = client.echo(TEST_MESSAGE);
    assertEquals("We should get the echo string result from router", result, "echo " + TEST_MESSAGE);
    Boolean bool = client.echoBoolean(Boolean.TRUE);
    assertNotNull("The result should not be null", bool);
    assertEquals("We should get the echo boolean result from router ", bool.toString(), "true");
}
Also used : ClientFactoryBean(org.apache.cxf.frontend.ClientFactoryBean) ClientProxyFactoryBean(org.apache.cxf.frontend.ClientProxyFactoryBean) Test(org.junit.Test)

Example 17 with ClientFactoryBean

use of org.apache.cxf.frontend.ClientFactoryBean in project camel by apache.

the class CxfSpringEndpoint method createClient.

// Package private methods
// -------------------------------------------------------------------------
/**
     * Create a CXF Client
     */
@Override
Client createClient() throws Exception {
    // get service class
    Class<?> cls = getSEIClass();
    if (getDataFormat().equals(DataFormat.POJO)) {
        ObjectHelper.notNull(cls, CxfConstants.SERVICE_CLASS);
    }
    if (getWsdlURL() == null && cls == null) {
        // no WSDL and serviceClass specified, set our default serviceClass
        setServiceClass(org.apache.camel.component.cxf.DefaultSEI.class.getName());
        setDefaultOperationNamespace(CxfConstants.DISPATCH_NAMESPACE);
        setDefaultOperationName(CxfConstants.DISPATCH_DEFAULT_OPERATION_NAMESPACE);
        if (getDataFormat().equals(DataFormat.PAYLOAD)) {
            setSkipPayloadMessagePartCheck(true);
        }
        cls = getSEIClass();
    }
    if (cls != null) {
        // create client factory bean
        ClientFactoryBean factoryBean = createClientFactoryBean(cls);
        // setup client factory bean
        setupClientFactoryBean(factoryBean, cls);
        // fill in values that have not been filled.
        QName serviceQName = null;
        try {
            serviceQName = factoryBean.getServiceName();
        } catch (IllegalStateException e) {
        // It throws IllegalStateException if serviceName has not been set.
        }
        if (serviceQName == null && getServiceLocalName() != null) {
            factoryBean.setServiceName(new QName(getServiceNamespace(), getServiceLocalName()));
        }
        if (factoryBean.getEndpointName() == null && getEndpointLocalName() != null) {
            factoryBean.setEndpointName(new QName(getEndpointNamespace(), getEndpointLocalName()));
        }
        Client client = factoryBean.create();
        // setup the handlers
        setupHandlers(factoryBean, client);
        return client;
    } else {
        ClientFactoryBean factoryBean = createClientFactoryBean();
        // setup client factory bean
        setupClientFactoryBean(factoryBean, null);
        // fill in values that have not been filled.
        QName serviceQName = null;
        try {
            serviceQName = factoryBean.getServiceName();
        } catch (IllegalStateException e) {
        // It throws IllegalStateException if serviceName has not been set.
        }
        if (serviceQName == null && getServiceLocalName() != null) {
            factoryBean.setServiceName(new QName(getServiceNamespace(), getServiceLocalName()));
        }
        if (factoryBean.getEndpointName() == null && getEndpointLocalName() != null) {
            factoryBean.setEndpointName(new QName(getEndpointNamespace(), getEndpointLocalName()));
        }
        checkName(factoryBean.getEndpointName(), "endpoint/port name");
        checkName(factoryBean.getServiceName(), "service name");
        return factoryBean.create();
    }
}
Also used : ClientFactoryBean(org.apache.cxf.frontend.ClientFactoryBean) QName(javax.xml.namespace.QName) Client(org.apache.cxf.endpoint.Client)

Example 18 with ClientFactoryBean

use of org.apache.cxf.frontend.ClientFactoryBean in project camel by apache.

the class CxfHolderConsumerTest method testInvokingServiceWithSoapHeaderFromCXFClient.

@Test
public void testInvokingServiceWithSoapHeaderFromCXFClient() throws Exception {
    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
    clientBean.setAddress(ADDRESS);
    clientBean.setServiceClass(MyOrderEndpoint.class);
    MyOrderEndpoint client = (MyOrderEndpoint) proxyFactory.create();
    Holder<String> header = new Holder<String>();
    header.value = "parts";
    String result = client.mySecureOrder(1, header);
    assertEquals("Get a wrong order result", "Ordered ammount 1", result);
    assertEquals("Get a wrong parts", "secureParts", header.value);
}
Also used : ClientFactoryBean(org.apache.cxf.frontend.ClientFactoryBean) Holder(javax.xml.ws.Holder) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) Test(org.junit.Test)

Example 19 with ClientFactoryBean

use of org.apache.cxf.frontend.ClientFactoryBean in project camel by apache.

the class CxfHolderConsumerTest method testInvokingServiceFromCXFClient.

@Test
public void testInvokingServiceFromCXFClient() throws Exception {
    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
    clientBean.setAddress(ADDRESS);
    clientBean.setServiceClass(MyOrderEndpoint.class);
    MyOrderEndpoint client = (MyOrderEndpoint) proxyFactory.create();
    Holder<String> strPart = new Holder<String>();
    strPart.value = "parts";
    Holder<String> strCustomer = new Holder<String>();
    strCustomer.value = "";
    String result = client.myOrder(strPart, 2, strCustomer);
    assertEquals("Get a wrong order result", "Ordered ammount 2", result);
    assertEquals("Get a wrong parts", "parts", strPart.value);
    assertEquals("Get a wrong customer", "newCustomer", strCustomer.value);
}
Also used : ClientFactoryBean(org.apache.cxf.frontend.ClientFactoryBean) Holder(javax.xml.ws.Holder) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) Test(org.junit.Test)

Aggregations

ClientFactoryBean (org.apache.cxf.frontend.ClientFactoryBean)19 ClientProxyFactoryBean (org.apache.cxf.frontend.ClientProxyFactoryBean)11 Test (org.junit.Test)10 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)6 URL (java.net.URL)2 Holder (javax.xml.ws.Holder)2 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)2 Client (org.apache.cxf.endpoint.Client)2 IOException (java.io.IOException)1 QName (javax.xml.namespace.QName)1 CreditAgencyWS (org.apache.camel.loanbroker.credit.CreditAgencyWS)1 SoapFault (org.apache.cxf.binding.soap.SoapFault)1 Greeter (org.apache.cxf.greeter_control.Greeter)1 PingMeFault (org.apache.cxf.greeter_control.PingMeFault)1 LoggingOutInterceptor (org.apache.cxf.interceptor.LoggingOutInterceptor)1 JaxWsClientFactoryBean (org.apache.cxf.jaxws.JaxWsClientFactoryBean)1 Greeter (org.apache.hello_world_soap_http.Greeter)1