List of usage examples for javax.net.ssl SSLHandshakeException getMessage
public String getMessage()
From source file:net.officefloor.plugin.socket.server.http.integrate.AutoWireHttpsSocketTest.java
/** * Ensure reports back if no matching cypher. */// w ww . ja v a2s. co m public void testNoMatchingCypherForHttpsServer() throws Exception { // Register the managed object source HttpsServerSocketManagedObjectSource.autoWire(this.autoWire, this.port, null, "TEST", "handleRequest"); // Open the OfficeFloor this.officeFloor = this.autoWire.openOfficeFloor(); // Use default SslContext which should not match on cypher try (CloseableHttpClient client = HttpClientBuilder.create().build()) { // Send request try { client.execute(new HttpGet("https://localhost:" + this.port)); fail("Should not be successful"); } catch (SSLHandshakeException ex) { assertEquals("Incorrect cause", "Remote host closed connection during handshake", ex.getMessage()); } } }
From source file:com.springsource.hq.plugin.tcserver.serverconfig.web.services.SettingsLoaderImpl.java
public void restartServer(RemoteSettings remoteSettings) throws SettingsLoaderException { try {//from w w w .j av a2s .c o m logger.debug("Attempting to restart server for '" + remoteSettings.getSettings().getEid() + "'"); PostMethod method = new PostMethod( remoteSettings.getBasePath() + "/hqu/tomcatserverconfig/tomcatserverconfig/restartServer.hqu"); method.addParameter("isJmxListenerChanged", Boolean.toString(remoteSettings.isJmxListenerChanged())); configureMethod(method, remoteSettings.getSettings().getEid(), remoteSettings.getSessionId(), remoteSettings.getCsrfNonce()); httpClient.executeMethod(method); if (method.getStatusCode() >= 300 && method.getStatusCode() < 400) { logger.info("Unable to restart server for '" + remoteSettings.getSettings().getEid() + "', HQ session expired"); throw new SettingsLoaderException(SESSION_EXPIRED_MESSAGE); } else if (method.getStatusCode() >= 400) { logger.warn("Unable to restart server for '" + remoteSettings.getSettings().getEid() + "', " + method.getStatusCode() + " " + method.getStatusText()); throw new SettingsLoaderException(method.getStatusText()); } remoteSettings.setCsrfNonce(method.getResponseBodyAsString()); logger.debug("Restarted server for '" + remoteSettings.getSettings().getEid() + "'"); } catch (SSLHandshakeException e) { logger.error("Server SSL certificate is untrusted: " + e.getMessage(), e); throw new SettingsLoaderException( "Unable to restart server because the server is using an untrusted SSL certificate. " + "Please check the documentation for more information.", e); } catch (IOException e) { logger.error("Unable to restart server for '" + remoteSettings.getSettings().getEid() + "': " + e.getMessage(), e); throw new SettingsLoaderException( "Server restart failed because of a server error, please check the logs for more details", e); } }
From source file:com.springsource.hq.plugin.tcserver.serverconfig.web.services.SettingsLoaderImpl.java
public void saveConfiguration(RemoteSettings remoteSettings) throws SettingsLoaderException { try {//from w ww . j a v a 2 s .co m logger.debug("Attempting to save Settings for '" + remoteSettings.getSettings().getEid() + "'"); String xml = xstream.toXML(remoteSettings.getSettings()); PostMethod method = new PostMethod(remoteSettings.getBasePath() + "/hqu/tomcatserverconfig/tomcatserverconfig/saveConfiguration.hqu"); configureMethod(method, remoteSettings.getSettings().getEid(), remoteSettings.getSessionId(), remoteSettings.getCsrfNonce()); method.setRequestEntity(new StringRequestEntity(xml, "text/xml", "UTF-8")); httpClient.executeMethod(method); if (method.getStatusCode() >= 300 && method.getStatusCode() < 400) { logger.info("Unable to save Settings for '" + remoteSettings.getSettings().getEid() + "', HQ session expired"); throw new SettingsLoaderException(SESSION_EXPIRED_MESSAGE); } else if (method.getStatusCode() >= 400) { logger.warn("Unable to save Settings for '" + remoteSettings.getSettings().getEid() + "', " + method.getStatusCode() + " " + method.getStatusText()); throw new SettingsLoaderException(method.getStatusText()); } remoteSettings.setCsrfNonce(method.getResponseBodyAsString()); logger.info("Saved Settings for '" + remoteSettings.getSettings().getEid() + "'"); } catch (SSLHandshakeException e) { logger.error("Server SSL certificate is untrusted: " + e.getMessage(), e); throw new SettingsLoaderException( "Unable to save settings because the server is using an untrusted SSL certificate. " + "Please check the documentation for more information.", e); } catch (IOException e) { logger.error("Unable to save Settings for '" + remoteSettings.getSettings().getEid() + "': " + e.getMessage(), e); throw new SettingsLoaderException( "Saving settings failed because of a server error, please check the logs for more details", e); } }
From source file:com.springsource.hq.plugin.tcserver.serverconfig.web.services.SettingsLoaderImpl.java
public void revertToPreviousConfiguration(RemoteSettings remoteSettings) throws SettingsLoaderException { try {/*from w w w . ja v a2 s. c om*/ logger.debug("Attempting to revert to previous configuration for '" + remoteSettings.getSettings().getEid() + "'"); PostMethod method = new PostMethod(remoteSettings.getBasePath() + "/hqu/tomcatserverconfig/tomcatserverconfig/revertToPreviousConfiguration.hqu"); configureMethod(method, remoteSettings.getSettings().getEid(), remoteSettings.getSessionId(), remoteSettings.getCsrfNonce()); httpClient.executeMethod(method); if (method.getStatusCode() >= 300 && method.getStatusCode() < 400) { logger.info("Unable to revert to previous configuration for '" + remoteSettings.getSettings().getEid() + "', HQ session expired"); throw new SettingsLoaderException(SESSION_EXPIRED_MESSAGE); } else if (method.getStatusCode() >= 400) { logger.warn( "Unable to revert to previous configuration for '" + remoteSettings.getSettings().getEid() + "', " + method.getStatusCode() + " " + method.getStatusText()); throw new SettingsLoaderException(method.getStatusText()); } remoteSettings.setCsrfNonce(method.getResponseBodyAsString()); logger.info("Reverted to previous configuration for '" + remoteSettings.getSettings().getEid() + "'"); } catch (SSLHandshakeException e) { logger.error("Server SSL certificate is untrusted: " + e.getMessage(), e); throw new SettingsLoaderException( "Unable to revert to previous configuration because the server is using an untrusted SSL certificate. " + "Please check the documentation for more information.", e); } catch (IOException e) { logger.error("Unable to revert to previous configuration for '" + remoteSettings.getSettings().getEid() + "': " + e.getMessage(), e); throw new SettingsLoaderException( "Reverting to previous configuration failed because of a server error, please check the logs for more details", e); } }
From source file:com.springsource.hq.plugin.tcserver.serverconfig.web.services.SettingsLoaderImpl.java
public RemoteSettings getConfiguration(String eid, String sessionId, String basePath, String csrfNonce) throws SettingsLoaderException { try {/*from ww w . j a va 2s . c om*/ logger.debug("Attempting to load Settings for '" + eid + "'"); GetMethod method = new GetMethod( basePath + "/hqu/tomcatserverconfig/tomcatserverconfig/getConfiguration.hqu"); configureMethod(method, eid, sessionId, csrfNonce); httpClient.executeMethod(method); if (method.getStatusCode() >= 300 && method.getStatusCode() < 400) { logger.info("Unable to load Settings for '" + eid + "', HQ session expired"); throw new SettingsLoaderException(SESSION_EXPIRED_MESSAGE); } else if (method.getStatusCode() >= 400) { logger.warn("Unable to load Settings for '" + eid + "', " + method.getStatusCode() + " " + method.getStatusText()); throw new SettingsLoaderException(method.getStatusText()); } Settings settings = (Settings) xstream.fromXML(method.getResponseBodyAsString()); RemoteSettings remoteSettings = new RemoteSettings(); remoteSettings.setSettings(settings); remoteSettings.setBasePath(basePath); remoteSettings.setSessionId(sessionId); remoteSettings.setCsrfNonce(csrfNonce); logger.info("Loaded Settings for '" + eid + "'"); return remoteSettings; } catch (SSLHandshakeException e) { logger.error("Server SSL certificate is untrusted: " + e.getMessage(), e); throw new SettingsLoaderException( "Unable to load settings because the server is using an untrusted SSL certificate. " + "Please check the documentation for more information.", e); } catch (IOException e) { logger.error("Unable to load Settings for '" + eid + "': " + e.getMessage(), e); throw new SettingsLoaderException( "Unable to load settings because of a server error, please check the logs for more details", e); } }
From source file:com.springsource.hq.plugin.tcserver.serverconfig.web.services.SettingsLoaderImpl.java
public void saveConfigurationFile(String fileName, String config, RemoteSettings remoteSettings) throws SettingsLoaderException { try {// ww w . ja v a 2 s. c o m logger.debug( "Attempting to save '" + fileName + "' for '" + remoteSettings.getSettings().getEid() + "'"); PostMethod method = new PostMethod(remoteSettings.getBasePath() + "/hqu/tomcatserverconfig/tomcatserverconfig/saveConfigurationFile.hqu"); configureMethod(method, remoteSettings.getSettings().getEid(), remoteSettings.getSessionId(), remoteSettings.getCsrfNonce()); Part[] parts = new Part[] { new StringPart("fileName", fileName), new StringPart("file", config) }; method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams())); httpClient.executeMethod(method); if (method.getStatusCode() >= 300 && method.getStatusCode() < 400) { logger.info("Unable to save '" + fileName + "' configuration for '" + remoteSettings.getSettings().getEid() + "', HQ session expired"); throw new SettingsLoaderException(SESSION_EXPIRED_MESSAGE); } else if (method.getStatusCode() >= 400) { logger.warn("Unable to save '" + fileName + "' configuration for '" + remoteSettings.getSettings().getEid() + "', " + method.getStatusCode() + " " + method.getStatusText()); throw new SettingsLoaderException(method.getStatusText()); } remoteSettings.setCsrfNonce(method.getResponseBodyAsString()); logger.info("Saved '" + fileName + "' for '" + remoteSettings.getSettings().getEid() + "'"); } catch (SSLHandshakeException e) { logger.error("Server SSL certificate is untrusted: " + e.getMessage(), e); throw new SettingsLoaderException( "Unable to save '" + fileName + "' because the server is using an untrusted SSL certificate. " + "Please check the documentation for more information.", e); } catch (IOException e) { logger.error("Unable to save '" + fileName + "' for '" + remoteSettings.getSettings().getEid() + "': " + e.getMessage(), e); throw new SettingsLoaderException( "Saving configuration file failed because of a server error, please check the logs for more details", e); } }
From source file:org.lockss.config.HTTPConfigFile.java
/** * Given a URL, open an input stream, handling the appropriate * if-modified-since behavior./*from www . ja v a 2s . c o m*/ */ private InputStream getUrlInputStream(String url) throws IOException, MalformedURLException { try { return getUrlInputStream0(url); } catch (javax.net.ssl.SSLHandshakeException e) { m_loadError = "Could not authenticate server: " + e.getMessage(); throw new IOException(m_loadError, e); } catch (javax.net.ssl.SSLKeyException e) { m_loadError = "Could not authenticate; bad client or server key: " + e.getMessage(); throw new IOException(m_loadError, e); } catch (javax.net.ssl.SSLPeerUnverifiedException e) { m_loadError = "Could not verify server identity: " + e.getMessage(); throw new IOException(m_loadError, e); } catch (javax.net.ssl.SSLException e) { m_loadError = "Error negotiating SSL seccion: " + e.getMessage(); throw new IOException(m_loadError, e); } }
From source file:org.eclipse.mylyn.commons.tests.net.WebUtilTest.java
public void testLocationConnectSsl() throws Exception { String url = "https://" + proxyAddress.getHostName() + ":" + proxyAddress.getPort() + "/"; AbstractWebLocation location = new WebLocation(url, null, null, null); HostConfiguration hostConfiguration = WebUtil.createHostConfiguration(client, location, null); testProxy.setCloseOnConnect(true);/*w w w . j a v a 2s . co m*/ GetMethod method = new GetMethod("/"); try { int statusCode = client.executeMethod(hostConfiguration, method); fail("Expected SSLHandshakeException or connection reset, got status: " + statusCode); } catch (SSLHandshakeException e) { } catch (SocketException e) { assertEquals("Connection reset", e.getMessage()); } assertFalse(testProxy.hasRequest()); }
From source file:com.aliyun.odps.rest.RestClient.java
protected Response requestWithNoRetry(String resource, String method, Map<String, String> params, Map<String, String> headers, InputStream body, long bodyLen) throws OdpsException { Response resp = null;/*from w w w . j a va 2 s . co m*/ if (headers == null) { headers = new HashMap<String, String>(); } try { // set Content-Length if (body != null) { headers.put(Headers.CONTENT_LENGTH, String.valueOf(bodyLen)); if (!headers.containsKey(Headers.CONTENT_MD5) && (bodyLen > 0)) { String contentMd5 = org.apache.commons.codec.binary.Hex .encodeHexString(org.apache.commons.codec.digest.DigestUtils.md5(body)); IOUtils.resetInputStream(body); headers.put(Headers.CONTENT_MD5, contentMd5); } } Request req = buildRequest(resource, method, params, headers); req.setBody(body); req.setBodyLength(bodyLen); resp = transport.request(req); return resp; } catch (SSLHandshakeException e) { // FOR HTTPS CERTS CHECK FAILED // USE RuntimeException could avoid retry throw new RuntimeException(e.getMessage(), e); } catch (IOException e) { throw new OdpsException(e.getMessage(), e); } }
From source file:com.morphoss.acal.service.connector.AcalRequestor.java
/** * <p>// ww w . j av a 2 s .co m * Does an XML request against the specified path (or the previously set path, if null), * following redirects and returning the root DavNode of an XML tree. * </p> * * @return <p> * A DavNode which is the root of the multistatus response, or null if it couldn't be parsed. * </p> * @throws SSLHandshakeException */ public DavNode doXmlRequest(String method, String requestPath, Header[] headers, String xml) throws SSLHandshakeException { long start = System.currentTimeMillis(); InputStream responseStream = null; DavNode root = null; try { responseStream = doRequest(method, requestPath, headers, xml); if (responseHeaders == null) { return root; } for (Header h : responseHeaders) { if ("Content-Type".equals(h.getName())) { for (HeaderElement he : h.getElements()) { if ("text/plain".equals(he.getName()) || "text/html".equals(he.getName())) { Log.println(Constants.LOGI, TAG, "Response is not an XML document"); if (responseStream != null) responseStream.close(); return root; } } } } if (statusCode == 404 || statusCode == 401) { return root; } root = DavParserFactory.buildTreeFromXml(Constants.XMLParseMethod, responseStream); } catch (SSLHandshakeException e) { throw e; } catch (Exception e) { Log.i(TAG, e.getMessage(), e); return null; } finally { if (responseStream != null) try { responseStream.close(); } catch (IOException e) { } } if (debugThisRequest) Log.println(Constants.LOGV, TAG, "Request and parse completed in " + (System.currentTimeMillis() - start) + "ms"); return root; }