List of usage examples for java.net Socket getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.eclipse.mylyn.internal.commons.repositories.http.core.PollingSslProtocolSocketFactory.java
public boolean isSecure(Socket socket) throws IllegalArgumentException { Assert.isNotNull(socket);// w w w. j ava 2 s . co m if (!(socket instanceof SSLSocket)) { throw new IllegalArgumentException("Socket is not secure: " + socket.getClass()); //$NON-NLS-1$ } if (socket.isClosed()) { throw new IllegalArgumentException("Socket is closed"); //$NON-NLS-1$ } return true; }
From source file:org.keycloak.adapters.cloned.SniSSLSocketFactory.java
private Socket applySNI(final Socket socket, String hostname) { if (socket instanceof SSLSocket) { try {// ww w. ja v a2 s.c om Method setHostMethod = AccessController.doPrivileged(new PrivilegedExceptionAction<Method>() { @Override public Method run() throws NoSuchMethodException { return socket.getClass().getMethod("setHost", String.class); } }); setHostMethod.invoke(socket, hostname); LOG.log(Level.FINEST, "Applied SNI to socket for host {0}", hostname); } catch (PrivilegedActionException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { LOG.log(Level.WARNING, "Failed to apply SNI to SSLSocket", e); } } return socket; }
From source file:com.servoy.extensions.plugins.http.HttpClient.java
public HttpClient(IClientPluginAccess plugin) { client = new DefaultHttpClient(); client.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, Boolean.TRUE); client.getAuthSchemes().register(AuthPolicy.NTLM, new NTLMSchemeFactory()); client.getAuthSchemes().register(AuthPolicy.SPNEGO, new NegotiateSchemeFactory()); this.plugin = plugin; try {/* ww w. j av a 2 s.co m*/ final AllowedCertTrustStrategy allowedCertTrustStrategy = new AllowedCertTrustStrategy(); SSLSocketFactory sf = new SSLSocketFactory(allowedCertTrustStrategy) { @Override public Socket connectSocket(Socket socket, InetSocketAddress remoteAddress, InetSocketAddress localAddress, HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException { if (socket instanceof SSLSocket) { try { Method s = socket.getClass().getMethod("setHost", String.class); s.invoke(socket, remoteAddress.getHostName()); } catch (NoSuchMethodException ex) { } catch (IllegalAccessException ex) { } catch (InvocationTargetException ex) { } catch (IllegalArgumentException ex) { } catch (SecurityException ex) { } } try { return super.connectSocket(socket, remoteAddress, localAddress, params); } catch (SSLPeerUnverifiedException ex) { X509Certificate[] lastCertificates = allowedCertTrustStrategy.getAndClearLastCertificates(); if (lastCertificates != null) { // allow for next time if (HttpClient.this.plugin.getApplicationType() == IClientPluginAccess.CLIENT || HttpClient.this.plugin.getApplicationType() == IClientPluginAccess.RUNTIME) { // show dialog CertificateDialog dialog = new CertificateDialog( ((ISmartRuntimeWindow) HttpClient.this.plugin.getCurrentRuntimeWindow()) .getWindow(), remoteAddress, lastCertificates); if (dialog.shouldAccept()) { allowedCertTrustStrategy.add(lastCertificates); // try it again now with the new chain. return super.connectSocket(socket, remoteAddress, localAddress, params); } } else { Debug.error("Couldn't connect to " + remoteAddress + ", please make sure that the ssl certificates of that site are added to the java keystore." + "Download the keystore in the browser and update the java cacerts file in jre/lib/security: " + "keytool -import -file downloaded.crt -keystore cacerts"); } } throw ex; } finally { // always just clear the last request. allowedCertTrustStrategy.getAndClearLastCertificates(); } } }; Scheme https = new Scheme("https", 443, sf); //$NON-NLS-1$ client.getConnectionManager().getSchemeRegistry().register(https); } catch (Exception e) { Debug.error("Can't register a https scheme", e); //$NON-NLS-1$ } }
From source file:org.eredlab.g4.ccl.net.ftp.FTP.java
/** * Checks if the socket is connected using reflection to be backward compatible. * The return value of this method is only meaningful in an java 1.4 environment. * * @param socket//from ww w .ja va 2 s. c o m * @return true if connected or pre java 1.4 */ private boolean socketIsConnected(Socket socket) { if (socket == null) { return false; } try { Method isConnected = socket.getClass().getMethod("isConnected", null); return ((Boolean) isConnected.invoke(socket, null)).booleanValue(); } catch (NoSuchMethodException e) { return true; } catch (IllegalAccessException e) { return true; } catch (InvocationTargetException e) { return true; } }