Search in sources :

Example 6 with DispatchImpl

use of org.apache.cxf.jaxws.DispatchImpl in project cxf by apache.

the class ActionTest method testSignatureDispatchPayload.

@org.junit.Test
public void testSignatureDispatchPayload() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = ActionTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = ActionTest.class.getResource("DoubleItAction.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSignatureConfigPort");
    Dispatch<StreamSource> dispatch = service.createDispatch(portQName, StreamSource.class, Service.Mode.PAYLOAD);
    updateAddressPort(dispatch, PORT);
    // Programmatic interceptor
    Map<String, Object> props = new HashMap<>();
    props.put(ConfigurationConstants.ACTION, "Signature");
    props.put(ConfigurationConstants.SIGNATURE_USER, "alice");
    props.put(ConfigurationConstants.PW_CALLBACK_REF, new KeystorePasswordCallback());
    props.put(ConfigurationConstants.SIG_KEY_ID, "DirectReference");
    props.put(ConfigurationConstants.SIG_PROP_FILE, "alice.properties");
    WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(props);
    Client client = ((DispatchImpl<StreamSource>) dispatch).getClient();
    client.getOutInterceptors().add(outInterceptor);
    String payload = "<ns2:DoubleIt xmlns:ns2=\"http://www.example.org/schema/DoubleIt\">" + "<numberToDouble>25</numberToDouble></ns2:DoubleIt>";
    StreamSource request = new StreamSource(new StringReader(payload));
    StreamSource response = dispatch.invoke(request);
    assertNotNull(response);
    Document doc = StaxUtils.read(response.getInputStream());
    assertEquals("50", doc.getElementsByTagNameNS(null, "doubledNumber").item(0).getTextContent());
    ((java.io.Closeable) dispatch).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) DispatchImpl(org.apache.cxf.jaxws.DispatchImpl) StreamSource(javax.xml.transform.stream.StreamSource) Service(javax.xml.ws.Service) Document(org.w3c.dom.Document) URL(java.net.URL) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) StringReader(java.io.StringReader) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Client(org.apache.cxf.endpoint.Client) KeystorePasswordCallback(org.apache.cxf.systest.ws.common.KeystorePasswordCallback)

Example 7 with DispatchImpl

use of org.apache.cxf.jaxws.DispatchImpl in project cxf by apache.

the class SignatureWhitespaceTest method testTrailingWhitespaceInSOAPBody.

@org.junit.Test
public void testTrailingWhitespaceInSOAPBody() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SignatureWhitespaceTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = SignatureWhitespaceTest.class.getResource("DoubleItAction.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSignaturePort2");
    Dispatch<StreamSource> dispatch = service.createDispatch(portQName, StreamSource.class, Service.Mode.MESSAGE);
    Client client = ((DispatchImpl<StreamSource>) dispatch).getClient();
    HTTPConduit http = (HTTPConduit) client.getConduit();
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout(0);
    httpClientPolicy.setReceiveTimeout(0);
    http.setClient(httpClientPolicy);
    // Creating a DOMSource Object for the request
    URL requestFile = SignatureWhitespaceTest.class.getResource("request-with-trailing-whitespace.xml");
    StreamSource request = new StreamSource(new File(requestFile.getPath()));
    updateAddressPort(dispatch, test.getPort());
    // Make a successful request
    StreamSource response = dispatch.invoke(request);
    assertNotNull(response);
    Document doc = StaxUtils.read(response.getInputStream());
    assertEquals("50", doc.getElementsByTagNameNS(null, "doubledNumber").item(0).getTextContent());
    ((java.io.Closeable) dispatch).close();
}
Also used : Bus(org.apache.cxf.Bus) QName(javax.xml.namespace.QName) DispatchImpl(org.apache.cxf.jaxws.DispatchImpl) StreamSource(javax.xml.transform.stream.StreamSource) Service(javax.xml.ws.Service) Document(org.w3c.dom.Document) URL(java.net.URL) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Client(org.apache.cxf.endpoint.Client) File(java.io.File)

Example 8 with DispatchImpl

use of org.apache.cxf.jaxws.DispatchImpl in project tesb-rt-se by Talend.

the class JmsUriConfiguratorTest method testCreateDispatch.

@Test
public void testCreateDispatch() {
    Service service = Service.create(SERVICE_NAME);
    service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, ADDRESS);
    Dispatch<Source> dispatch = service.createDispatch(PORT_NAME, Source.class, Service.Mode.PAYLOAD);
    Assert.assertNotNull(dispatch);
    JmsUriConfigurator conf = JmsUriConfigurator.create(dispatch);
    Assert.assertNotNull(conf);
    try {
        System.out.println(conf.createJmsAddress());
    } catch (Throwable t) {
        t.printStackTrace();
    }
    Assert.assertEquals("jms:jndi:dynamicQueues/libraryprovider.queue?jndiConnectionFactoryName=ConnectionFactory&jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory&jndiURL=tcp://localhost:61616", conf.getJmsAddress());
    dispatch = conf.configureDispatch(dispatch);
    Assert.assertNotNull(dispatch);
    Client cl = ((DispatchImpl<Source>) dispatch).getClient();
    Assert.assertEquals("jms:jndi:dynamicQueues/libraryprovider.queue?jndiConnectionFactoryName=ConnectionFactory&jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory&jndiURL=tcp://localhost:61616", cl.getRequestContext().get(Message.ENDPOINT_ADDRESS));
    Assert.assertEquals("jms:jndi:dynamicQueues/libraryprovider.queue?jndiConnectionFactoryName=ConnectionFactory&jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory&jndiURL=tcp://localhost:61616", cl.getEndpoint().getEndpointInfo().getAddress());
}
Also used : JmsUriConfigurator(org.talend.esb.mep.requestcallback.beans.JmsUriConfigurator) DispatchImpl(org.apache.cxf.jaxws.DispatchImpl) Service(javax.xml.ws.Service) Client(org.apache.cxf.endpoint.Client) Source(javax.xml.transform.Source) Test(org.junit.Test)

Example 9 with DispatchImpl

use of org.apache.cxf.jaxws.DispatchImpl in project tesb-rt-se by Talend.

the class CallContext method setupDispatch.

public static void setupDispatch(final Dispatch<?> dispatch) {
    if (!(dispatch instanceof DispatchImpl)) {
        throw new IllegalArgumentException("Only CXF JAX-WS Dispatch supported. ");
    }
    final DispatchImpl<?> dsp = (DispatchImpl<?>) dispatch;
    final Client dispatchClient = dsp.getClient();
    final Bus bus = dispatchClient.getBus();
    (new RequestCallbackFeature()).initialize(dispatchClient, bus);
    if (logging) {
        (new LoggingFeature()).initialize(dispatchClient, bus);
    }
    if (serviceActivityMonitoring) {
        getEventFeature().initialize(dispatchClient, bus);
    }
}
Also used : Bus(org.apache.cxf.Bus) DispatchImpl(org.apache.cxf.jaxws.DispatchImpl) LoggingFeature(org.apache.cxf.feature.LoggingFeature) Client(org.apache.cxf.endpoint.Client)

Example 10 with DispatchImpl

use of org.apache.cxf.jaxws.DispatchImpl in project jbossws-cxf by jbossws.

the class CXFClientConfigurer method setConfigProperties.

protected void setConfigProperties(Object client, ClientConfig config) {
    Client cxfClient;
    if (client instanceof DispatchImpl<?>) {
        cxfClient = ((DispatchImpl<?>) client).getClient();
    } else {
        cxfClient = ClientProxy.getClient(client);
    }
    cleanupPreviousProps(cxfClient);
    Map<String, String> props = config.getProperties();
    if (props != null && !props.isEmpty()) {
        savePropList(cxfClient, props);
    }
    setConfigProperties(cxfClient, props);
    // config jaspi
    JASPIAuthenticationProvider japsiProvider = (JASPIAuthenticationProvider) ServiceLoader.loadService(JASPIAuthenticationProvider.class.getName(), null, ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader());
    if (japsiProvider != null) {
        japsiProvider.enableClientAuthentication(cxfClient, props);
    } else {
        Loggers.SECURITY_LOGGER.cannotFindJaspiClasses();
    }
}
Also used : DispatchImpl(org.apache.cxf.jaxws.DispatchImpl) JASPIAuthenticationProvider(org.jboss.wsf.spi.security.JASPIAuthenticationProvider) Client(org.apache.cxf.endpoint.Client)

Aggregations

DispatchImpl (org.apache.cxf.jaxws.DispatchImpl)24 Client (org.apache.cxf.endpoint.Client)18 QName (javax.xml.namespace.QName)12 Service (javax.xml.ws.Service)12 URL (java.net.URL)10 Bus (org.apache.cxf.Bus)9 DOMSource (javax.xml.transform.dom.DOMSource)8 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)7 Document (org.w3c.dom.Document)7 Test (org.junit.Test)6 Source (javax.xml.transform.Source)5 StreamSource (javax.xml.transform.stream.StreamSource)5 AddressingFeature (javax.xml.ws.soap.AddressingFeature)4 STSClient (org.apache.cxf.ws.security.trust.STSClient)4 HashMap (java.util.HashMap)3 AbstractJaxWsTest (org.apache.cxf.jaxws.AbstractJaxWsTest)3 MessageReplayObserver (org.apache.cxf.jaxws.MessageReplayObserver)3 ServiceImpl (org.apache.cxf.jaxws.ServiceImpl)3 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)3 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)3