01: /*
02: * $Id: HttpsMessageReceiver.java 10961 2008-02-22 19:01:02Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
10:
11: package org.mule.transport.http;
12:
13: import org.mule.api.MuleMessage;
14: import org.mule.api.endpoint.InboundEndpoint;
15: import org.mule.api.lifecycle.CreateException;
16: import org.mule.api.service.Service;
17: import org.mule.api.transport.Connector;
18:
19: import java.io.IOException;
20: import java.net.Socket;
21: import java.security.cert.Certificate;
22:
23: import javax.net.ssl.HandshakeCompletedEvent;
24: import javax.net.ssl.HandshakeCompletedListener;
25: import javax.net.ssl.SSLPeerUnverifiedException;
26: import javax.net.ssl.SSLSocket;
27: import javax.resource.spi.work.Work;
28:
29: public class HttpsMessageReceiver extends HttpMessageReceiver {
30:
31: public HttpsMessageReceiver(Connector connector, Service service,
32: InboundEndpoint endpoint) throws CreateException {
33: super (connector, service, endpoint);
34: }
35:
36: // @Override
37: protected Work createWork(Socket socket) throws IOException {
38: return new HttpsWorker(socket);
39: }
40:
41: private class HttpsWorker extends HttpWorker implements
42: HandshakeCompletedListener {
43: private Certificate[] peerCertificateChain;
44: private Certificate[] localCertificateChain;
45:
46: public HttpsWorker(Socket socket) throws IOException {
47: super (socket);
48: ((SSLSocket) socket).addHandshakeCompletedListener(this );
49: }
50:
51: protected void preRouteMessage(MuleMessage message) {
52: super .preRouteMessage(message);
53:
54: if (peerCertificateChain != null) {
55: message.setProperty(HttpsConnector.PEER_CERTIFICATES,
56: peerCertificateChain);
57: }
58: if (localCertificateChain != null) {
59: message.setProperty(HttpsConnector.LOCAL_CERTIFICATES,
60: localCertificateChain);
61: }
62: }
63:
64: public void handshakeCompleted(HandshakeCompletedEvent event) {
65: localCertificateChain = event.getLocalCertificates();
66: try {
67: peerCertificateChain = event.getPeerCertificates();
68: } catch (SSLPeerUnverifiedException e) {
69: logger.debug("Cannot get peer certificate chain: "
70: + e.getMessage());
71: }
72: }
73:
74: }
75:
76: }
|