|
1 | 1 | package org.eclipse.ecf.examples.sslcontextfactory;
|
2 | 2 |
|
3 |
| -import java.security.NoSuchAlgorithmException; |
4 |
| -import java.security.NoSuchProviderException; |
5 |
| - |
6 |
| -import javax.net.ssl.SSLContext; |
7 |
| - |
8 | 3 | import org.eclipse.ecf.core.security.SSLContextFactory;
|
9 | 4 | import org.osgi.service.component.annotations.Component;
|
10 | 5 | import org.osgi.service.component.annotations.Reference;
|
| 6 | +import org.osgi.service.component.annotations.ReferenceCardinality; |
11 | 7 |
|
12 | 8 | @Component(immediate=true)
|
13 | 9 | public class ContextFactoryConsumer {
|
14 | 10 |
|
15 |
| - @Reference |
| 11 | + private static SSLContextFactory factory; |
| 12 | + |
| 13 | + @Reference(cardinality = ReferenceCardinality.MANDATORY) |
16 | 14 | void bindSSLContextFactory(SSLContextFactory sslContextFactory) {
|
17 |
| - System.out.println("Got it "+ sslContextFactory); |
18 |
| - // Now get PKIJoe SSLContext |
19 |
| - try { |
20 |
| - SSLContext sslContext = sslContextFactory.getInstance("TLS", "PKIJoe"); |
21 |
| - // # do stuff with sslContext here! |
22 |
| - System.out.println("sslContext="+sslContext); |
23 |
| - } catch (NoSuchAlgorithmException e) { |
24 |
| - // TODO Auto-generated catch block |
25 |
| - e.printStackTrace(); |
26 |
| - } catch (NoSuchProviderException e) { |
27 |
| - // TODO Auto-generated catch block |
28 |
| - e.printStackTrace(); |
29 |
| - } |
| 15 | + factory = sslContextFactory; |
30 | 16 | }
|
31 | 17 |
|
32 | 18 | void unbindSSLContextFactory(SSLContextFactory sslContextFactory) {
|
33 |
| - System.out.println("Ungot it "+ sslContextFactory); |
| 19 | + factory = null; |
| 20 | + } |
| 21 | + |
| 22 | + public static SSLContextFactory getSSLContextFactory() { |
| 23 | + return factory; |
34 | 24 | }
|
35 | 25 | }
|
0 commit comments