licensing update to APSL 2.0
[org.ibex.net.git] / src / org / ibex / net / ssl / Test.java
1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
4
5 package org.ibex.net.ssl;
6
7 import org.ibex.net.SSL;
8 import java.io.*;
9
10 public class Test {
11     public static void main(String[] args) throws Exception {
12         SSL.debugOn = true;
13         if(args.length < 2) { System.err.println("Usage: SSL host port"); }
14         String host = args[0];
15         int port = Integer.parseInt(args[1]);
16         SSL ssl = new SSL(host,port);
17         //ssl.setTLS(false);
18         ssl.getOutputStream().write(SSL.getBytes("GET / HTTP/1.0\r\nHost: " + host + "\r\n\r\n"));
19         cat(ssl.getInputStream());
20         ssl.close();
21         
22         // try to resume
23         ssl = new SSL(host,port,ssl.getSessionState());
24         ssl.getOutputStream().write(SSL.getBytes("GET / HTTP/1.0\r\nHost: " + host + "\r\n\r\n"));
25         cat(ssl.getInputStream());
26         ssl.close();
27     }
28     private static void cat(InputStream is) throws IOException {
29         BufferedReader br = new BufferedReader(new InputStreamReader(is));
30         String line;
31         int count = 100;
32         try {
33             while((line = br.readLine()) != null && --count >= 0) System.out.println(line);
34         } catch(SSL.PrematureCloseExn e) { /* ignore */ }
35     }
36 }