3
3
import popjava .broker .Broker ;
4
4
import popjava .broker .RequestQueue ;
5
5
import popjava .util .LogWriter ;
6
+ import popjava .combox .ComboxReceiveRequest ;
6
7
7
- import java .net .* ;
8
+ import java .io . IOException ;
8
9
import java .util .LinkedList ;
9
- import java . io .* ;
10
- import popjava . combox . ComboxReceiveRequest ;
10
+ import javax . net . ssl . SSLServerSocket ;
11
+ import javax . net . ssl . SSLSocket ;
11
12
12
13
/**
13
14
* This class is responsible to accept the new connection for the associated server combox socket
@@ -21,19 +22,19 @@ public class ComboxAcceptSecureSocket implements Runnable {
21
22
22
23
protected Broker broker ;
23
24
protected RequestQueue requestQueue ;
24
- protected ServerSocket serverSocket ;
25
+ protected SSLServerSocket serverSocket ;
25
26
protected int status = EXIT ;
26
- protected final LinkedList <Socket > concurentConnections = new LinkedList <>();
27
+ protected final LinkedList <SSLSocket > concurentConnections = new LinkedList <>();
27
28
28
29
/**
29
30
* Create a new instance of the ComboxAccept socket
30
31
* @param broker The associated broker
31
32
* @param requestQueue The associated request queue
32
- * @param socket The associated combox socket
33
+ * @param serverSocket The associated combox socket
33
34
*/
34
35
public ComboxAcceptSecureSocket (Broker broker , RequestQueue requestQueue ,
35
- ServerSocket socket ) {
36
- serverSocket = socket ;
36
+ SSLServerSocket serverSocket ) {
37
+ this . serverSocket = serverSocket ;
37
38
this .broker = broker ;
38
39
this .requestQueue = requestQueue ;
39
40
}
@@ -43,34 +44,39 @@ public ComboxAcceptSecureSocket(Broker broker, RequestQueue requestQueue,
43
44
*/
44
45
public void run () {
45
46
while (status != EXIT ) {
46
- Socket connection = null ;
47
+ SSLSocket connection = null ;
47
48
try {
48
- connection = serverSocket .accept ();
49
- LogWriter .writeDebugInfo ("Connection accepted " +connection .getLocalPort ()+" local:" +connection .getPort ());
49
+ connection = ( SSLSocket ) serverSocket .accept ();
50
+ LogWriter .writeDebugInfo ("[SSL Accept] Connection accepted " +connection .getLocalPort ()+" local:" +connection .getPort ());
50
51
if (broker != null ){
51
52
broker .onNewConnection ();
52
53
}
54
+
55
+ // force srart of handshake from server side
56
+ connection .startHandshake ();
57
+
53
58
synchronized (concurentConnections ) {
54
59
concurentConnections .add (connection );
55
60
}
56
61
57
62
Runnable runnable = new ComboxReceiveRequest (broker , requestQueue , new ComboxSecureSocket (connection ));
58
63
Thread thread = new Thread (runnable , "Combox request acceptance" );
59
64
thread .start ();
60
- } catch (IOException e ) {
65
+ } catch (IOException e ) {
66
+ LogWriter .writeDebugInfo ("[SSL Accept] Error while setting up connection: %s" , e .getMessage ());
61
67
break ;
62
68
}
63
69
}
64
70
65
- LogWriter .writeDebugInfo ("Combox Server finished" );
71
+ LogWriter .writeDebugInfo ("[SSL Accept] Combox Server finished" );
66
72
this .close ();
67
73
}
68
74
69
75
/**
70
76
* Close the current connection
71
77
*/
72
78
public void close () {
73
- for (Socket s : concurentConnections ) {
79
+ for (SSLSocket s : concurentConnections ) {
74
80
try {
75
81
s .close ();
76
82
} catch (IOException e ) {
0 commit comments