use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.
the class ProxyEndpoint method massageRequestURI.
private static HttpRequestMessage massageRequestURI(HttpRequestMessage request) {
final SessionContext context = request.getContext();
String modifiedPath;
HttpQueryParams modifiedQueryParams = null;
String uri = null;
if (context.get("requestURI") != null) {
uri = (String) context.get("requestURI");
}
// If another filter has specified an overrideURI, then use that instead of requested URI.
final Object override = context.get("overrideURI");
if (override != null) {
uri = override.toString();
}
if (null != uri) {
int index = uri.indexOf('?');
if (index != -1) {
// Strip the query string off of the URI.
String paramString = uri.substring(index + 1);
modifiedPath = uri.substring(0, index);
try {
paramString = URLDecoder.decode(paramString, "UTF-8");
modifiedQueryParams = new HttpQueryParams();
StringTokenizer stk = new StringTokenizer(paramString, "&");
while (stk.hasMoreTokens()) {
String token = stk.nextToken();
int idx = token.indexOf("=");
if (idx != -1) {
String key = token.substring(0, idx);
String val = token.substring(idx + 1);
modifiedQueryParams.add(key, val);
}
}
} catch (UnsupportedEncodingException e) {
LOG.error("Error decoding url query param - " + paramString, e);
}
} else {
modifiedPath = uri;
}
request.setPath(modifiedPath);
if (null != modifiedQueryParams) {
request.setQueryParams(modifiedQueryParams);
}
}
return request;
}
use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.
the class ZuulFilterChainHandler method exceptionCaught.
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
LOG.error("zuul filter chain handler caught exception. cause=" + String.valueOf(cause), cause);
if (zuulRequest != null && !isClientChannelClosed(cause)) {
final SessionContext zuulCtx = zuulRequest.getContext();
zuulCtx.setError(cause);
zuulCtx.setShouldSendErrorResponse(true);
sendResponse(FAILURE_LOCAL, 500, ctx);
} else {
fireEndpointFinish(true);
ctx.close();
}
}
use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.
the class ZuulFilterChainHandler method sendResponse.
private void sendResponse(final StatusCategory statusCategory, final int status, ChannelHandlerContext ctx) {
if (zuulRequest == null) {
ctx.close();
} else {
final SessionContext zuulCtx = zuulRequest.getContext();
StatusCategoryUtils.storeStatusCategoryIfNotAlreadyFailure(zuulCtx, statusCategory);
final HttpResponseMessage zuulResponse = new HttpResponseMessageImpl(zuulCtx, zuulRequest, status);
final Headers headers = zuulResponse.getHeaders();
headers.add("Connection", "close");
headers.add("Content-Length", "0");
zuulResponse.finishBufferedBodyIfIncomplete();
responseFilterChain.filter(zuulResponse);
fireEndpointFinish(true);
}
}
Aggregations