use of org.apache.cxf.jaxws.DispatchImpl in project jbossws-cxf by jbossws.
the class Helper method testDefaultClientConfigurationOnDispatch.
public boolean testDefaultClientConfigurationOnDispatch() throws Exception {
final URL wsdlURL = new URL(address + "?wsdl");
final ClientConfig defaultClientConfig = TestUtils.getAndVerifyDefaultClientConfiguration();
// -- modify default conf --
try {
final Map<String, String> props = new HashMap<String, String>();
props.put("propA", "valueA");
TestUtils.registerClientConfigAndReload(new ClientConfig(defaultClientConfig.getConfigName(), null, null, props, null));
// --
Service service = Service.create(wsdlURL, serviceName);
Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class, Mode.MESSAGE);
return (((DispatchImpl<SOAPMessage>) dispatch).getClient().getEndpoint().get("propA").equals("valueA"));
} finally {
// -- restore default conf --
TestUtils.registerClientConfigAndReload(defaultClientConfig);
// --
}
}
use of org.apache.cxf.jaxws.DispatchImpl in project cxf by apache.
the class SymmetricBindingTest method testUsernameTokenSAML2Dispatch.
@org.junit.Test
public void testUsernameTokenSAML2Dispatch() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = SymmetricBindingTest.class.getResource("cxf-client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = SymmetricBindingTest.class.getResource("DoubleIt.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItSymmetricSAML2Port");
Dispatch<DOMSource> dispatch = service.createDispatch(portQName, DOMSource.class, Service.Mode.PAYLOAD, new AddressingFeature());
updateAddressPort(dispatch, test.getPort());
// Setup STSClient
STSClient stsClient = createDispatchSTSClient(bus);
String wsdlLocation = "http://localhost:" + test.getStsPort() + "/SecurityTokenService/UT?wsdl";
stsClient.setWsdlLocation(wsdlLocation);
// Creating a DOMSource Object for the request
DOMSource request = createDOMRequest();
// Make a successful request
Client client = ((DispatchImpl<DOMSource>) dispatch).getClient();
client.getRequestContext().put(SecurityConstants.STS_CLIENT, stsClient);
if (test.isStreaming()) {
client.getRequestContext().put(SecurityConstants.ENABLE_STREAMING_SECURITY, "true");
client.getResponseContext().put(SecurityConstants.ENABLE_STREAMING_SECURITY, "true");
}
DOMSource response = dispatch.invoke(request);
assertNotNull(response);
bus.shutdown(true);
}
use of org.apache.cxf.jaxws.DispatchImpl in project cxf by apache.
the class DispatchClientServerTest method testTimeout.
@Test
public void testTimeout() throws Exception {
// CXF-2384
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(wsdl);
// pick one of the other service/ports that would have an address
// without a service running
QName otherServiceName = new QName("http://apache.org/hello_world_soap_http", "SOAPProviderService");
QName otherPortName = new QName("http://apache.org/hello_world_soap_http", "SoapProviderPort");
SOAPService service = new SOAPService(wsdl, otherServiceName);
assertNotNull(service);
Dispatch<SOAPMessage> disp = service.createDispatch(otherPortName, SOAPMessage.class, Service.Mode.MESSAGE);
disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + TestUtil.getPortNumber("fake-port") + "/SOAPDispatchService/SoapDispatchPort");
DispatchImpl<?> dispImpl = (DispatchImpl<?>) disp;
HTTPConduit cond = (HTTPConduit) dispImpl.getClient().getConduit();
cond.getClient().setConnectionTimeout(500);
InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
SOAPMessage soapReqMsg = MessageFactory.newInstance().createMessage(null, is);
assertNotNull(soapReqMsg);
try {
disp.invoke(soapReqMsg);
fail("Should have faulted");
} catch (SOAPFaultException ex) {
fail("should not be a SOAPFaultException");
} catch (WebServiceException ex) {
// expected
assertTrue(ex.getCause().getClass().getName(), ex.getCause() instanceof java.net.ConnectException || ex.getCause() instanceof java.net.SocketTimeoutException);
}
dispImpl.close();
}
use of org.apache.cxf.jaxws.DispatchImpl in project cxf by apache.
the class ActionTest method testSignatureDispatchMessage.
@org.junit.Test
public void testSignatureDispatchMessage() 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.MESSAGE);
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 = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soap:Header></soap:Header><soap:Body>" + "<ns2:DoubleIt xmlns:ns2=\"http://www.example.org/schema/DoubleIt\">" + "<numberToDouble>25</numberToDouble></ns2:DoubleIt>" + "</soap:Body></soap:Envelope>";
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 DispatchOpTest method testResolveOperationWithSource.
@Test
public void testResolveOperationWithSource() throws Exception {
ServiceImpl service = new ServiceImpl(getBus(), getClass().getResource(wsdlResource), serviceName, null);
Dispatch<Source> disp = service.createDispatch(portName, Source.class, Service.Mode.PAYLOAD);
disp.getRequestContext().put(MessageContext.WSDL_OPERATION, operationName);
disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
d.setMessageObserver(new MessageReplayObserver(responseResource));
BindingOperationVerifier bov = new BindingOperationVerifier();
((DispatchImpl<?>) disp).getClient().getOutInterceptors().add(bov);
Document doc = StaxUtils.read(getResourceAsStream(requestResource));
DOMSource source = new DOMSource(doc);
Source res = disp.invoke(source);
assertNotNull(res);
BindingOperationInfo boi = bov.getBindingOperationInfo();
assertNotNull(boi);
assertEquals(operationName, boi.getName());
}
Aggregations