Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coupled design #178

Open
alalag1 opened this issue Apr 28, 2022 · 0 comments
Open

coupled design #178

alalag1 opened this issue Apr 28, 2022 · 0 comments
Assignees
Milestone

Comments

@alalag1
Copy link
Member

alalag1 commented Apr 28, 2022

Actual behavior

this windup logic should not appear here

public CompletionStage<Void> process(RequestContext context) {
return super.process(context).whenComplete((v, th) -> {
if (th != null) {
DispatcherHandlerImpl.handleException(context, Futures.unwrapCompletionException(th));
}
final HandlerMethod method = RouteTracking.matchedMethod(context);
final List<MediaType> mediaTypes = ResponseEntityUtils.getMediaTypes(context);
final ResponseEntity entity = new ResponseEntityImpl(method, context.response(),
mediaTypes.isEmpty() ? null : mediaTypes.get(0));
HandlerResolverFactory resolverFactory = getResolverFactory(method);
final ResponseEntityResolverContext rspCtx = new ResponseEntityResolverContextImpl(context,
entity, channelFactory.create(context), resolverFactory.getResponseEntityResolvers(method),
resolverFactory.getResponseEntityResolverAdvices(method));
setEntityTypeIfNecessary(rspCtx, context.response());
final HttpRequest request = context.request();
try {
rspCtx.proceed();
if (!rspCtx.channel().isCommitted()) {
logger.error("The response entity({}) of request(url={}, method={}) still haven't been committed"
+ " after all ResponseEntity advices, maybe the write operation was terminated by"
+ " an advice?", entity, request.path(), request.method());
rspCtx.context().response().status(HttpStatus.INTERNAL_SERVER_ERROR.code());
rspCtx.channel().end();
}
} catch (Throwable ex) {
if (!rspCtx.channel().isCommitted()) {
logger.error("Error occurred when writing response entity({}) of request(url={}, method={})",
entity, request.path(), request.method(), ex);
final HttpStatus status;
if (ex instanceof WebServerException) {
status = ((WebServerException) ex).status();
} else {
status = HttpStatus.INTERNAL_SERVER_ERROR;
}
rspCtx.context().response().status(status.code());
rspCtx.channel().end();
} else {
logger.error("Unexpected error occurred after committing response entity({})" +
" of request(url={}, method={})", entity, request.path(), request.method(), ex);
}
}
if (logger.isDebugEnabled()) {
logger.debug("Request(url={}, method={}) completed. {}",
request.path(), request.method(), context.response().status());
}
});
}

Env

  • Restlight version:
  • JVM version:
  • OS:
@LCDZhao-Z LCDZhao-Z self-assigned this May 6, 2022
@LCDZhao-Z LCDZhao-Z added this to the v1.0.1 milestone May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants