use of com.netflix.zuul.exception.ZuulException in project zuul by Netflix.
the class OriginResponseReceiver method writeInternal.
private void writeInternal(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (!ctx.channel().isActive()) {
ReferenceCountUtil.release(msg);
return;
}
if (msg instanceof HttpRequestMessage) {
promise.addListener((future) -> {
if (!future.isSuccess()) {
Throwable cause = ctx.channel().attr(SSL_HANDSHAKE_UNSUCCESS_FROM_ORIGIN_THROWABLE).get();
if (cause != null) {
// Set the specific SSL handshake error if the handlers have already caught them
ctx.channel().attr(SSL_HANDSHAKE_UNSUCCESS_FROM_ORIGIN_THROWABLE).set(null);
fireWriteError("request headers", cause, ctx);
LOG.debug("SSLException is overridden by SSLHandshakeException caught in handler level. Original SSL exception message: ", future.cause());
} else {
fireWriteError("request headers", future.cause(), ctx);
}
}
});
HttpRequestMessage zuulReq = (HttpRequestMessage) msg;
preWriteHook(ctx, zuulReq);
super.write(ctx, buildOriginHttpRequest(zuulReq), promise);
} else if (msg instanceof HttpContent) {
promise.addListener((future) -> {
if (!future.isSuccess()) {
fireWriteError("request content chunk", future.cause(), ctx);
}
});
super.write(ctx, msg, promise);
} else {
// should never happen
ReferenceCountUtil.release(msg);
throw new ZuulException("Received invalid message from client", true);
}
}
use of com.netflix.zuul.exception.ZuulException in project zuul by Netflix.
the class ProxyEndpoint method handleError.
private void handleError(final Throwable cause) {
final ZuulException ze = (cause instanceof ZuulException) ? (ZuulException) cause : requestAttemptFactory.mapNettyToOutboundException(cause, context);
LOG.debug("Proxy endpoint failed.", cause);
if (!startedSendingResponseToClient) {
startedSendingResponseToClient = true;
zuulResponse = new HttpResponseMessageImpl(context, zuulRequest, ze.getStatusCode());
// TODO - why close the connection? maybe don't always want this to happen ...
zuulResponse.getHeaders().add("Connection", "close");
zuulResponse.finishBufferedBodyIfIncomplete();
invokeNext(zuulResponse);
} else {
channelCtx.fireExceptionCaught(ze);
}
}
use of com.netflix.zuul.exception.ZuulException in project zuul by Netflix.
the class ZuulServlet method service.
@Override
public void service(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse) throws ServletException, IOException {
try {
init((HttpServletRequest) servletRequest, (HttpServletResponse) servletResponse);
// Marks this request as having passed through the "Zuul engine", as opposed to servlets
// explicitly bound in web.xml, for which requests will not have the same data attached
RequestContext context = RequestContext.getCurrentContext();
context.setZuulEngineRan();
try {
preRoute();
} catch (ZuulException e) {
error(e);
postRoute();
return;
}
try {
route();
} catch (ZuulException e) {
error(e);
postRoute();
return;
}
try {
postRoute();
} catch (ZuulException e) {
error(e);
return;
}
} catch (Throwable e) {
error(new ZuulException(e, 500, "UNHANDLED_EXCEPTION_" + e.getClass().getName()));
} finally {
RequestContext.getCurrentContext().unset();
}
}
use of com.netflix.zuul.exception.ZuulException in project paascloud-master by paascloud.
the class AuthHeaderFilter method doSomething.
private void doSomething(RequestContext requestContext) throws ZuulException {
HttpServletRequest request = requestContext.getRequest();
String requestURI = request.getRequestURI();
if (OPTIONS.equalsIgnoreCase(request.getMethod()) || !requestURI.contains(AUTH_PATH) || !requestURI.contains(LOGOUT_URI) || !requestURI.contains(ALIPAY_CALL_URI)) {
return;
}
String authHeader = RequestUtil.getAuthHeader(request);
if (PublicUtil.isEmpty(authHeader)) {
throw new ZuulException("刷新页面重试", 403, "check token fail");
}
if (authHeader.startsWith(BEARER_TOKEN_TYPE)) {
requestContext.addZuulRequestHeader(HttpHeaders.AUTHORIZATION, authHeader);
log.info("authHeader={} ", authHeader);
// 传递给后续微服务
requestContext.addZuulRequestHeader(CoreHeaderInterceptor.HEADER_LABEL, authHeader);
}
}
use of com.netflix.zuul.exception.ZuulException in project spring-cloud-netflix by spring-cloud.
the class RibbonRoutingFilter method handleException.
protected ClientHttpResponse handleException(Map<String, Object> info, HystrixRuntimeException ex) throws ZuulException {
int statusCode = HttpStatus.INTERNAL_SERVER_ERROR.value();
Throwable cause = ex;
String message = ex.getFailureType().toString();
ClientException clientException = findClientException(ex);
if (clientException == null) {
clientException = findClientException(ex.getFallbackException());
}
if (clientException != null) {
if (clientException.getErrorType() == ClientException.ErrorType.SERVER_THROTTLED) {
statusCode = HttpStatus.SERVICE_UNAVAILABLE.value();
}
cause = clientException;
message = clientException.getErrorType().toString();
}
info.put("status", String.valueOf(statusCode));
throw new ZuulException(cause, "Forwarding error", statusCode, message);
}
Aggregations