On Fri, 2007-09-21 at 12:28 +0200, Johannes Koch wrote:
> Hi,
>
> is it possible to access the socket used by the connection from within
> the process methods of a org.apache.http.protocol.HttpProcessor? In case
> of secure HTTP I would like to get some information from the certificates.
>
> I do some experiments with the trunk of httpcore and httpclient.
>
Hi Johannes,
You can obtain the connection object from the context. The default
implementation of the ClientConnection does not expose the underlying
socket but this can be easily mended by creating a custom super class.
You will also need to plug in a custom ClientConnectionOperator to the
connection manager.
Something along these lines:
class CertificateProtocolInterceptor implements HttpRequestInterceptor {
public void process(
final HttpRequest request,
final HttpContext context) throws HttpException,
IOException {
HttpConnection conn = (HttpConnection) context.getAttribute(
ExecutionContext.HTTP_CONNECTION);
if (conn instanceof MySSLClientConnection) {
SSLSocket socket = ((MySSLClientConnection)conn)
.getSSLSocket();
X509Certificate[] certs = socket.getSession()
.getPeerCertificateChain();
if (certs != null) {
for (int i = 0; i < certs.length; i++) {
System.out.println(certs[i]);
}
}
}
}
}
class MySSLClientConnection extends DefaultClientConnection {
public SSLSocket getSSLSocket() {
Socket socket = getSocket();
if (socket instanceof SSLSocket) {
return (SSLSocket) socket;
} else {
return null;
}
}
}
We may actually think about exposing SSLSession through the
ClientConnection or its extension.
Feel free to open a JIRA ticket for that.
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]