Skip to content

Commit 8915e3b

Browse files
committed
Enhanced the ContextFactoryConsumer
1 parent cc78aec commit 8915e3b

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="org.eclipse.ecf.examples.sslcontextfactory.ContextFactoryConsumer">
3-
<reference bind="bindSSLContextFactory" interface="org.eclipse.ecf.core.security.SSLContextFactory" name="SSLContextFactory" unbind="unbindSSLContextFactory"/>
3+
<reference bind="bindSSLContextFactory" cardinality="1..1" interface="org.eclipse.ecf.core.security.SSLContextFactory" name="SSLContextFactory" unbind="unbindSSLContextFactory"/>
44
<implementation class="org.eclipse.ecf.examples.sslcontextfactory.ContextFactoryConsumer"/>
55
</scr:component>
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,25 @@
11
package org.eclipse.ecf.examples.sslcontextfactory;
22

3-
import java.security.NoSuchAlgorithmException;
4-
import java.security.NoSuchProviderException;
5-
6-
import javax.net.ssl.SSLContext;
7-
83
import org.eclipse.ecf.core.security.SSLContextFactory;
94
import org.osgi.service.component.annotations.Component;
105
import org.osgi.service.component.annotations.Reference;
6+
import org.osgi.service.component.annotations.ReferenceCardinality;
117

128
@Component(immediate=true)
139
public class ContextFactoryConsumer {
1410

15-
@Reference
11+
private static SSLContextFactory factory;
12+
13+
@Reference(cardinality = ReferenceCardinality.MANDATORY)
1614
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;
3016
}
3117

3218
void unbindSSLContextFactory(SSLContextFactory sslContextFactory) {
33-
System.out.println("Ungot it "+ sslContextFactory);
19+
factory = null;
20+
}
21+
22+
public static SSLContextFactory getSSLContextFactory() {
23+
return factory;
3424
}
3525
}

0 commit comments

Comments
 (0)