You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ya...@apache.org on 2019/10/26 01:51:41 UTC
[servicecomb-java-chassis] branch master updated: [SCB-1525]print
codec error stack (#1349)
This is an automated email from the ASF dual-hosted git repository.
yaohaishi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push:
new 332ef45 [SCB-1525]print codec error stack (#1349)
332ef45 is described below
commit 332ef45ce238bbe702884dd88abbd22cb01e4d79
Author: bao liu <bi...@qq.com>
AuthorDate: Sat Oct 26 09:51:29 2019 +0800
[SCB-1525]print codec error stack (#1349)
* [SCB-1525]print codec error stack
---
.../apache/servicecomb/common/rest/RestConst.java | 2 ++
.../servicecomb/common/rest/codec/RestCodec.java | 22 ++++++++++++++++------
.../swagger/engine/SwaggerProducerOperation.java | 14 ++++++++------
3 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/RestConst.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/RestConst.java
index afdc96b..454ac62 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/RestConst.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/RestConst.java
@@ -72,4 +72,6 @@ public final class RestConst {
public static final String UPLOAD_FILE_SIZE_THRESHOLD = "servicecomb.uploads.fileSizeThreshold";
public static final String PROVIDER_SCAN_REST_CONTROLLER = "servicecomb.provider.rest.scanRestController";
+
+ public static final String PRINT_CODEC_ERROR_MESSGAGE = "servicecomb.codec.printErrorMessage";
}
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestCodec.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestCodec.java
index a1bf32d..24101cc 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestCodec.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestCodec.java
@@ -22,12 +22,15 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Response.Status;
+import org.apache.servicecomb.common.rest.RestConst;
import org.apache.servicecomb.common.rest.definition.RestOperationMeta;
import org.apache.servicecomb.common.rest.definition.RestParam;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.netflix.config.DynamicPropertyFactory;
+
public final class RestCodec {
private static final Logger LOG = LoggerFactory.getLogger(RestCodec.class);
@@ -61,12 +64,19 @@ public final class RestCodec {
try {
paramValues[idx] = param.getParamProcessor().getValue(request);
} catch (Exception e) {
- // Avoid information leak of user input.
- throw new InvocationException(Status.BAD_REQUEST,
- String.format("Parameter is not valid for operation [%s]. Parameter is [%s]. Processor is [%s].",
- restOperation.getOperationMeta().getMicroserviceQualifiedName(),
- param.getParamName(),
- param.getParamProcessor().getProcessorType()));
+ // Avoid information leak of user input, and add option for debug use.
+ String message = String.format("Parameter is not valid for operation [%s]. Parameter is [%s]. Processor is [%s].",
+ restOperation.getOperationMeta().getMicroserviceQualifiedName(),
+ param.getParamName(),
+ param.getParamProcessor().getProcessorType());
+ if (DynamicPropertyFactory.getInstance().getBooleanProperty(
+ RestConst.PRINT_CODEC_ERROR_MESSGAGE, false).get()) {
+ LOG.error(message, e);
+ throw new InvocationException(Status.BAD_REQUEST.getStatusCode(), "", message, e);
+ } else {
+ LOG.error("{} Add {}=true to print the details.", message, RestConst.PRINT_CODEC_ERROR_MESSGAGE);
+ throw new InvocationException(Status.BAD_REQUEST, message);
+ }
}
}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java
index 5be9562..5619c15 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java
@@ -152,15 +152,16 @@ public class SwaggerProducerOperation {
asyncResp.handle(processException(invocation, ex));
});
} catch (IllegalArgumentException ae) {
+ LOGGER.error("Parameters not valid or types not match {},",
+ invocation.getInvocationQualifiedName(), ae);
invocation.onBusinessMethodFinish();
invocation.onBusinessFinish();
asyncResp.handle(processException(invocation,
new InvocationException(Status.BAD_REQUEST.getStatusCode(), "",
new CommonExceptionData("Parameters not valid or types not match."), ae)));
- LOGGER.error("Parameters not valid or types not match {}, "
- + "debug this line to find the actual decode errors.",
- invocation.getInvocationQualifiedName());
} catch (Throwable e) {
+ LOGGER.error("unexpected error {},",
+ invocation.getInvocationQualifiedName(), e);
invocation.onBusinessMethodFinish();
invocation.onBusinessFinish();
asyncResp.handle(processException(invocation, e));
@@ -190,16 +191,17 @@ public class SwaggerProducerOperation {
invocation.onBusinessMethodFinish();
invocation.onBusinessFinish();
} catch (IllegalArgumentException ae) {
+ LOGGER.error("Parameters not valid or types not match {},",
+ invocation.getInvocationQualifiedName(), ae);
invocation.onBusinessMethodFinish();
invocation.onBusinessFinish();
// ae.getMessage() is always null. Give a custom error message.
response = processException(invocation,
new InvocationException(Status.BAD_REQUEST.getStatusCode(), "",
new CommonExceptionData("Parameters not valid or types not match."), ae));
- LOGGER.error("Parameters not valid or types not match {}, "
- + "debug this line to find the actual decode errors.",
- invocation.getInvocationQualifiedName());
} catch (Throwable e) {
+ LOGGER.error("unexpected error {},",
+ invocation.getInvocationQualifiedName(), e);
invocation.onBusinessMethodFinish();
invocation.onBusinessFinish();
response = processException(invocation, e);