Search in sources :

Example 16 with DispatchImpl

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());
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) AddressingFeature(javax.xml.ws.soap.AddressingFeature) ServiceImpl(org.apache.cxf.jaxws.ServiceImpl) DispatchImpl(org.apache.cxf.jaxws.DispatchImpl) Document(org.w3c.dom.Document) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) MessageReplayObserver(org.apache.cxf.jaxws.MessageReplayObserver) Test(org.junit.Test) AbstractJaxWsTest(org.apache.cxf.jaxws.AbstractJaxWsTest)

Example 17 with DispatchImpl

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;
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) AddressingFeature(javax.xml.ws.soap.AddressingFeature) DispatchImpl(org.apache.cxf.jaxws.DispatchImpl) Service(javax.xml.ws.Service) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source)

Example 18 with DispatchImpl

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();
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) QName(javax.xml.namespace.QName) DispatchImpl(org.apache.cxf.jaxws.DispatchImpl) Element(org.w3c.dom.Element) Service(javax.xml.ws.Service) Document(org.w3c.dom.Document) Client(org.apache.cxf.endpoint.Client) URL(java.net.URL)

Example 19 with DispatchImpl

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);
        }
    }
}
Also used : Bus(org.apache.cxf.Bus) Endpoint(org.apache.cxf.endpoint.Endpoint) DispatchImpl(org.apache.cxf.jaxws.DispatchImpl) WSS4JInInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Client(org.apache.cxf.endpoint.Client) WebClient(org.apache.cxf.jaxrs.client.WebClient) WSS4JInInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) Subject(javax.security.auth.Subject)

Example 20 with DispatchImpl

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;
}
Also used : JMSConfiguration(org.apache.cxf.transport.jms.JMSConfiguration) DispatchImpl(org.apache.cxf.jaxws.DispatchImpl) QName(javax.xml.namespace.QName) 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