Search in sources :

Example 1 with HttpException

use of com.adaptris.http.HttpException in project interlok by adaptris.

the class HttpsProduceConnection method initialiseClient.

/**
 * @see HttpClientConnection#initialiseClient(java.lang.String)
 */
@Override
public HttpClientTransport initialiseClient(String url) throws HttpException {
    HttpsClient client = new HttpsClient(url);
    try {
        if (keystore != null) {
            KeystoreFactory ksf = KeystoreFactory.getDefault();
            KeystoreLocation ksl = null;
            if (keystorePassword != null) {
                ksl = ksf.create(keystore, Password.decode(keystorePassword).toCharArray());
            } else {
                ksl = ksf.create(keystore);
            }
            char[] pkpw = PasswordOverride.discoverPrivateKeyPassword(ksl, getPrivateKeyPasswordProvider());
            if (pkpw != null) {
                client.registerPrivateKeyPassword(pkpw);
            }
            client.registerKeystore(ksf.create(ksl));
        }
    } catch (AdaptrisSecurityException e) {
        throw new HttpException(e);
    }
    client.setAlwaysTrust(alwaysTrust);
    return client;
}
Also used : KeystoreLocation(com.adaptris.security.keystore.KeystoreLocation) HttpsClient(com.adaptris.http.HttpsClient) AdaptrisSecurityException(com.adaptris.security.exc.AdaptrisSecurityException) KeystoreFactory(com.adaptris.security.keystore.KeystoreFactory) HttpException(com.adaptris.http.HttpException)

Example 2 with HttpException

use of com.adaptris.http.HttpException in project interlok by adaptris.

the class SimpleHttpProducer method doRequest.

@Override
protected AdaptrisMessage doRequest(AdaptrisMessage msg, String destination, long timeout) throws ProduceException {
    AdaptrisMessage reply = defaultIfNull(getMessageFactory()).newMessage();
    OutputStream out = null;
    try {
        HttpClientConnection c = retrieveConnection(HttpClientConnection.class);
        HttpClientTransport client = c.initialiseClient(destination);
        client.setMethod(getMethod());
        HttpMessage m = HttpMessageFactory.getDefaultInstance().create();
        applyHeaders(getAdditionalHeaders(msg), m);
        if (getContentTypeKey() != null && msg.containsKey(getContentTypeKey())) {
            m.getHeaders().put(Http.CONTENT_TYPE, msg.getMetadataValue(getContentTypeKey()));
        }
        if (getAuthorisation() != null) {
            m.getHeaders().put(Http.AUTHORIZATION, getAuthorisation());
        }
        if (getEncoder() != null) {
            getEncoder().writeMessage(msg, m);
        } else {
            out = m.getOutputStream();
            out.write(msg.getPayload());
            out.flush();
        }
        HttpSession httpSession = client.send(m, new Long(timeout).intValue(), handleRedirection());
        readResponse(httpSession, reply);
        httpSession.close();
    } catch (HttpException e) {
        throw new ProduceException(e);
    } catch (IOException e) {
        throw new ProduceException(e);
    } catch (CoreException e) {
        throw new ProduceException(e);
    }
    return reply;
}
Also used : HttpClientTransport(com.adaptris.http.HttpClientTransport) CoreException(com.adaptris.core.CoreException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) HttpSession(com.adaptris.http.HttpSession) OutputStream(java.io.OutputStream) HttpException(com.adaptris.http.HttpException) IOException(java.io.IOException) HttpMessage(com.adaptris.http.HttpMessage) ProduceException(com.adaptris.core.ProduceException)

Example 3 with HttpException

use of com.adaptris.http.HttpException in project interlok by adaptris.

the class VersionedHttpsProduceConnection method initialiseClient.

/**
 * @see HttpClientConnection#initialiseClient(java.lang.String)
 */
@Override
public HttpClientTransport initialiseClient(String url) throws HttpException {
    HttpsClient client = new HttpsClient(new URLString(url), protocolVersion);
    try {
        if (getKeystore() != null) {
            KeystoreFactory ksf = KeystoreFactory.getDefault();
            KeystoreLocation ksl = null;
            if (getKeystorePassword() != null) {
                ksl = ksf.create(getKeystore(), Password.decode(getKeystorePassword()).toCharArray());
            } else {
                ksl = ksf.create(getKeystore());
            }
            char[] pkpw = PasswordOverride.discoverPrivateKeyPassword(ksl, getPrivateKeyPasswordProvider());
            if (pkpw != null) {
                client.registerPrivateKeyPassword(pkpw);
            }
            client.registerKeystore(ksf.create(ksl));
        }
    } catch (AdaptrisSecurityException e) {
        throw new HttpException(e);
    }
    client.setAlwaysTrust(getAlwaysTrust());
    return client;
}
Also used : KeystoreLocation(com.adaptris.security.keystore.KeystoreLocation) HttpsClient(com.adaptris.http.HttpsClient) AdaptrisSecurityException(com.adaptris.security.exc.AdaptrisSecurityException) KeystoreFactory(com.adaptris.security.keystore.KeystoreFactory) HttpException(com.adaptris.http.HttpException) URLString(com.adaptris.util.URLString)

Aggregations

HttpException (com.adaptris.http.HttpException)3 HttpsClient (com.adaptris.http.HttpsClient)2 AdaptrisSecurityException (com.adaptris.security.exc.AdaptrisSecurityException)2 KeystoreFactory (com.adaptris.security.keystore.KeystoreFactory)2 KeystoreLocation (com.adaptris.security.keystore.KeystoreLocation)2 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1 CoreException (com.adaptris.core.CoreException)1 ProduceException (com.adaptris.core.ProduceException)1 HttpClientTransport (com.adaptris.http.HttpClientTransport)1 HttpMessage (com.adaptris.http.HttpMessage)1 HttpSession (com.adaptris.http.HttpSession)1 URLString (com.adaptris.util.URLString)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1