FileDocCategorySizeDatePackage
MovieClient.javaAPI DocExample2266Sun Jul 07 09:44:48 BST 2002javajaxb

MovieClient.java

package javajaxb;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Properties;

// Connection data binding classes
import javajaxb.generated.config.*;

// Jason Hunter's HttpMessage class
import com.oreilly.servlet.HttpMessage;

public class MovieClient {

    public static void main(String[] args) {
        if (args.length != 1) {
            System.out.println("Usage: java javajaxb.MovieClient " +
                "[XML configuration file]");
            return;
        }

        try {
            File configFile = new File(args[0]);
            FileInputStream inputStream = 
                new FileInputStream(configFile);

            // Unmarshal the connection information
            Connection connection = Connection.unmarshal(inputStream);

            // Determine the data needed
            Host host = connection.getHost();
            Url configURL = connection.getUrl();
            String filename = new StringBuffer("/")
                .append(configURL.getContext())
                .append("/")
                .append(configURL.getServletPrefix())
                .append("/")
                .append(configURL.getServletName())
                .toString();

            // Connect to the servlet
            URL url = new URL("http", 
                              host.getHostname(),
                              Integer.parseInt(host.getPort()),
                              filename);
            HttpMessage msg = new HttpMessage(url);

            // Indicate we want a listing
            Properties props = new Properties();
            props.put("action", "list");

            // Get response
            InputStream in = msg.sendPostMessage(props);
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(in));

            // Output response to screen
            String line = null;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}