private void runProtected (final Operation operation, final HttpExchange request) throws IOException
  {
    final OutputStream responseBody = request.getResponseBody();
    try {
      request.getResponseHeaders().add("Content-Type", "text/html");
      operation.run(request);
    } catch (final IllegalURIPathException ex) {
      log(ex);
      sendResponseHeaders(HttpURLConnection.HTTP_BAD_REQUEST, ex.getMessage(), request, responseBody);
    } catch (final IllegalArgumentException ex) {
      log(ex);
      sendResponseHeaders(HttpURLConnection.HTTP_FORBIDDEN, ex.getMessage(), request, responseBody);
    } catch (final UnauthorizedException ex) {
      log(ex);
      sendResponseHeaders(HttpURLConnection.HTTP_UNAUTHORIZED, ex.getMessage(), request, responseBody);
    } catch (final UnsupportedMethodException ex) {
      log(ex);
      final Headers headers = request.getResponseHeaders();
      headers.add("ALLOW", "GET");
      headers.add("ALLOW", "POST");
      sendResponseHeaders(HttpURLConnection.HTTP_BAD_METHOD, ex.getMessage(), request, responseBody);
      
    } catch (final Exception ex) {
      log(ex);
      sendResponseHeaders(HttpURLConnection.HTTP_INTERNAL_ERROR, ex.getMessage(), request, responseBody);
    }
    finally {
      responseBody.close();
    }
  }