View Javadoc

1   /*
2    * $Id: SaveCertificatesCallback.java 20321 2010-11-24 15:21:24Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.ssl;
12  
13  import org.mule.api.MuleEventContext;
14  import org.mule.tck.functional.EventCallback;
15  
16  import java.security.cert.Certificate;
17  import java.util.Collections;
18  import java.util.LinkedList;
19  import java.util.List;
20  
21  public class SaveCertificatesCallback implements EventCallback
22  {
23      // volatile since this is a thread-safe collection (see holger)
24      private volatile List<Certificate[]> certificates;
25  
26      public SaveCertificatesCallback()
27      {
28          super();
29          clear();
30      }
31  
32      public void eventReceived(MuleEventContext context, Object component) throws Exception
33      {
34          // putting a Thread.sleep here doesn't make this less reliable
35          // surely it would if it was thread scribbling?
36          Thread.sleep(100);
37  
38          Certificate[] certs = context.getMessage().getOutboundProperty(SslConnector.LOCAL_CERTIFICATES);
39          certificates.add(certs);
40      }
41  
42      public void clear()
43      {
44          certificates = Collections.synchronizedList(new LinkedList<Certificate[]>());
45      }
46  
47      public List<Certificate[]> getCertificates()
48      {
49          return certificates;
50      }
51  }