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);
}
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();
}
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());
}
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);
}
}
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();
}
}
Aggregations