Skip to content

Instantly share code, notes, and snippets.

@mingliangguo
Created August 21, 2019 15:18
Show Gist options
  • Save mingliangguo/d3afcd904c3357eac5281c648d0ee932 to your computer and use it in GitHub Desktop.
Save mingliangguo/d3afcd904c3357eac5281c648d0ee932 to your computer and use it in GitHub Desktop.
debug_interceptors
public static class DebugHandlerInterceptorAdapter extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
try {
String responseText = IOUtils.toString(request.getReader());
System.out.println("response is:" + responseText);
} catch (IOException e) {
e.printStackTrace();
}
return true;
}
}
public static class TestHandler extends DefaultResponseErrorHandler {
@Override
protected void handleError(ClientHttpResponse response, HttpStatus statusCode) throws IOException {
System.err.println("@@@ statusCode = " + statusCode);
System.err.println("@@@ statusText = " + response.getStatusText());
System.err.println("@@@ headers = " + response.getHeaders());
System.err.println("@@@ body = " + new String(getResponseBody(response), "UTF-8"));
super.handleError(response, statusCode);
}
}
public class TestErrorDecoder implements ErrorDecoder {
@Override
public Exception decode(String methodKey, Response response) {
Response.Body body = response.body();
String responseText = "Unknown response text.";
try {
responseText = CharStreams.toString(body.asReader());
System.out.println("responseText is:\n" + responseText);
} catch (IOException e) {
e.printStackTrace();
}
return new HttpClientErrorException(HttpStatus.valueOf(response.status()), responseText);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment