KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > TestServer


1 /*
2  * Created on 08-May-2005
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6 */

7
8
9 import com.maverick.http.GetMethod;
10 import com.maverick.http.HttpClient;
11 import com.maverick.http.HttpResponse;
12 import com.maverick.http.PasswordCredentials;
13 import com.maverick.multiplex.Channel;
14 import com.maverick.multiplex.ChannelFactory;
15 import com.maverick.multiplex.MultiplexedConnection;
16 import com.maverick.multiplex.SocketChannel;
17
18 /**
19  * @author lee
20  *
21  * TODO To change the template for this generated type comment go to
22  * Window - Preferences - Java - Code Style - Code Templates
23  */

24 public class TestServer {
25
26
27     public void processRequest(String JavaDoc requestName, byte[] requestData) {
28         
29         if(requestName.equals("authorizationTicket")) {
30             System.out.println("Received authorization ticket " + new String JavaDoc(requestData));
31         }
32     }
33
34     MultiplexedConnection c;
35
36
37     public TestServer() {
38
39         
40         
41         try {
42         
43             System.setProperty("com.maverick.ssl.allowUntrustedCertificates", "true");
44             System.setProperty("com.maverick.ssl.allowInvalidCertificates", "true");
45             
46             HttpClient client = new HttpClient("127.0.0.1", 443, true);
47             GetMethod get = new GetMethod("AGENT", "/");
48             client.setCredentials(new PasswordCredentials("lee", "xxxxxxxxxx"));
49             client.setPreemtiveAuthentication(true);
50             
51             HttpResponse response = client.execute(get);
52             
53             c = new MultiplexedConnection(new SocketChannelFactory());
54
55             c.startProtocol(response.getConnection().getInputStream(), response.getConnection().getOutputStream(), false);
56
57         } catch (Exception JavaDoc ex) {
58             ex.printStackTrace();
59         }
60
61     }
62
63
64     public static void main(String JavaDoc[] args) {
65         TestServer t = new TestServer();
66     }
67
68     class SocketChannelFactory implements ChannelFactory {
69
70             public Channel createChannel(MultiplexedConnection connection, String JavaDoc type) {
71                 
72                 if(type.equals(SocketChannel.CHANNEL_TYPE))
73                     return new SocketChannel();
74                 else
75                     return null;
76             }
77     }
78 }
79
Popular Tags