Search in sources :

Example 11 with DispatchImpl

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);
    // --
    }
}
Also used : HashMap(java.util.HashMap) DispatchImpl(org.apache.cxf.jaxws.DispatchImpl) Service(javax.xml.ws.Service) ClientConfig(org.jboss.wsf.spi.metadata.config.ClientConfig) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL)

Example 12 with DispatchImpl

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);
}
Also used : Bus(org.apache.cxf.Bus) DOMSource(javax.xml.transform.dom.DOMSource) STSClient(org.apache.cxf.ws.security.trust.STSClient) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) AddressingFeature(javax.xml.ws.soap.AddressingFeature) QName(javax.xml.namespace.QName) DispatchImpl(org.apache.cxf.jaxws.DispatchImpl) Service(javax.xml.ws.Service) STSClient(org.apache.cxf.ws.security.trust.STSClient) Client(org.apache.cxf.endpoint.Client) URL(java.net.URL)

Example 13 with DispatchImpl

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();
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) WebServiceException(javax.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) DispatchImpl(org.apache.cxf.jaxws.DispatchImpl) InputStream(java.io.InputStream) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) SocketTimeoutException(java.net.SocketTimeoutException) Test(org.junit.Test)

Example 14 with DispatchImpl

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);
}
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 15 with DispatchImpl

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());
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) 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)

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