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