List of usage examples for java.security KeyManagementException printStackTrace
public void printStackTrace()
From source file:portal.api.osm.client.OSMClient.java
private CloseableHttpClient returnHttpClient() { try {/* w w w . j a v a2s. c om*/ HttpClientBuilder h = HttpClientBuilder.create(); SSLContext sslContext; sslContext = new SSLContextBuilder().loadTrustMaterial(null, (certificate, authType) -> true).build(); CloseableHttpClient httpclient = HttpClients.custom().setSSLContext(sslContext) .setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); return httpclient; } catch (KeyManagementException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (KeyStoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:com.microfocus.application.automation.tools.srf.run.RunFromSrfBuilder.java
private void initSrfEventListener() throws IOException, IllegalArgumentException, SrfException, AuthorizationException { // !!! Important Notice !!! // by using 'level=session' in the sse request we're ensuring that we'll get only events related // to this run since we're creating a new session (token) for each run String urlSSe = _ftaasServerAddress.concat("/rest/test-manager/events").concat( "?level=session&types=test-run-started,test-run-ended,test-run-count,script-step-updated,script-step-created,script-run-started,script-run-ended"); urlSSe = urlSSe.concat("&access-token=").concat(_token); ClientBuilder sslBuilder = ClientBuilder.newBuilder(); SSLContext sslContext;/*w w w .j a v a 2s . c o m*/ try { sslContext = SSLContext.getInstance("TLS"); _trustMgr = new SrfTrustManager(); sslContext.init(null, new SrfTrustManager[] { _trustMgr }, null); SSLContext.setDefault(sslContext); } catch (NoSuchAlgorithmException | KeyManagementException e1) { return; } sslBuilder.register(SSLContext.class); Client client = sslBuilder.register(SseFeature.class).build(); client.register(sslContext); try { client.getSslContext().init(null, new SrfTrustManager[] { _trustMgr }, null); } catch (KeyManagementException e) { e.printStackTrace(); } WebTarget target = client.target(urlSSe); eventSrc = openAsynch(target, addAuthentication(null)); if (eventSrc == null) { throw new SrfException("Failed to initiate open event source for SRF SSE"); } eventSrc.register(this.sseEventListener); }
From source file:org.dasein.cloud.zimory.ZimoryMethod.java
private @Nonnull HttpClient getClient(URI uri) throws InternalException, CloudException { ProviderContext ctx = provider.getContext(); if (ctx == null) { throw new NoContextException(); }// w w w .j av a 2 s . c o m boolean ssl = uri.getScheme().startsWith("https"); int targetPort = uri.getPort(); if (targetPort < 1) { targetPort = (ssl ? 443 : 80); } HttpParams params = new BasicHttpParams(); SchemeRegistry registry = new SchemeRegistry(); try { registry.register( new Scheme(ssl ? "https" : "http", targetPort, new X509SSLSocketFactory(new X509Store(ctx)))); } catch (KeyManagementException e) { e.printStackTrace(); throw new InternalException(e); } catch (UnrecoverableKeyException e) { e.printStackTrace(); throw new InternalException(e); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); throw new InternalException(e); } catch (KeyStoreException e) { e.printStackTrace(); throw new InternalException(e); } HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); //noinspection deprecation HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); HttpProtocolParams.setUserAgent(params, ""); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 300000); Properties p = ctx.getCustomProperties(); if (p != null) { String proxyHost = p.getProperty("proxyHost"); String proxyPort = p.getProperty("proxyPort"); if (proxyHost != null) { int port = 0; if (proxyPort != null && proxyPort.length() > 0) { port = Integer.parseInt(proxyPort); } params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(proxyHost, port, ssl ? "https" : "http")); } } ClientConnectionManager ccm = new ThreadSafeClientConnManager(registry); return new DefaultHttpClient(ccm, params); }
From source file:com.hpe.application.automation.tools.srf.run.RunFromSrfBuilder.java
private void initSrfEventListener() throws IOException, ConnectException, UnknownHostException, SSLHandshakeException, IllegalArgumentException { if (this._token != null) return;// w w w . j av a 2 s .c om // !!! Important Notice !!! // by using 'level=session' in the sse request we're ensuring that we'll get only events related // to this run since we're creating a new session (token) for each run this._token = loginToSrf(); String urlSSe = _ftaasServerAddress.concat("/rest/test-manager/events").concat( "?level=session&types=test-run-started,test-run-ended,test-run-count,script-step-updated,script-step-created,script-run-started,script-run-ended"); urlSSe = urlSSe.concat("&access-token=").concat(_token); ClientBuilder sslBuilder = ClientBuilder.newBuilder(); SSLContext sslContext; try { sslContext = SSLContext.getInstance("TLS"); _trustMgr = new SrfTrustManager(); sslContext.init(null, new SrfTrustManager[] { _trustMgr }, null); SSLContext.setDefault(sslContext); } catch (NoSuchAlgorithmException | KeyManagementException e1) { return; } sslBuilder.register(SSLContext.class); Client client = sslBuilder.register(SseFeature.class).build(); client.register(sslContext); try { client.getSslContext().init(null, new SrfTrustManager[] { _trustMgr }, null); } catch (KeyManagementException e) { e.printStackTrace(); } WebTarget target = client.target(urlSSe); eventSrc = openAsynch(target, addAuthentication(null)); eventSrc.register(this.sseEventListener); }
From source file:com.example.wechatsample.library.http.AsyncHttpClient.java
/** * Creates a new AsyncHttpClient./*from www . j a v a2s.c om*/ */ public AsyncHttpClient() { BasicHttpParams httpParams = new BasicHttpParams(); ConnManagerParams.setTimeout(httpParams, socketTimeout); ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(maxConnections)); ConnManagerParams.setMaxTotalConnections(httpParams, DEFAULT_MAX_CONNECTIONS); HttpConnectionParams.setSoTimeout(httpParams, socketTimeout); HttpConnectionParams.setConnectionTimeout(httpParams, socketTimeout); HttpConnectionParams.setTcpNoDelay(httpParams, true); HttpConnectionParams.setSocketBufferSize(httpParams, DEFAULT_SOCKET_BUFFER_SIZE); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setUserAgent(httpParams, String.format("android-async-http/%s (http://loopj.com/android-async-http)", VERSION)); ThreadSafeClientConnManager cm = null; try { // https? KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); // ?? SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", sf, 443)); schemeRegistry.register(new Scheme("https", sf, 8443)); cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry); } catch (KeyManagementException e) { e.printStackTrace(); } catch (UnrecoverableKeyException e) { e.printStackTrace(); } catch (KeyStoreException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (CertificateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } httpContext = new SyncBasicHttpContext(new BasicHttpContext()); httpClient = new DefaultHttpClient(cm, httpParams); httpClient.addRequestInterceptor(new HttpRequestInterceptor() { public void process(HttpRequest request, HttpContext context) { if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) { request.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP); } for (String header : clientHeaderMap.keySet()) { request.addHeader(header, clientHeaderMap.get(header)); } } }); httpClient.addResponseInterceptor(new HttpResponseInterceptor() { public void process(HttpResponse response, HttpContext context) { final HttpEntity entity = response.getEntity(); if (entity == null) { return; } final Header encoding = entity.getContentEncoding(); if (encoding != null) { for (HeaderElement element : encoding.getElements()) { if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) { response.setEntity(new InflatingEntity(response.getEntity())); break; } } } } }); httpClient.setHttpRequestRetryHandler(new RetryHandler(DEFAULT_MAX_RETRIES)); threadPool = (ThreadPoolExecutor) Executors.newCachedThreadPool(); requestMap = new WeakHashMap<Context, List<WeakReference<Future<?>>>>(); clientHeaderMap = new HashMap<String, String>(); }
From source file:com.gft.unity.android.AndroidIO.java
@Override public void run() { if (this.Validatecertificates()) { try {/*from ww w . j a va 2s .com*/ createHttpClients(); } catch (KeyManagementException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnrecoverableKeyException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (CertificateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (KeyStoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:org.openmrs.module.rheapocadapter.handler.RequestHandler.java
/** * this works with the sheduled task/* w w w . j a v a 2 s .com*/ * * @param method * to use while sending the body * @param body * Message to send * @param url * URL to send to */ public Transaction sendRequest(String method, String body, String url) { ResponseHandler response = new ResponseHandler(); User creator = Context.getUserService().getUserByUsername(TransactionUtil.getCreator().getUsername()); int sender = creator.getUserId(); try { ConnectionHandler conn = new ConnectionHandler(); log.info("url to use: " + url); if (method.equalsIgnoreCase("GET")) { Date sendDateTime = new Date(); String[] result = conn.callGet(url); Date receiveDateTime = new Date(); Transaction transaction = generateTransaction(sendDateTime, result[1], url, sender); Transaction item = response.generateMessage(transaction, Integer.parseInt(result[0]), method, receiveDateTime); return item; } else if (method.equalsIgnoreCase("POST") || method.equalsIgnoreCase("PUT")) { Date sendDateTime = new Date(); String[] result = conn.callPostAndPut(url, body, method); Date receiveDateTime = new Date(); Transaction transaction = generateTransaction(sendDateTime, result[1], url, sender); Transaction item = response.generateMessage(transaction, Integer.parseInt(result[0]), method, receiveDateTime); return item; } } catch (KeyManagementException e) { Date sendDateTime = new Date(); Date receiveDateTime = new Date(); Transaction transaction = generateTransaction(sendDateTime, e.getMessage(), url, sender); Transaction item = response.generateMessage(transaction, 400, method, receiveDateTime); log.error("KeyManagementException generated" + e.getMessage()); return item; } catch (KeyStoreException e) { Date sendDateTime = new Date(); Date receiveDateTime = new Date(); Transaction transaction = generateTransaction(sendDateTime, e.getMessage(), url, sender); Transaction item = response.generateMessage(transaction, 400, method, receiveDateTime); log.error("KeyStoreException generated" + e.getMessage()); return item; } catch (NoSuchAlgorithmException e) { Date sendDateTime = new Date(); Date receiveDateTime = new Date(); Transaction transaction = generateTransaction(sendDateTime, e.getMessage(), url, sender); Transaction item = response.generateMessage(transaction, 400, method, receiveDateTime); log.error("NoSuchAlgorithmException generated" + e.getMessage()); return item; } catch (CertificateException e) { Date sendDateTime = new Date(); Date receiveDateTime = new Date(); Transaction transaction = generateTransaction(sendDateTime, e.getMessage(), url, sender); Transaction item = response.generateMessage(transaction, 400, method, receiveDateTime); log.error("CertificateException generated" + e.getMessage()); return item; } catch (TransformerFactoryConfigurationError e) { Date sendDateTime = new Date(); Date receiveDateTime = new Date(); Transaction transaction = generateTransaction(sendDateTime, e.getMessage(), url, sender); Transaction item = response.generateMessage(transaction, 400, method, receiveDateTime); log.error("TransformerFactoryConfigurationError generated" + e.getMessage()); return item; } catch (SocketTimeoutException e) { Date sendDateTime = new Date(); Date receiveDateTime = new Date(); Transaction transaction = generateTransaction(sendDateTime, e.getMessage(), url, sender); Transaction item = response.generateMessage(transaction, 600, method, receiveDateTime); log.error("SocketTimeoutException generated " + e.getMessage()); return item; } catch (IOException e) { Date sendDateTime = new Date(); Date receiveDateTime = new Date(); Transaction transaction = generateTransaction(sendDateTime, e.getMessage(), url, sender); Transaction item = response.generateMessage(transaction, 600, method, receiveDateTime); log.error("IOException generated " + e.getMessage()); e.printStackTrace(); return item; } catch (Exception e) { Date sendDateTime = new Date(); Date receiveDateTime = new Date(); Transaction transaction = generateTransaction(sendDateTime, e.getMessage(), url, sender); Transaction item = response.generateMessage(transaction, 400, method, receiveDateTime); log.error("IOException generated " + e.getMessage()); e.printStackTrace(); return item; } return null; }
From source file:org.openmrs.module.rheapocadapter.handler.RequestHandler.java
/** * gets method, message body and parameters and call the connection, send * and call the response handler/*from w w w. j a va2 s .c o m*/ * * @param method * Method to use for sending, the first element is either get or * post, the second is used while creating the URL to know what * action to be done. e.g: GetClinicalData is different to * GetClients, both are gets but has different URLs. * @param body * message to be sent, it can be null. * @param parameter * used to create URL */ public Transaction sendRequest(String[] method, String body, TreeMap<String, String> parameter) { ResponseHandler response = new ResponseHandler(); String url = null; User creator = Context.getUserService().getUserByUsername(Context.getAuthenticatedUser().getUsername()); int sender = creator.getUserId(); try { ConnectionHandler conn = new ConnectionHandler(); // create url according to method to be used and transaction // performed url = conn.createUrl(method[1], parameter); if ((url == null) || (url == "")) { throw new SocketTimeoutException(); } log.info("URL= " + url); // if the method is GET or POST, send accordingly. if (method[0].equalsIgnoreCase("GET")) { Date sendDateTime = new Date(); String[] result = conn.callGet(url); Date receiveDateTime = new Date(); log.info("After callGet " + result[0] + " = " + result[1]); Transaction transaction = generateTransaction(sendDateTime, result[1], url, sender); Transaction item = response.generateMessage(transaction, Integer.parseInt(result[0]), method[0], receiveDateTime); return item; } else if (method[0].equalsIgnoreCase("POST") || method[0].equalsIgnoreCase("PUT")) { Date sendDateTime = new Date(); String[] result = conn.callPostAndPut(url, body, method[0]); Date receiveDateTime = new Date(); Transaction transaction = generateTransaction(sendDateTime, result[1], url, sender); Transaction item = response.generateMessage(transaction, Integer.parseInt(result[0]), method[0], receiveDateTime); return item; } } catch (KeyManagementException e) { Date sendDateTime = new Date(); Date receiveDateTime = new Date(); Transaction transaction = generateTransaction(sendDateTime, e.getMessage(), url, sender); Transaction item = response.generateMessage(transaction, 400, method[0], receiveDateTime); log.error("KeyManagementException generated" + e.getMessage()); return item; } catch (KeyStoreException e) { Date sendDateTime = new Date(); Date receiveDateTime = new Date(); Transaction transaction = generateTransaction(sendDateTime, e.getMessage(), url, sender); Transaction item = response.generateMessage(transaction, 400, method[0], receiveDateTime); log.error("KeyStoreException generated" + e.getMessage()); return item; } catch (NoSuchAlgorithmException e) { Date sendDateTime = new Date(); Date receiveDateTime = new Date(); Transaction transaction = generateTransaction(sendDateTime, e.getMessage(), url, sender); Transaction item = response.generateMessage(transaction, 400, method[0], receiveDateTime); log.error("NoSuchAlgorithmException generated" + e.getMessage()); return item; } catch (CertificateException e) { Date sendDateTime = new Date(); Date receiveDateTime = new Date(); Transaction transaction = generateTransaction(sendDateTime, e.getMessage(), url, sender); Transaction item = response.generateMessage(transaction, 400, method[0], receiveDateTime); log.error("CertificateException generated" + e.getMessage()); return item; } catch (TransformerFactoryConfigurationError e) { Date sendDateTime = new Date(); Date receiveDateTime = new Date(); Transaction transaction = generateTransaction(sendDateTime, e.getMessage(), url, sender); Transaction item = response.generateMessage(transaction, 400, method[0], receiveDateTime); log.error("TransformerFactoryConfigurationError generated" + e.getMessage()); return item; } catch (SocketTimeoutException e) { Date sendDateTime = new Date(); Date receiveDateTime = new Date(); Transaction transaction = generateTransaction(sendDateTime, e.getMessage(), url, sender); Transaction item = response.generateMessage(transaction, 600, method[0], receiveDateTime); log.error("SocketTimeoutException generated " + e.getMessage()); return item; } catch (IOException e) { Date sendDateTime = new Date(); Date receiveDateTime = new Date(); Transaction transaction = generateTransaction(sendDateTime, e.getMessage(), url, sender); Transaction item = response.generateMessage(transaction, 600, method[0], receiveDateTime); log.error("IOException generated " + e.getMessage()); e.printStackTrace(); return item; } log.info("Gonna return null"); return null; }