use of java.security.KeyManagementException in project camel by apache.
the class ExceptionBuilderTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@SuppressWarnings("unchecked")
public void configure() throws Exception {
errorHandler(deadLetterChannel("mock:error").redeliveryDelay(0).maximumRedeliveries(3));
// START SNIPPET: exceptionBuilder1
onException(NullPointerException.class).maximumRedeliveries(0).setHeader(MESSAGE_INFO, constant("Damm a NPE")).to(ERROR_QUEUE);
onException(IOException.class).redeliveryDelay(100L).maximumRedeliveries(3).maximumRedeliveryDelay(30 * 1000L).backOffMultiplier(1.0).useExponentialBackOff().setHeader(MESSAGE_INFO, constant("Damm somekind of IO exception")).to(ERROR_QUEUE);
onException(Exception.class).redeliveryDelay(100L).maximumRedeliveries(2).setHeader(MESSAGE_INFO, constant("Damm just exception")).to(ERROR_QUEUE);
onException(MyBaseBusinessException.class).redeliveryDelay(100L).maximumRedeliveries(3).setHeader(MESSAGE_INFO, constant("Damm my business is not going to well")).to(BUSINESS_ERROR_QUEUE);
onException(GeneralSecurityException.class, KeyException.class).maximumRedeliveries(1).setHeader(MESSAGE_INFO, constant("Damm some security error")).to(SECURITY_ERROR_QUEUE);
onException(InstantiationException.class, IllegalAccessException.class, ClassNotFoundException.class).maximumRedeliveries(0).setHeader(MESSAGE_INFO, constant("Damm some access error")).to(ERROR_QUEUE);
// END SNIPPET: exceptionBuilder1
from("direct:a").process(new Processor() {
public void process(Exchange exchange) throws Exception {
String s = exchange.getIn().getBody(String.class);
if ("Hello NPE".equals(s)) {
throw new NullPointerException();
} else if ("Hello IO".equals(s)) {
throw new ConnectException("Forced for testing - cannot connect to remote server");
} else if ("Hello Exception".equals(s)) {
throw new CamelExchangeException("Forced for testing", exchange);
} else if ("Hello business".equals(s)) {
throw new MyBusinessException();
} else if ("I am not allowed to do this".equals(s)) {
throw new KeyManagementException();
} else if ("I am not allowed to access this".equals(s)) {
throw new IllegalAccessException();
}
exchange.getOut().setBody("Hello World");
}
}).to("mock:result");
}
};
}
use of java.security.KeyManagementException in project AndroidNetworkDemo by dodocat.
the class RequestManager method newRequestQueue.
private RequestQueue newRequestQueue(Context context) {
RequestQueue requestQueue;
try {
String[] hosts = { "kyfw.12306.cn" };
int[] certRes = { R.raw.kyfw };
String[] certPass = { "asdfqaz" };
socketFactoryMap = new Hashtable<>(hosts.length);
for (int i = 0; i < certRes.length; i++) {
int res = certRes[i];
String password = certPass[i];
SSLSocketFactory sslSocketFactory = createSSLSocketFactory(context, res, password);
socketFactoryMap.put(hosts[i], sslSocketFactory);
}
HurlStack stack = new SelfSignSslOkHttpStack(socketFactoryMap);
requestQueue = Volley.newRequestQueue(context, stack);
requestQueue.start();
} catch (KeyStoreException | CertificateException | NoSuchAlgorithmException | KeyManagementException | IOException e) {
throw new RuntimeException(e);
}
return requestQueue;
}
use of java.security.KeyManagementException in project android_frameworks_base by ParanoidAndroid.
the class SSLCertificateSocketFactory method makeSocketFactory.
private SSLSocketFactory makeSocketFactory(KeyManager[] keyManagers, TrustManager[] trustManagers) {
try {
OpenSSLContextImpl sslContext = new OpenSSLContextImpl();
sslContext.engineInit(keyManagers, trustManagers, null);
sslContext.engineGetClientSessionContext().setPersistentCache(mSessionCache);
return sslContext.engineGetSocketFactory();
} catch (KeyManagementException e) {
Log.wtf(TAG, e);
// Fallback
return (SSLSocketFactory) SSLSocketFactory.getDefault();
}
}
use of java.security.KeyManagementException in project sonarqube by SonarSource.
the class HttpsTrustTest method failOnError.
@Test
public void failOnError() throws Exception {
HttpsTrust.Ssl context = mock(HttpsTrust.Ssl.class);
KeyManagementException cause = new KeyManagementException("foo");
when(context.newFactory(any(TrustManager.class))).thenThrow(cause);
try {
new HttpsTrust(context);
fail();
} catch (IllegalStateException e) {
assertThat(e.getMessage()).isEqualTo("Fail to build SSL factory");
assertThat(e.getCause()).isSameAs(cause);
}
}
use of java.security.KeyManagementException in project OpenAttestation by OpenAttestation.
the class Pkcs12 method setRsaCredentialX509.
/**
* Replaces an existing keypair with the same alias or adds a new keypair
* if one did not already exist.
*
* The chain is optional and if provided it must be the certificates that
* signed the credential's public key, in order, with the Root CA being LAST.
*
* @param key
* @param chain
* @param alias
* @param keyPassword
*/
public void setRsaCredentialX509(RsaCredentialX509 key, X509Certificate[] chain, String alias, String keyPassword) throws KeyManagementException {
try {
List<String> aliases = Collections.list(keystore.aliases());
if (aliases.contains(alias)) {
keystore.deleteEntry(alias);
}
X509Certificate[] chain1;
if (chain != null) {
chain1 = new X509Certificate[chain.length + 1];
chain1[0] = key.getCertificate();
System.arraycopy(chain, 0, chain1, 1, chain.length);
} else {
chain1 = new X509Certificate[] { key.getCertificate() };
}
keystore.setKeyEntry(alias, key.getPrivateKey(), keyPassword.toCharArray(), chain1);
} catch (KeyStoreException e) {
throw new KeyManagementException("Cannot add credential", e);
}
}
Aggregations