⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpserver.java

📁 数字图书馆的互操作接口
💻 JAVA
字号:
package dli2fe.http;

/**
 * Title:        Digial Library Interoperable Interface Fudan Edition
 * Description:  This project contains all the classes required for DLI2FE interface. Developers use these classes to implement the wrapper and client side codes. The basic functions of DLI2FE is as follows:
 * Search: Search a digital library source site.
 * Metadata: Fetch metadata for a site.
 * ResultAccess: Get results for a given query.
 * DLI2FE uses Dublin Core as the basic attribute model, DAV/DASL as the general XML-based query language and CORBA as distributed object transportation mechanism.
 * Copyright:    Copyright (c) 2001
 * Company:      Fudan University
 * @author Carl Tao
 * @version 1.0
 */

import java.io.*;
import java.net.*;
import java.util.*;

/**
 * An HTTP layer implementation.
 *
 * @author Sergey Melnik <melnik@db.stanford.edu>
 */

public class HTTPServer extends Thread {

  public final static int DEFAULT_PORT = 80;
  int PRIORITY = Thread.NORM_PRIORITY; // 3; // priority of client threads

  protected ServerSocket  listen_socket;
  protected ThreadGroup   threadgroup;
  String name;

  Hashtable connPool = new Hashtable(); // URL -> Connection (client or server conn)

  // server port it listens to
  int port;

  HTTPCallback callback;

  // General constructor
  public HTTPServer(String name, HTTPCallback callback, int port) throws IOException {

    this.name = name;
    this.callback = callback;
    this.port = port;
    // A ThreadGroup object is created to keep track of existing connections.
    threadgroup = new ThreadGroup("HTTP Connections");
    acceptConnections();
  }

  public HTTPServer(HTTPCallback callback, int port) throws IOException  {
    this(null, callback, port);
  }

  public HTTPServer(HTTPCallback callback) throws IOException  {
    this(null, callback, DEFAULT_PORT);
  }

  public HTTPCallback getCallback() {
    return callback;
  }

  /*
  Search getDispatcher(String what) {

    for(Enumeration en = dispTable.keys(); en.hasMoreElements(); ) {

      String key = (String)en.nextElement();
      if( what.startsWith(key) )
	return (Layer)dispTable.get(key);
    }
    return null;
  }
  */

  // server method
  public void acceptConnections() throws IOException {

    // An attempt is made to create a ServerSocket object.
    listen_socket = new ServerSocket(port);

    //    System.out.println("Listening on " + listen_socket);

    this.start();
  }

  // This is the body of the server thread.  It listens constantly for
  // connection requests from clients.  For each connection, a new
  // Connection object is created to handle communication through the
  // new Socket.  When a new connection is established, it is added to
  // a vector of existing connections, and List object is updated to
  // reflect the new addition.  The SYNCHRONIZED mechanism is used to
  // lock the vector of connections to ensure against redundant operations.
  // The Vulture class does the same, so the vulture won't be removing dead
  // connections while new ones are being added.
  public void run() {

    try {
      while(true) {

	Socket client_socket = listen_socket.accept();
	// assign new state
	//	Resource state = RDFUtil.noname();
	// do not send header, server connection, // no preset dispatcher
	HTTPConnection c = new HTTPConnection(this, client_socket, threadgroup, PRIORITY);
      }
    } catch (IOException e) {
      System.err.println(toString() + " Exception while listening for connections:" + e);
    }
  }

  public String toString() {
    return name != null ? name : "[HTTP Server]";
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -