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;
}
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;
}
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;
}
Aggregations