Search in sources :

Example 21 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project jbossws-cxf by jbossws.

the class SOAPConnectionImpl method get.

@Override
public SOAPMessage get(Object addressObject) throws SOAPException {
    checkClosed();
    String address = getAddress(addressObject);
    ConduitInitiator ci = getConduitInitiator(address);
    // create a new Message and Exchange
    EndpointInfo info = new EndpointInfo();
    info.setAddress(address);
    Message outMessage = new MessageImpl();
    Exchange exch = new ExchangeImpl();
    outMessage.setExchange(exch);
    // sent GET request
    try {
        // TODO verify bus
        final Conduit c = ci.getConduit(info, BusFactory.getThreadDefaultBus(false));
        if (c instanceof HTTPConduit) {
            ((HTTPConduit) c).getClient().setAutoRedirect(true);
        }
        outMessage.put(Message.HTTP_REQUEST_METHOD, "GET");
        c.prepare(outMessage);
        c.setMessageObserver(createMessageObserver(c));
        c.close(outMessage);
    } catch (Exception ex) {
        throw MESSAGES.getRequestCouldNotBeSent(ex);
    }
    // read SOAPMessage
    return readSoapMessage(exch);
}
Also used : Exchange(org.apache.cxf.message.Exchange) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Message(org.apache.cxf.message.Message) SOAPMessage(javax.xml.soap.SOAPMessage) Conduit(org.apache.cxf.transport.Conduit) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) SOAPException(javax.xml.soap.SOAPException) IOException(java.io.IOException)

Example 22 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project jbossws-cxf by jbossws.

the class AddressingTestCase method testDecoupledEndpointForLongLastingProcessingOfInvocations.

/**
 * This shows the usage of decoupled-endpoint for getting back response on a new http connection.
 * The CXF client basically creates a destination listening at the provided decoupled endpoint address, using the
 * configured http transport factory. The client gets back a HTTP 202 accept response message immediately after
 * the call to the server, then once the actual response comes back to the decoupled endpoint, the client is
 * notified and returns control to the application code.
 *
 * @throws Exception
 */
@Test
@RunAsClient
public void testDecoupledEndpointForLongLastingProcessingOfInvocations() throws Exception {
    final Bus bus = BusFactory.newInstance().createBus();
    BusFactory.setThreadDefaultBus(bus);
    try {
        // construct proxy
        QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/wsaddressing", "AddressingService");
        URL wsdlURL = new URL(baseURL + "/jaxws-samples-wsa/AddressingService?wsdl");
        Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
        ServiceIface proxy = (ServiceIface) service.getPort(ServiceIface.class);
        Client client = ClientProxy.getClient(proxy);
        HTTPConduit conduit = (HTTPConduit) client.getConduit();
        HTTPClientPolicy policy = conduit.getClient();
        // set low connection and receive timeouts to ensure the http client can't keep the connection open till the response is received
        // 5 secs
        policy.setConnectionTimeout(5000);
        // 10 secs
        policy.setReceiveTimeout(10000);
        try {
            // this takes at least 30 secs
            proxy.sayHello("Sleepy");
            fail("Timeout exception expected");
        } catch (WebServiceException e) {
            assertTrue(e.getCause() instanceof SocketTimeoutException);
        }
        policy.setDecoupledEndpoint("http://" + getServerHost() + ":18181/jaxws-samples-wsa/decoupled-endpoint");
        // this takes at least 30 secs... but now the client doesn't time out
        String response = proxy.sayHello("Sleepy");
        assertEquals("Hello Sleepy!", response);
    } finally {
        bus.shutdown(true);
    }
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) Bus(org.apache.cxf.Bus) SocketTimeoutException(java.net.SocketTimeoutException) WebServiceException(javax.xml.ws.WebServiceException) UseThreadBusFeature(org.jboss.wsf.stack.cxf.client.UseThreadBusFeature) QName(javax.xml.namespace.QName) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Service(javax.xml.ws.Service) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Client(org.apache.cxf.endpoint.Client) URL(java.net.URL) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 23 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project fabric8 by fabric8io.

the class WebClients method disableSslChecks.

public static void disableSslChecks(WebClient webClient) {
    HTTPConduit conduit = WebClient.getConfig(webClient).getHttpConduit();
    TLSClientParameters params = conduit.getTlsClientParameters();
    if (params == null) {
        params = new TLSClientParameters();
        conduit.setTlsClientParameters(params);
    }
    params.setTrustManagers(new TrustManager[] { new TrustEverythingSSLTrustManager() });
    params.setDisableCNCheck(true);
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) TrustEverythingSSLTrustManager(io.fabric8.utils.ssl.TrustEverythingSSLTrustManager)

Example 24 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project fabric8 by fabric8io.

the class WebClients method configureUserAndPassword.

public static void configureUserAndPassword(WebClient webClient, String username, String password) {
    if (Strings.isNotBlank(username) && Strings.isNotBlank(password)) {
        HTTPConduit conduit = WebClient.getConfig(webClient).getHttpConduit();
        conduit.getAuthorization().setUserName(username);
        conduit.getAuthorization().setPassword(password);
    }
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit)

Example 25 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project fabric8 by fabric8io.

the class WebClients method configureClientCert.

public static void configureClientCert(WebClient webClient, String clientCertData, File clientCertFile, String clientKeyData, File clientKeyFile, String clientKeyAlgo, char[] clientKeyPassword) {
    try {
        KeyStore keyStore = createKeyStore(clientCertData, clientCertFile, clientKeyData, clientKeyFile, clientKeyAlgo, clientKeyPassword);
        KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        keyManagerFactory.init(keyStore, clientKeyPassword);
        KeyManager[] keyManagers = keyManagerFactory.getKeyManagers();
        HTTPConduit conduit = WebClient.getConfig(webClient).getHttpConduit();
        TLSClientParameters params = conduit.getTlsClientParameters();
        if (params == null) {
            params = new TLSClientParameters();
            conduit.setTlsClientParameters(params);
        }
        KeyManager[] existingKeyManagers = params.getKeyManagers();
        if (existingKeyManagers != null && existingKeyManagers.length > 0) {
            List<KeyManager> list = new ArrayList<>();
            list.addAll(Arrays.asList(existingKeyManagers));
            list.addAll(Arrays.asList(keyManagers));
            keyManagers = list.toArray(new KeyManager[list.size()]);
        }
        params.setKeyManagers(keyManagers);
    } catch (Exception e) {
        LOG.error("Could not create key manager for " + clientCertFile + " (" + clientKeyFile + ")", e);
    }
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) ArrayList(java.util.ArrayList) KeyStore(java.security.KeyStore) KeyManager(javax.net.ssl.KeyManager) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Aggregations

HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)158 Client (org.apache.cxf.endpoint.Client)65 Test (org.junit.Test)60 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)52 URL (java.net.URL)43 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)43 Bus (org.apache.cxf.Bus)36 QName (javax.xml.namespace.QName)24 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)23 KeyStore (java.security.KeyStore)21 Greeter (org.apache.hello_world.Greeter)21 SOAPService (org.apache.hello_world.services.SOAPService)21 Service (javax.xml.ws.Service)18 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)17 InputStream (java.io.InputStream)15 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)15 IOException (java.io.IOException)13 ExecutionException (java.util.concurrent.ExecutionException)13 TrustManager (javax.net.ssl.TrustManager)13 WebClient (org.apache.cxf.jaxrs.client.WebClient)11