Search in sources :

Example 1 with ConnectionClosedException

use of org.openecard.apache.http.ConnectionClosedException in project open-ecard by ecsec.

the class HttpService method run.

@Override
public void run() {
    while (!Thread.interrupted()) {
        try {
            final DefaultBHttpServerConnection connection;
            CharsetDecoder dec = Charset.forName("UTF-8").newDecoder();
            CharsetEncoder enc = Charset.forName("UTF-8").newEncoder();
            connection = new DefaultBHttpServerConnection(8192, dec, enc, null);
            connection.bind(accept());
            new Thread() {

                @Override
                public void run() {
                    try {
                        while (connection.isOpen()) {
                            service.handleRequest(connection, new BasicHttpContext());
                        }
                    } catch (ConnectionClosedException ex) {
                    // connection closed by client, this is the expected outcome
                    } catch (org.openecard.apache.http.HttpException ex) {
                        LOG.error("Error processing HTTP request or response.", ex);
                    } catch (IOException ex) {
                        LOG.error("IO Error while processing HTTP request or response.", ex);
                    } finally {
                        try {
                            connection.shutdown();
                        } catch (IOException ignore) {
                        }
                    }
                }
            }.start();
        } catch (IOException | HttpServiceError ex) {
            // if interrupted the error is intentionally (SocketClosedException)
            if (!Thread.interrupted()) {
                LOG.error(ex.getMessage(), ex);
            } else {
                // set interrupt status again after reading it
                thread.interrupt();
            }
        }
    }
}
Also used : CharsetDecoder(java.nio.charset.CharsetDecoder) BasicHttpContext(org.openecard.apache.http.protocol.BasicHttpContext) ConnectionClosedException(org.openecard.apache.http.ConnectionClosedException) IOException(java.io.IOException) CharsetEncoder(java.nio.charset.CharsetEncoder) DefaultBHttpServerConnection(org.openecard.apache.http.impl.DefaultBHttpServerConnection)

Aggregations

IOException (java.io.IOException)1 CharsetDecoder (java.nio.charset.CharsetDecoder)1 CharsetEncoder (java.nio.charset.CharsetEncoder)1 ConnectionClosedException (org.openecard.apache.http.ConnectionClosedException)1 DefaultBHttpServerConnection (org.openecard.apache.http.impl.DefaultBHttpServerConnection)1 BasicHttpContext (org.openecard.apache.http.protocol.BasicHttpContext)1