use of org.openecard.apache.http.impl.DefaultBHttpServerConnection 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();
}
}
}
}
Aggregations