org.apache.http.HttpInetConnection Java Examples
The following examples show how to use
org.apache.http.HttpInetConnection.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SiteToSiteRestApiClient.java From localization_nifi with Apache License 2.0 | 5 votes |
@Override public void process(final HttpResponse response, final HttpContext httpContext) throws HttpException, IOException { final HttpCoreContext coreContext = HttpCoreContext.adapt(httpContext); final HttpInetConnection conn = coreContext.getConnection(HttpInetConnection.class); if (!conn.isOpen()) { return; } final SSLSession sslSession; if (conn instanceof ManagedHttpClientConnection) { sslSession = ((ManagedHttpClientConnection) conn).getSSLSession(); } else if (conn instanceof ManagedNHttpClientConnection) { sslSession = ((ManagedNHttpClientConnection) conn).getSSLSession(); } else { throw new RuntimeException("Unexpected connection type was used, " + conn); } if (sslSession != null) { final Certificate[] certChain = sslSession.getPeerCertificates(); if (certChain == null || certChain.length == 0) { throw new SSLPeerUnverifiedException("No certificates found"); } try { final X509Certificate cert = CertificateUtils.convertAbstractX509Certificate(certChain[0]); trustedPeerDn = cert.getSubjectDN().getName().trim(); } catch (final CertificateException e) { final String msg = "Could not extract subject DN from SSL session peer certificate"; logger.warn(msg); eventReporter.reportEvent(Severity.WARNING, EVENT_CATEGORY, msg); throw new SSLPeerUnverifiedException(msg); } } }
Example #2
Source File: SimpleHttpFetcher.java From ache with Apache License 2.0 | 5 votes |
@Override public HttpResponse execute(HttpRequest request, HttpClientConnection conn, HttpContext context) throws IOException, HttpException { HttpInetConnection connection = (HttpInetConnection) conn; context.setAttribute(HOST_ADDRESS, connection.getRemoteAddress().getHostAddress()); return super.execute(request, conn, context); }
Example #3
Source File: HttpContextUtil.java From galaxy-fds-sdk-java with Apache License 2.0 | 5 votes |
public static String getRemoteAddressFromContext(HttpContext context) { String remoteAddress = (String)context.getAttribute(Constants.SOCKET_REMOTE_ADDRESS); if (remoteAddress == null) { if (HttpClientContext.class.isInstance(context)) { HttpClientContext cc = (HttpClientContext)context; if (cc.getConnection() instanceof HttpInetConnection) { HttpInetConnection inetConnection = (HttpInetConnection)cc.getConnection(); remoteAddress = inetConnection.getRemoteAddress().getHostAddress(); } } } return remoteAddress; }
Example #4
Source File: SiteToSiteRestApiClient.java From nifi with Apache License 2.0 | 5 votes |
@Override public void process(final HttpResponse response, final HttpContext httpContext) throws HttpException, IOException { final HttpCoreContext coreContext = HttpCoreContext.adapt(httpContext); final HttpInetConnection conn = coreContext.getConnection(HttpInetConnection.class); if (!conn.isOpen()) { return; } final SSLSession sslSession; if (conn instanceof ManagedHttpClientConnection) { sslSession = ((ManagedHttpClientConnection) conn).getSSLSession(); } else if (conn instanceof ManagedNHttpClientConnection) { sslSession = ((ManagedNHttpClientConnection) conn).getSSLSession(); } else { throw new RuntimeException("Unexpected connection type was used, " + conn); } if (sslSession != null) { final Certificate[] certChain = sslSession.getPeerCertificates(); if (certChain == null || certChain.length == 0) { throw new SSLPeerUnverifiedException("No certificates found"); } try { final X509Certificate cert = CertificateUtils.convertAbstractX509Certificate(certChain[0]); trustedPeerDn = cert.getSubjectDN().getName().trim(); } catch (final CertificateException e) { final String msg = "Could not extract subject DN from SSL session peer certificate"; logger.warn(msg); eventReporter.reportEvent(Severity.WARNING, EVENT_CATEGORY, msg); throw new SSLPeerUnverifiedException(msg); } } }