summaryrefslogtreecommitdiffstats
path: root/filters
diff options
context:
space:
mode:
Diffstat (limited to 'filters')
-rw-r--r--filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/RequestResponseLoggingFilter.java85
1 files changed, 68 insertions, 17 deletions
diff --git a/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/RequestResponseLoggingFilter.java b/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/RequestResponseLoggingFilter.java
index c49729595..e24a75274 100644
--- a/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/RequestResponseLoggingFilter.java
+++ b/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/RequestResponseLoggingFilter.java
@@ -79,6 +79,9 @@ public class RequestResponseLoggingFilter implements Filter {
private static class ByteArrayPrintWriter extends PrintWriter {
private ByteArrayOutputStream baos;
+ private int errorCode = -1;
+ private String errorMsg = "";
+ private boolean errored = false;
public ByteArrayPrintWriter(ByteArrayOutputStream out) {
super(out);
@@ -88,6 +91,27 @@ public class RequestResponseLoggingFilter implements Filter {
public ServletOutputStream getStream() {
return new ByteArrayServletStream(baos);
}
+
+ public Boolean hasErrored() {
+ return errored;
+ }
+ public int getErrorCode() {
+ return errorCode;
+ }
+ public String getErrorMsg() {
+ return errorMsg;
+ }
+
+ public void setError(int code) {
+ errorCode = code;
+ errored = true;
+ }
+
+ public void setError(int code, String msg) {
+ errorMsg = msg;
+ errorCode = code;
+ errored = true;
+ }
}
@@ -217,6 +241,18 @@ public class RequestResponseLoggingFilter implements Filter {
public ServletOutputStream getOutputStream() {
return pw.getStream();
}
+
+ @Override
+ public void sendError(int sc) throws IOException {
+ super.sendError(sc);
+ pw.setError(sc);
+
+ }
+ @Override
+ public void sendError(int sc, String msg) throws IOException {
+ super.sendError(sc, msg);
+ pw.setError(sc, msg);
+ }
};
try {
@@ -225,29 +261,44 @@ public class RequestResponseLoggingFilter implements Filter {
log.error("Chain Exception", e);
throw e;
} finally {
- byte[] bytes = baos.toByteArray();
- response.getOutputStream().write(bytes);
- response.getOutputStream().flush();
-
- StringBuilder responseHeaders = new StringBuilder("RESPONSE HEADERS|");
-
- for (String headerName : response.getHeaderNames()) {
- responseHeaders.append(headerName);
- responseHeaders.append(":");
- responseHeaders.append(response.getHeader(headerName));
- responseHeaders.append(";");
+ try {
+ byte[] bytes = baos.toByteArray();
+ StringBuilder responseHeaders = new StringBuilder("RESPONSE HEADERS|");
+
+ for (String headerName : response.getHeaderNames()) {
+ responseHeaders.append(headerName);
+ responseHeaders.append(":");
+ responseHeaders.append(response.getHeader(headerName));
+ responseHeaders.append(";");
+ }
+ responseHeaders.append("Status:");
+ responseHeaders.append(response.getStatus());
+ responseHeaders.append(";IsCommited:" + wrappedResp.isCommitted());
+
+ log.info(responseHeaders.toString());
+
+ if ("gzip".equals(response.getHeader("Content-Encoding"))) {
- }
- log.info(responseHeaders.toString());
+ log.info("UNGZIPED RESPONSE BODY|" + decompressGZIPByteArray(bytes));
- if ("gzip".equals(response.getHeader("Content-Encoding"))) {
+ } else {
- log.info("UNGZIPED RESPONSE BODY|" + decompressGZIPByteArray(bytes));
+ log.info("RESPONSE BODY|" + new String(bytes));
+ }
- } else {
+ if (pw.hasErrored()) {
+ log.info("ERROR RESPONSE|" + pw.getErrorCode() + ":" + pw.getErrorMsg());
+ } else {
+ if (!wrappedResp.isCommitted()){
+ response.getOutputStream().write(bytes);
+ response.getOutputStream().flush();
+ }
+ }
- log.info("RESPONSE BODY|" + new String(bytes));
+ } catch (Exception e) {
+ log.error("Exception in response filter", e);
}
+
}
}