KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ubermq > jms > client > unicast > SSLClientSession


1 package com.ubermq.jms.client.unicast;
2
3 import java.net.*;
4 import java.nio.channels.*;
5
6 import javax.net.ssl.*;
7
8 import com.ubermq.jms.client.*;
9 import com.ubermq.jms.client.impl.*;
10 import com.ubermq.jms.common.ssl.*;
11 import com.ubermq.kernel.*;
12
13 /**
14  * This client session extends the abstract base client session to make socket
15  * connections to internet destinations.
16  * This client session uses direct point to point socket connections.
17  */

18 public class SSLClientSession
19     extends AbstractClientSession
20 {
21     private IDatagramFactory factory;
22
23     /**
24      * Creates a session with the given datagram factory to handle processing.
25      * @param f the datagram factory to use.
26      */

27     public SSLClientSession(IDatagramFactory f)
28         throws java.io.IOException JavaDoc
29     {
30         super();
31         this.factory = f;
32     }
33
34     public IConnectionInfo connect(javax.jms.Connection JavaDoc cxn,
35                                    ConnectionDescriptor descriptor,
36                                    IMessageProcessor proc)
37         throws java.io.IOException JavaDoc
38     {
39         // connect & force handshake to ensure
40
// liveness
41
InternetConnectionDescriptor d = (InternetConnectionDescriptor)descriptor;
42         InetSocketAddress isa = (InetSocketAddress)d.getAddress();
43         SSLSocket s = (SSLSocket)SSLSocketFactory.getDefault().createSocket(isa.getAddress(),
44                                                                             isa.getPort());
45         s.startHandshake();
46
47         // create two pipes, one upstream and one downstream
48
Pipe tosocket = Pipe.open(), fromsocket = Pipe.open();
49
50         // create my connection info, for client-side registration
51
IConnectionInfo connInfo = new PipeConnectionInfo(fromsocket.source(),
52                                                           tosocket.sink(),
53                                                           factory,
54                                                           proc);
55
56         // normalize IO
57
IONormalizer.normalize(fromsocket, tosocket, s);
58
59         // attach the connection info to the client processor.
60
proc.accept(connInfo);
61         return connInfo;
62     }
63 }
64
Popular Tags