use of com.sun.appserv.ProxyHandler in project Payara by payara.
the class CoyoteAdapter method doService.
private void doService(final org.glassfish.grizzly.http.server.Request req, final Request request, final org.glassfish.grizzly.http.server.Response res, final Response response, final boolean v3Enabled) throws Exception {
// Check connector for disabled state
if (!connector.isEnabled()) {
String msg = MessageFormat.format(rb.getString(LogFacade.HTTP_LISTENER_DISABLED), String.valueOf(connector.getPort()));
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE, msg);
}
response.sendError(HttpServletResponse.SC_NOT_FOUND, msg);
return;
}
// request parameters
if (postParseRequest(req, request, res, response, v3Enabled)) {
// START S1AS 6188932
boolean authPassthroughEnabled = connector.getAuthPassthroughEnabled();
ProxyHandler proxyHandler = connector.getProxyHandler();
if (authPassthroughEnabled && proxyHandler != null) {
// START SJSAS 6397218
if (proxyHandler.getSSLKeysize((HttpServletRequest) request.getRequest()) > 0) {
request.setSecure(true);
}
// END SJSAS 6397218
X509Certificate[] certs = null;
try {
certs = proxyHandler.getSSLClientCertificateChain(request.getRequest());
} catch (CertificateException ce) {
log.log(Level.SEVERE, LogFacade.PARSING_CLIENT_CERT_EXCEPTION, ce);
}
if (certs != null) {
request.setAttribute(Globals.CERTIFICATES_ATTR, certs);
}
}
// END S1AS 6188932
// // "Server" header is set by GlassfishHttpCodecFilter
// if (serverName != null && !serverName.isEmpty()) {
// response.addHeader("Server", serverName);
// }
// Invoke the web container
connector.requestStartEvent(request.getRequest(), request.getHost(), request.getContext());
Container container = connector.getContainer();
enteringServletContainer(request, response);
try {
request.lockSession();
if (container.getPipeline().hasNonBasicValves() || container.hasCustomPipeline()) {
container.getPipeline().invoke(request, response);
} else {
// Invoke host directly
Host host = request.getHost();
if (host == null) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
String msg = MessageFormat.format(rb.getString(LogFacade.NO_HOST_MATCHES_SERVER_NAME_INFO), request.getRequest().getServerName());
response.setDetailMessage(msg);
return;
}
if (host.getPipeline().hasNonBasicValves() || host.hasCustomPipeline()) {
host.getPipeline().invoke(request, response);
} else {
GlassFishValve hostValve = host.getPipeline().getBasic();
hostValve.invoke(request, response);
// Error handling
hostValve.postInvoke(request, response);
}
}
} finally {
try {
connector.requestEndEvent(request.getRequest(), request.getHost(), request.getContext(), response.getStatus());
} finally {
leavingServletContainer(request, response);
}
}
}
}
use of com.sun.appserv.ProxyHandler in project Payara by payara.
the class CoyoteAdapter method postParseRequest.
// ------------------------------------------------------ Protected Methods
/**
* Parse additional request parameters.
*/
protected boolean postParseRequest(final org.glassfish.grizzly.http.server.Request req, final Request request, final org.glassfish.grizzly.http.server.Response res, final Response response, final boolean v3Enabled) throws Exception {
// XXX the processor may have set a correct scheme and port prior to this point,
// in ajp13 protocols dont make sense to get the port from the connector...
// otherwise, use connector configuration
request.setSecure(req.isSecure());
// URI decoding
DataChunk decodedURI;
try {
decodedURI = req.getRequest().getRequestURIRef().getDecodedRequestURIBC();
} catch (CharConversionException cce) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid URI");
return false;
}
if (compatWithTomcat || !v3Enabled) {
// decodedURI.duplicate(req.requestURI());
// try {
// req.getURLDecoder().convert(decodedURI, false);
// } catch (IOException ioe) {
// res.setStatus(400);
// res.setMessage("Invalid URI: " + ioe.getMessage());
// return false;
// }
/* GlassFish Issue 2339
// Normalize decoded URI
if (!normalize(req.decodedURI())) {
res.setStatus(400);
res.setMessage("Invalid URI");
return false;
}
*/
// Set the remote principal
String principal = req.getRemoteUser();
if (principal != null) {
request.setUserPrincipal(new CoyotePrincipal(principal));
}
// Set the authorization type
String authtype = req.getAuthType();
if (authtype != null) {
request.setAuthType(authtype);
}
/* CR 6309511
// URI character decoding
convertURI(decodedURI, request);
// Parse session Id
parseSessionId(req, request);
*/
// START CR 6309511
// URI character decoding
// request.convertURI(decodedURI);
// START GlassFish Issue 2339
// Normalize decoded URI
// if (!normalize(decodedURI)) {
// res.setStatus(400);
// res.setMessage("Invalid URI");
// return false;
// }
// END GlassFish Issue 2339
}
// END CR 6309511
/*
* Remove any parameters from the URI, so they won't be considered
* by the mapping algorithm, and save them in a temporary CharChunk,
* so that any session id param may be parsed once the target
* context, which may use a custom session parameter name, has been
* identified
*/
final CharChunk uriParamsCC = request.getURIParams();
final CharChunk uriCC = decodedURI.getCharChunk();
final int semicolon = uriCC.indexOf(';');
if (semicolon > 0) {
final int absSemicolon = uriCC.getStart() + semicolon;
uriParamsCC.setChars(uriCC.getBuffer(), absSemicolon, uriCC.getEnd() - absSemicolon);
decodedURI.setChars(uriCC.getBuffer(), uriCC.getStart(), absSemicolon - uriCC.getStart());
}
if (compatWithTomcat || !v3Enabled) {
/*mod_jk*/
DataChunk localDecodedURI = decodedURI;
if (semicolon > 0) {
localDecodedURI = req.getNote(DATA_CHUNK);
if (localDecodedURI == null) {
localDecodedURI = DataChunk.newInstance();
req.setNote(DATA_CHUNK, localDecodedURI);
}
localDecodedURI.duplicate(decodedURI);
}
connector.getMapper().map(req.getRequest().serverName(), localDecodedURI, request.getMappingData());
MappingData md = request.getMappingData();
req.setNote(MAPPING_DATA, md);
request.updatePaths(md);
}
// FIXME: the code below doesnt belongs to here,
// this is only have sense
// in Http11, not in ajp13..
// At this point the Host header has been processed.
// Override if the proxyPort/proxyHost are set
String proxyName = connector.getProxyName();
int proxyPort = connector.getProxyPort();
if (proxyPort != 0) {
req.setServerPort(proxyPort);
}
if (proxyName != null) {
req.setServerName(proxyName);
}
Context ctx = (Context) request.getMappingData().context;
// Parse session id
if (ctx != null) {
if (req.isRequestedSessionIdFromURL() && Globals.SESSION_PARAMETER_NAME.equals(ctx.getSessionParameterName())) {
request.obtainSessionId();
} else if (!uriParamsCC.isNull()) {
// String sessionParam = ";" + ctx.getSessionParameterName() + "=";
request.parseSessionId(ctx.getSessionParameterName(), uriParamsCC);
}
}
// START GlassFish 1024
request.setDefaultContext(request.getMappingData().isDefaultContext);
// END GlassFish 1024
// START SJSAS 6253524
// request.setContext((Context) request.getMappingData().context);
// END SJSAS 6253524
// START SJSAS 6253524
request.setContext(ctx);
if (ctx != null && !uriParamsCC.isNull()) {
request.parseSessionVersion(uriParamsCC);
}
if (!uriParamsCC.isNull()) {
request.parseJReplica(uriParamsCC);
}
request.setWrapper((Wrapper) request.getMappingData().wrapper);
// Filter trace method
if (!connector.getAllowTrace() && Method.TRACE.equals(req.getMethod())) {
Wrapper wrapper = request.getWrapper();
String header = null;
if (wrapper != null) {
String[] methods = wrapper.getServletMethods();
if (methods != null) {
for (String method : methods) {
// Exclude TRACE from methods returned in Allow header
if ("TRACE".equals(method)) {
continue;
}
if (header == null) {
header = method;
} else {
header += ", " + method;
}
}
}
}
res.setStatus(405, "TRACE method is not allowed");
res.addHeader("Allow", header);
return false;
}
// Possible redirect
DataChunk redirectPathMB = request.getMappingData().redirectPath;
// START SJSAS 6253524
if (!redirectPathMB.isNull() && (!ctx.hasAdHocPaths() || (ctx.getAdHocServletName(((HttpServletRequest) request.getRequest()).getServletPath()) == null))) {
// END SJSAS 6253524
String redirectPath = redirectPathMB.toString();
String query = request.getQueryString();
if (request.isRequestedSessionIdFromURL()) {
// This is not optimal, but as this is not very common, it
// shouldn't matter
redirectPath = redirectPath + ";" + ctx.getSessionParameterName() + "=" + request.getRequestedSessionId();
}
// START GlassFish 936
redirectPath = response.encode(redirectPath);
// END GlassFish 936
if (query != null) {
// This is not optimal, but as this is not very common, it
// shouldn't matter
redirectPath = redirectPath + "?" + query;
}
// START CR 6590921
boolean authPassthroughEnabled = connector.getAuthPassthroughEnabled();
ProxyHandler proxyHandler = connector.getProxyHandler();
if (authPassthroughEnabled && proxyHandler != null) {
if (proxyHandler.getSSLKeysize((HttpServletRequest) request.getRequest()) > 0) {
request.setSecure(true);
}
}
// END CR 6590921
// Issue a permanent redirect
response.sendRedirect(redirectPath, false);
return false;
}
// Parse session Id
/* CR 6309511
parseSessionCookiesId(req, request);
*/
// START CR 6309511
request.parseSessionCookiesId();
// END CR 6309511
// START SJSAS 6346226
request.parseJrouteCookie();
return true;
}
use of com.sun.appserv.ProxyHandler in project Payara by payara.
the class PECoyoteConnector method setProxyHandler.
/*
* Loads and instantiates the ProxyHandler implementation
* class with the specified name, and sets the instantiated
* ProxyHandler on this connector.
*
* @param className The ProxyHandler implementation class name
*/
public void setProxyHandler(String className) {
Object handler = null;
try {
Class handlerClass = webContainer.loadCommonClass(className);
handler = handlerClass.newInstance();
} catch (Exception e) {
String msg = MessageFormat.format(_rb.getString(LogFacade.PROXY_HANDLER_CLASS_LOAD_ERROR), className);
_logger.log(Level.SEVERE, msg, e);
}
if (handler != null) {
if (!(handler instanceof ProxyHandler)) {
_logger.log(Level.SEVERE, LogFacade.PROXY_HANDLER_CLASS_INVALID, className);
} else {
setProxyHandler((ProxyHandler) handler);
}
}
}
Aggregations