01: package cli;
02:
03: import java.io.*;
04: import java.net.HttpURLConnection;
05: import java.net.URL;
06:
07: import db.Hello;
08: import db.HelloImpl;
09: import org.ozoneDB.ExternalDatabase;
10: import org.ozoneDB.OzoneInterface;
11:
12: public class HelloClient {
13:
14: private static Hello hello;
15: private static ExternalDatabase db;
16: private static String OBJ_NAME = "hej";
17:
18: public static void main(String[] args) {
19: try {
20: buildObject();
21: callServlet();
22: } catch (Exception e) {
23: e.printStackTrace();
24: }
25: }
26:
27: private static void buildObject() throws Exception {
28: System.out.println("Trying to connect to ozone...");
29: db = ExternalDatabase
30: .openDatabase("ozonedb:remote://localhost:3333");
31: System.out.println("....Connected to ozone");
32: db.reloadClasses();
33: System.out.println("....Classes reloaded");
34: hello = (Hello) db.objectForName(OBJ_NAME);
35: if (hello == null) {
36: System.out.println("Storing new Hello object");
37: hello = (Hello) db.createObject(HelloImpl.class.getName(),
38: OzoneInterface.Public, OBJ_NAME);
39: } else {
40: System.out.println("Found existing Hello object");
41: }
42: System.out.println("db.Hello has the following greeting: "
43: + hello.getGreeting());
44: db.close();
45: }
46:
47: private static void callServlet() throws IOException {
48: URL url = new URL("http", "localhost", 80,
49: "/SimpleOzoneServlet/HelloServlet");
50: System.out.println("Connecting to " + url);
51: HttpURLConnection connection = (HttpURLConnection) url
52: .openConnection();
53: BufferedReader reader = new BufferedReader(
54: new InputStreamReader(connection.getInputStream()));
55: String response = reader.readLine();
56: do {
57: System.out.println(response);
58: response = reader.readLine();
59: } while (response != null);
60: }
61: }
|