Java 类org.apache.http.impl.DefaultHttpServerConnection 实例源码

项目:yaacc-code    文件:YaaccUpnpServerService.java   
@Override
public void run() {
    Log.d(getClass().getName(), "Listening on port " + serversocket.getLocalPort());
    while (!Thread.interrupted()) {
        try {
            // Set up HTTP connection
            Socket socket = serversocket.accept();
            DefaultHttpServerConnection connection = new DefaultHttpServerConnection();
            Log.d(getClass().getName(), "Incoming connection from " + socket.getInetAddress());
            connection.bind(socket, params);
            // Start worker thread
            Thread workerThread = new WorkerThread(httpService, connection);
            workerThread.setDaemon(true);
            workerThread.start();
        } catch (InterruptedIOException ex) {
            break;
        } catch (IOException e) {
            Log.d(getClass().getName(), "I/O error initialising connection thread: ", e);
            break;
        }
    }
}
项目:PhET    文件:ElementalHttpServer.java   
public void run() {
    System.out.println("Listening on port " + this.serversocket.getLocalPort());
    while (!Thread.interrupted()) {
        try {
            // Set up HTTP connection
            Socket socket = this.serversocket.accept();
            DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
            System.out.println("Incoming connection from " + socket.getInetAddress());
            conn.bind(socket, this.params);

            // Start worker thread
            Thread t = new WorkerThread(this.httpService, conn);
            t.setDaemon(true);
            t.start();
        } catch (InterruptedIOException ex) {
            break;
        } catch (IOException e) {
            System.err.println("I/O error initialising connection thread: " 
                    + e.getMessage());
            break;
        }
    }
}
项目:cosmic    文件:ApiServer.java   
@Override
public void run() {
    s_logger.info("ApiServer listening on port " + _serverSocket.getLocalPort());
    while (!Thread.interrupted()) {
        try {
            // Set up HTTP connection
            final Socket socket = _serverSocket.accept();
            final DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
            conn.bind(socket, _params);

            // Execute a new worker task to handle the request
            s_executor.execute(new WorkerTask(_httpService, conn, s_workerCount++));
        } catch (final InterruptedIOException ex) {
            break;
        } catch (final IOException e) {
            s_logger.error("I/O error initializing connection thread", e);
            break;
        }
    }
}
项目:Camel    文件:HttpTestServer.java   
@Override
public void run() {
    try {
        while (!interrupted()) {
            Socket socket = servicedSocket.accept();
            acceptedConnections.incrementAndGet();
            DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
            conn.bind(socket, httpservice.getParams());
            // Start worker thread
            Worker worker = new Worker(conn);
            workers.add(worker);
            worker.setDaemon(true);
            worker.start();
        }
    } catch (Exception ex) {
        this.exception = ex;
    } finally {
        try {
            servicedSocket.close();
        } catch (IOException ignore) {
        }
    }
}
项目:esper    文件:EsperHttpServiceClassicRunnable.java   
public void run() {
    log.info("For service '" + serviceName + "' listening on port " + this.serversocket.getLocalPort());
    while (!Thread.interrupted()) {
        try {
            // Set up HTTP connection
            Socket socket = this.serversocket.accept();
            DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
            log.info("Incoming connection service '" + serviceName + "' from " + socket.getInetAddress());
            conn.bind(socket, this.parameters);

            // Start worker thread
            WorkerThread t = new WorkerThread(this.httpService, conn, this);
            t.setDaemon(true);
            t.start();
            workers.add(t);
        } catch (InterruptedIOException ex) {
            break;
        } catch (IOException e) {
            if (!shutdown) {
                log.error("I/O error initialising connection thread for service '" + serviceName + "' : " + e.getMessage());
            }
            break;
        }
    }
    log.info("For service '" + serviceName + "' listening on port " + this.serversocket.getLocalPort() + " ended socket thread.");
}
项目:dsworkbench    文件:ReportServer.java   
public void run() {
    logger.debug("Listening on port " + this.serversocket.getLocalPort());
    while (!Thread.interrupted()) {
        try {
            // Set up HTTP connection
            Socket socket = this.serversocket.accept();
            DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
            logger.debug("Incoming connection from " + socket.getInetAddress());
            conn.bind(socket, this.params);
            // Start worker thread
            Thread t = new WorkerThread(this.httpService, conn);
            t.setDaemon(true);
            t.start();
        } catch (InterruptedIOException ex) {
            break;
        } catch (IOException e) {
            logger.error("I/O error initialising connection thread: " + e.getMessage(), e);
            break;
        }
    }
}
项目:carbon-platform-integration    文件:SimpleHttpServer.java   
public void run() {
    log.info("Starting HTTP server on port: " + port);
    while (!Thread.interrupted()) {
        try {
            // Set up HTTP connection
            Socket socket = serverSocket.accept();
            DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
            conn.bind(socket, params);
            // Start workers thread
            workerPool.submit(new ServerWorker(conn));
        } catch (IOException e) {
            if (!shutdown) {
                log.error("I/O error while accepting a connection", e);
            }
            break;
        }
    }
}
项目:cloudstack    文件:ApiServer.java   
@Override
public void run() {
    s_logger.info("ApiServer listening on port " + _serverSocket.getLocalPort());
    while (!Thread.interrupted()) {
        try {
            // Set up HTTP connection
            final Socket socket = _serverSocket.accept();
            final DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
            conn.bind(socket, _params);

            // Execute a new worker task to handle the request
            s_executor.execute(new WorkerTask(_httpService, conn, s_workerCount++));
        } catch (final InterruptedIOException ex) {
            break;
        } catch (final IOException e) {
            s_logger.error("I/O error initializing connection thread", e);
            break;
        }
    }
}
项目:CadalWorkspace    文件:Httpd.java   
public void run() {
    System.out.println("Listening on port " + this.serversocket.getLocalPort());
    System.out.println("Point your browser to http://localhost:8088/tutorial/js/tutorial.html");

    while (!Thread.interrupted()) {
        try {
            // Set up HTTP connection
            Socket socket = this.serversocket.accept();
            DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
            System.out.println("Incoming connection from " + socket.getInetAddress());
            conn.bind(socket, this.params);

            // Start worker thread
            Thread t = new WorkerThread(this.httpService, conn);
            t.setDaemon(true);
            t.start();
        } catch (InterruptedIOException ex) {
            break;
        } catch (IOException e) {
            System.err.println("I/O error initialising connection thread: " + e.getMessage());
            break;
        }
    }
}
项目:CadalWorkspace    文件:Httpd.java   
public void run() {
    System.out.println("Listening on port " + this.serversocket.getLocalPort());
    System.out.println("Point your browser to http://localhost:8088/test/test.html");

    while (!Thread.interrupted()) {
        try {
            // Set up HTTP connection
            Socket socket = this.serversocket.accept();
            DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
            System.out.println("Incoming connection from " + socket.getInetAddress());
            conn.bind(socket, this.params);

            // Start worker thread
            Thread t = new WorkerThread(this.httpService, conn);
            t.setDaemon(true);
            t.start();
        } catch (InterruptedIOException ex) {
            break;
        } catch (IOException e) {
            System.err.println("I/O error initialising connection thread: " + e.getMessage());
            break;
        }
    }
}
项目:tunebot    文件:WebServer.java   
@Override
public void run() {
    System.out.println("Listening on port " + this.serversocket.getLocalPort());
    while (!Thread.interrupted()) {
        try {
            // Set up HTTP connection
            Socket socket = this.serversocket.accept();
            DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
            System.out.println("Incoming connection from " + socket.getInetAddress());
            conn.bind(socket, this.params);

            // Start worker thread
            Thread t = new WorkerThread(this.httpService, conn);
            t.setDaemon(true);
            t.start();
        } catch (InterruptedIOException ex) {
            break;
        } catch (IOException e) {
            System.err.println("I/O error initialising connection thread: "
                    + e.getMessage());
            break;
        }
    }
}
项目:PhET    文件:ElementalReverseProxy.java   
public void run() {
    System.out.println("Listening on port " + this.serversocket.getLocalPort());
    while (!Thread.interrupted()) {
        try {
            // Set up incoming HTTP connection
            Socket insocket = this.serversocket.accept();
            DefaultHttpServerConnection inconn = new DefaultHttpServerConnection();
            System.out.println("Incoming connection from " + insocket.getInetAddress());
            inconn.bind(insocket, this.params);

            // Set up outgoing HTTP connection
            Socket outsocket = new Socket(this.target.getHostName(), this.target.getPort());
            DefaultHttpClientConnection outconn = new DefaultHttpClientConnection();
            outconn.bind(outsocket, this.params);
            System.out.println("Outgoing connection to " + outsocket.getInetAddress());

            // Start worker thread
            Thread t = new ProxyThread(this.httpService, inconn, outconn);
            t.setDaemon(true);
            t.start();
        } catch (InterruptedIOException ex) {
            break;
        } catch (IOException e) {
            System.err.println("I/O error initialising connection thread: " 
                    + e.getMessage());
            break;
        }
    }
}
项目:hssd    文件:RequestListenerThread.java   
private void listen() throws InterruptedIOException, IOException {
    // Set up HTTP connection
    Socket socket = this.serversocket.accept();
    log.infof("Incoming connection from %s", socket.getInetAddress());

    DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
    conn.bind(socket, this.params);

    // Start worker thread
    Thread t = new WorkerThread(this.httpService, conn);
    t.setDaemon(true);
    t.start();
}
项目:WifiTransfer    文件:SingleConnection.java   
/**
 * Sends the Http header for a file download.
 * @param conn The connection the download header will be sent to.
 * @param hr The request that this header will be responding to.
 *           Used for the purposes of giving a ProtocolVersion
 * @param desiredFile The file that is being downloaded, about which name is needed.
 */
private void sendFileDownloadHeader(DefaultHttpServerConnection conn, HttpRequest hr, File desiredFile) {
    BasicHttpResponse response = new BasicHttpResponse(hr.getProtocolVersion(), HttpStatus.SC_OK, null);
    response.addHeader("Content-Disposition", "attachment; filename=" + desiredFile.getName());
    try {
        conn.sendResponseHeader(response);
    } catch (HttpException | IOException e) {
        e.printStackTrace();
    }
}
项目:WifiTransfer    文件:SingleConnection.java   
/**
     * Sends OK (200) Http response code on a connection.
     * @param conn The connection the header will be sent to.
     * @param hr The request that this header will be responding to.
     *           Used for the purposes of giving a ProtocolVersion
     */
    private void sendOk(DefaultHttpServerConnection conn, HttpRequest hr) {
        try {
            conn.sendResponseHeader(new BasicHttpResponse(hr.getProtocolVersion(), HttpStatus.SC_ACCEPTED, null));
        } catch (IOException ex) {
//            System.out.println("http headers couldn't send");
        } catch (HttpException e) {
            e.printStackTrace();
        }
    }
项目:WifiTransfer    文件:SingleConnection.java   
/**
     * Sends Continue (100) Http status code on a connection.
     * Used when uploading files, to tell the client to send the file data.
     * @param conn The connection the header will be sent to.
     * @param hr The request that this header will be responding to.
     *           Used for the purposes of giving a ProtocolVersion.
     */
    private void sendContinue(DefaultHttpServerConnection conn, HttpRequest hr) {
        try {
            conn.sendResponseHeader(new BasicHttpResponse(hr.getProtocolVersion(), HttpStatus.SC_CONTINUE, null));
        } catch (IOException ex) {
//            System.out.println("http headers couldn't send");
        } catch (HttpException e) {
            e.printStackTrace();
        }
    }
项目:irond    文件:RemotePDP.java   
public HandleXacmlRequest(Socket sock, LocalSunXacml pdp) throws IOException {
    mSocket = sock;
    mConn = new DefaultHttpServerConnection();
    HttpParams params = new BasicHttpParams();
    mConn.bind(mSocket, params);
    mPdp = pdp;
}
项目:WifiTransfer    文件:SingleConnection.java   
private void serveFile(String fileName, File dir, DefaultHttpServerConnection conn, HttpRequest request, BufferedOutputStream output) {

        File desiredFile = new File(dir, fileName);

//        System.out.println("file created: " + desiredFile.getAbsolutePath());


        CheckBox cb = (CheckBox) mainActivity.findViewById(R.id.checkbox_download);
        if (!cb.isChecked()) {
            mainActivity.makeToast("Download attempted by " + sock.getInetAddress() + ", and failed", false);
            sendOk(conn, request);
            return;
        }
        if(desiredFile.canRead()) // serve it
        {
            sendFileDownloadHeader(conn, request, desiredFile);
            BufferedInputStream fis;
//            System.out.println("file exists");
            try {
                fis = new BufferedInputStream(new FileInputStream(desiredFile), 100000);
            } catch(IOException ex){
                ex.printStackTrace();
                return; // kill it early if for some reason can't read the file.
            }

            byte[] buf = new byte[100000];
            int bytesRead = 0;
            try {
                bytesRead = fis.read(buf);
                while(bytesRead >= 0)
                {
                    output.write(buf, 0, bytesRead);
                    bytesRead = fis.read(buf);
                }
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
                return;
            }
            mainActivity.makeToast("File sent: " + fileName, false);

        }
    }
项目:DroidDLNA    文件:StreamServerImpl.java   
public ApacheServerConnection(Socket socket, DefaultHttpServerConnection connection) {
    this.socket = socket;
    this.connection = connection;
}
项目:irond    文件:ChannelThread.java   
private DefaultHttpServerConnection getDefaultHttpServerConnection(Socket s)
        throws IOException {
    DefaultHttpServerConnection hsc = new DefaultHttpServerConnection();
    hsc.bind(s, new BasicHttpParams());
    return hsc;
}