use of org.apache.cxf.jaxws.DispatchImpl in project cxf by apache.
the class DispatchOpTest method testResolveOperationWithSourceAndWSA.
@Test
public void testResolveOperationWithSourceAndWSA() throws Exception {
ServiceImpl service = new ServiceImpl(getBus(), getClass().getResource(wsdlResource), serviceName, null, new AddressingFeature());
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());
}
use of org.apache.cxf.jaxws.DispatchImpl in project cxf by apache.
the class WSSecurityClientTest method createUsernameTokenDispatcher.
private static Dispatch<Source> createUsernameTokenDispatcher(boolean decoupled, String port) {
final Service service = Service.create(GREETER_SERVICE_QNAME);
service.addPort(USERNAME_TOKEN_PORT_QNAME, decoupled ? SOAPBinding.SOAP11HTTP_BINDING : HTTPBinding.HTTP_BINDING, "http://localhost:" + port + "/GreeterService/UsernameTokenPort");
final Dispatch<Source> dispatcher = service.createDispatch(USERNAME_TOKEN_PORT_QNAME, Source.class, Service.Mode.MESSAGE, new AddressingFeature(decoupled, decoupled));
final java.util.Map<String, Object> requestContext = dispatcher.getRequestContext();
requestContext.put(MessageContext.HTTP_REQUEST_METHOD, "POST");
if (decoupled) {
HTTPConduit cond = (HTTPConduit) ((DispatchImpl<?>) dispatcher).getClient().getConduit();
cond.getClient().setDecoupledEndpoint("http://localhost:" + DEC_PORT + "/decoupled");
}
return dispatcher;
}
use of org.apache.cxf.jaxws.DispatchImpl in project cxf by apache.
the class FaultTest method testSoap12Dispatch.
@org.junit.Test
public void testSoap12Dispatch() throws Exception {
createBus();
BusFactory.setDefaultBus(getBus());
URL wsdl = FaultTest.class.getResource("DoubleItFault.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItSoap12DispatchPort");
Dispatch<DOMSource> dispatch = service.createDispatch(portQName, DOMSource.class, Service.Mode.PAYLOAD);
// Creating a DOMSource Object for the request
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document requestDoc = db.newDocument();
Element root = requestDoc.createElementNS("http://www.example.org/schema/DoubleIt", "ns2:DoubleIt");
root.setAttributeNS(WSS4JConstants.XMLNS_NS, "xmlns:ns2", "http://www.example.org/schema/DoubleIt");
Element number = requestDoc.createElementNS(null, "numberToDouble");
number.setTextContent("25");
root.appendChild(number);
requestDoc.appendChild(root);
DOMSource request = new DOMSource(requestDoc);
// Add WS-Security configuration
Client client = ((DispatchImpl<DOMSource>) dispatch).getClient();
client.getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.ws.common.KeystorePasswordCallback");
client.getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES, "bob.properties");
client.getRequestContext().put(SecurityConstants.ENCRYPT_USERNAME, "bob");
updateAddressPort(dispatch, PORT);
// Make a successful request
client.getRequestContext().put(SecurityConstants.USERNAME, "alice");
DOMSource response = dispatch.invoke(request);
assertNotNull(response);
// Now make an invocation using another username
client.getRequestContext().put(SecurityConstants.USERNAME, "bob");
client.getRequestContext().put("security.password", "password");
try {
dispatch.invoke(request);
fail("Expected failure on bob");
} catch (Exception ex) {
assertTrue(ex.getMessage().contains("This is a fault"));
}
client.destroy();
}
use of org.apache.cxf.jaxws.DispatchImpl in project teiid by teiid.
the class WSConnectionImpl method configureWSSecurity.
private <T> void configureWSSecurity(Dispatch<T> dispatch) {
if (this.mcf.getAsSecurityType() == WSManagedConnectionFactory.SecurityType.WSSecurity) {
Bus bus = BusFactory.getThreadDefaultBus();
BusFactory.setThreadDefaultBus(this.mcf.getBus());
try {
Client client = ((DispatchImpl) dispatch).getClient();
Endpoint ep = client.getEndpoint();
// spring configuration file
if (this.mcf.getOutInterceptors() != null) {
for (Interceptor i : this.mcf.getOutInterceptors()) {
ep.getOutInterceptors().add(i);
}
}
// ws-security pass-thru from custom jaas domain
Subject subject = ConnectionContext.getSubject();
if (subject != null) {
WSSecurityCredential credential = ConnectionContext.getSecurityCredential(subject, WSSecurityCredential.class);
if (credential != null) {
if (credential.useSts()) {
dispatch.getRequestContext().put(SecurityConstants.STS_CLIENT, credential.buildStsClient(bus));
}
if (credential.getSecurityHandler() == WSSecurityCredential.SecurityHandler.WSS4J) {
ep.getOutInterceptors().add(new WSS4JOutInterceptor(credential.getRequestPropterties()));
ep.getInInterceptors().add(new WSS4JInInterceptor(credential.getResponsePropterties()));
} else if (credential.getSecurityHandler() == WSSecurityCredential.SecurityHandler.WSPOLICY) {
dispatch.getRequestContext().putAll(credential.getRequestPropterties());
dispatch.getResponseContext().putAll(credential.getResponsePropterties());
}
}
// When properties are set on subject treat them as they can configure WS-Security
HashMap<String, String> properties = ConnectionContext.getSecurityCredential(subject, HashMap.class);
for (String key : properties.keySet()) {
if (key.startsWith("ws-security.")) {
// $NON-NLS-1$
ep.put(key, properties.get(key));
}
}
}
} finally {
BusFactory.setThreadDefaultBus(bus);
}
}
}
use of org.apache.cxf.jaxws.DispatchImpl in project tesb-rt-se by Talend.
the class JmsConfigurator method create.
public static JmsConfigurator create(Dispatch<?> dispatch) {
if (!(dispatch instanceof DispatchImpl<?>)) {
return null;
}
DispatchImpl<?> dsp = (DispatchImpl<?>) dispatch;
Client cl = dsp.getClient();
final QName serviceName;
try {
serviceName = cl.getEndpoint().getService().getName();
} catch (Exception e) {
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.log(Level.FINER, "Exception caught: ", e);
}
return null;
}
if (serviceName == null) {
return null;
}
QName endpointName;
try {
endpointName = cl.getEndpoint().getEndpointInfo().getName();
} catch (Exception e) {
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.log(Level.FINER, "Exception caught: ", e);
}
endpointName = null;
}
final String portName = endpointName == null ? null : endpointName.getLocalPart();
JmsConfigurator result = new JmsConfigurator();
result.setConfigurationPrefix(portName);
result.setJmsConfiguration(new JMSConfiguration());
result.setServiceName(serviceName);
return result;
}
Aggregations