use of com.sun.net.httpserver.HttpsExchange in project jersey by jersey.
the class JdkHttpHandlerContainer method handle.
@Override
public void handle(final HttpExchange exchange) throws IOException {
/**
* This is a URI that contains the path, query and fragment components.
*/
URI exchangeUri = exchange.getRequestURI();
/**
* The base path specified by the HTTP context of the HTTP handler. It
* is in decoded form.
*/
String decodedBasePath = exchange.getHttpContext().getPath();
// Ensure that the base path ends with a '/'
if (!decodedBasePath.endsWith("/")) {
if (decodedBasePath.equals(exchangeUri.getPath())) {
/**
* This is an edge case where the request path does not end in a
* '/' and is equal to the context path of the HTTP handler.
* Both the request path and base path need to end in a '/'
* Currently the request path is modified.
*
* TODO support redirection in accordance with resource configuration feature.
*/
exchangeUri = UriBuilder.fromUri(exchangeUri).path("/").build();
}
decodedBasePath += "/";
}
/*
* The following is madness, there is no easy way to get the complete
* URI of the HTTP request!!
*
* TODO this is missing the user information component, how can this be obtained?
*/
final boolean isSecure = exchange instanceof HttpsExchange;
final String scheme = isSecure ? "https" : "http";
final URI baseUri = getBaseUri(exchange, decodedBasePath, scheme);
final URI requestUri = getRequestUri(exchange, baseUri);
final ResponseWriter responseWriter = new ResponseWriter(exchange);
final ContainerRequest requestContext = new ContainerRequest(baseUri, requestUri, exchange.getRequestMethod(), getSecurityContext(exchange.getPrincipal(), isSecure), new MapPropertiesDelegate());
requestContext.setEntityStream(exchange.getRequestBody());
requestContext.getHeaders().putAll(exchange.getRequestHeaders());
requestContext.setWriter(responseWriter);
try {
appHandler.handle(requestContext);
} finally {
// if the response was not committed yet by the JerseyApplication
// then commit it and log warning
responseWriter.closeAndLogWarning();
}
}
Aggregations