You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2018/07/19 01:41:22 UTC

[incubator-servicecomb-java-chassis] branch master updated (a230404 -> f722a00)

This is an automated email from the ASF dual-hosted git repository.

liubao pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git.


    from a230404  [SCB-753]NPE when query not exists service
     new 8ade261  [SCB-754] add null pointer check on AbstractRestInvocation.invocation
     new f722a00  [SCB-754] add an IT to test bug trigger situation

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../common/rest/AbstractRestInvocation.java        | 22 +++++++++-------
 .../common/rest/TestAbstractRestInvocation.java    | 20 +++++++++++++++
 .../jaxrs/client/CodeFirstRestTemplateJaxrs.java   | 16 ++++++++++++
 .../jaxrs/server/JaxrsDemoHttpServerFilter.java}   | 30 +++++++++++-----------
 ...servicecomb.common.rest.filter.HttpServerFilter |  2 +-
 5 files changed, 65 insertions(+), 25 deletions(-)
 copy demo/{demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/UserIdFilter.java => demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/JaxrsDemoHttpServerFilter.java} (65%)
 copy demo/{demo-signature => demo-jaxrs/jaxrs-server}/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter (92%)


[incubator-servicecomb-java-chassis] 01/02: [SCB-754] add null pointer check on AbstractRestInvocation.invocation

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 8ade261bbb519c549f6ba35dbbbf3b84d5feadab
Author: yaohaishi <ya...@huawei.com>
AuthorDate: Wed Jul 18 14:51:37 2018 +0800

    [SCB-754] add null pointer check on AbstractRestInvocation.invocation
---
 .../common/rest/AbstractRestInvocation.java        | 22 +++++++++++++---------
 .../common/rest/TestAbstractRestInvocation.java    | 20 ++++++++++++++++++++
 2 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/AbstractRestInvocation.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/AbstractRestInvocation.java
index cb4413b..a467f0b 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/AbstractRestInvocation.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/AbstractRestInvocation.java
@@ -49,8 +49,11 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public abstract class AbstractRestInvocation {
+
   private static final Logger LOGGER = LoggerFactory.getLogger(AbstractRestInvocation.class);
 
+  public static final String UNKNOWN_OPERATION_ID = "UNKNOWN_OPERATION";
+
   protected RestOperationMeta restOperationMeta;
 
   protected Invocation invocation;
@@ -199,9 +202,8 @@ public abstract class AbstractRestInvocation {
     try {
       sendResponse(response);
     } catch (Throwable e) {
-      LOGGER.error("Failed to send rest response, operation:{}.",
-          invocation.getMicroserviceQualifiedName(),
-          e);
+      LOGGER.error("Failed to send rest response, operation:{}, request uri:{}",
+          getMicroserviceQualifiedName(), requestEx.getRequestURI(), e);
     }
   }
 
@@ -235,17 +237,15 @@ public abstract class AbstractRestInvocation {
 
   protected void onExecuteHttpServerFiltersFinish(Response response, Throwable e) {
     if (e != null) {
-      LOGGER.error("Failed to execute HttpServerFilters, operation:{}.",
-          invocation.getMicroserviceQualifiedName(),
-          e);
+      LOGGER.error("Failed to execute HttpServerFilters, operation:{}, request uri:{}",
+          getMicroserviceQualifiedName(), requestEx.getRequestURI(), e);
     }
 
     try {
       responseEx.flushBuffer();
     } catch (IOException flushException) {
-      LOGGER.error("Failed to flush rest response, operation:{}.",
-          invocation.getMicroserviceQualifiedName(),
-          flushException);
+      LOGGER.error("Failed to flush rest response, operation:{}, request uri:{}",
+          getMicroserviceQualifiedName(), requestEx.getRequestURI(), flushException);
     }
 
     requestEx.getAsyncContext().complete();
@@ -255,4 +255,8 @@ public abstract class AbstractRestInvocation {
       invocation.onFinish(response);
     }
   }
+
+  private String getMicroserviceQualifiedName() {
+    return null == invocation ? UNKNOWN_OPERATION_ID : invocation.getMicroserviceQualifiedName();
+  }
 }
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestAbstractRestInvocation.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestAbstractRestInvocation.java
index e8d4d7f..cc0c2c0 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestAbstractRestInvocation.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestAbstractRestInvocation.java
@@ -441,6 +441,26 @@ public class TestAbstractRestInvocation {
   }
 
   @Test
+  public void sendResponseQuietlyExceptionOnNullInvocation(@Mocked Response response) {
+    restInvocation = new AbstractRestInvocationForTest() {
+      @Override
+      protected void doInvoke() {
+      }
+
+      @Override
+      protected void sendResponse(Response response) {
+        throw new Error("");
+      }
+    };
+    initRestInvocation();
+    restInvocation.invocation = null;
+
+    restInvocation.sendResponseQuietly(response);
+
+    // just log, check nothing, and should not throw NPE
+  }
+
+  @Test
   public void sendResponseStatusAndContentTypeAndHeader(@Mocked Response response) {
     new Expectations() {
       {


[incubator-servicecomb-java-chassis] 02/02: [SCB-754] add an IT to test bug trigger situation

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit f722a00da0677c0135d2de5c3fec9de0e898bf5f
Author: yaohaishi <ya...@huawei.com>
AuthorDate: Wed Jul 18 17:59:41 2018 +0800

    [SCB-754] add an IT to test bug trigger situation
---
 .../jaxrs/client/CodeFirstRestTemplateJaxrs.java   | 16 ++++++++
 .../jaxrs/server/JaxrsDemoHttpServerFilter.java    | 46 ++++++++++++++++++++++
 ...servicecomb.common.rest.filter.HttpServerFilter | 18 +++++++++
 3 files changed, 80 insertions(+)

diff --git a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/CodeFirstRestTemplateJaxrs.java b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/CodeFirstRestTemplateJaxrs.java
index 429a12f..38ae6e9 100644
--- a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/CodeFirstRestTemplateJaxrs.java
+++ b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/CodeFirstRestTemplateJaxrs.java
@@ -30,12 +30,15 @@ import org.apache.servicecomb.demo.TestMgr;
 import org.springframework.core.io.FileSystemResource;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
+import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.RestClientException;
 import org.springframework.web.client.RestTemplate;
 
 public class CodeFirstRestTemplateJaxrs extends CodeFirstRestTemplate {
   @Override
   protected void testAllTransport(String microserviceName, RestTemplate template, String cseUrlPrefix) {
     testDefaultPath(template, cseUrlPrefix);
+    test404(template);
 
     super.testAllTransport(microserviceName, template, cseUrlPrefix);
   }
@@ -103,4 +106,17 @@ public class CodeFirstRestTemplateJaxrs extends CodeFirstRestTemplate {
     String result = template.postForObject(cseUrlPrefix + "/upload2", new HttpEntity<>(map, headers), String.class);
     TestMgr.check(expect, result);
   }
+
+  private void test404(RestTemplate template) {
+    HttpClientErrorException exception = null;
+    try {
+      template.getForEntity("http://127.0.0.1:8080/aPathNotExist", String.class);
+    } catch (RestClientException e) {
+      if (e instanceof HttpClientErrorException) {
+        exception = (HttpClientErrorException) e;
+      }
+    }
+    TestMgr.check(404, exception.getRawStatusCode());
+    TestMgr.check("404 Not Found", exception.getMessage());
+  }
 }
diff --git a/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/JaxrsDemoHttpServerFilter.java b/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/JaxrsDemoHttpServerFilter.java
new file mode 100644
index 0000000..0258474
--- /dev/null
+++ b/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/JaxrsDemoHttpServerFilter.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.demo.jaxrs.server;
+
+import org.apache.servicecomb.common.rest.filter.HttpServerFilter;
+import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
+import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
+import org.apache.servicecomb.swagger.invocation.Response;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JaxrsDemoHttpServerFilter implements HttpServerFilter {
+  private static final Logger LOGGER = LoggerFactory.getLogger(JaxrsDemoHttpServerFilter.class);
+
+  @Override
+  public int getOrder() {
+    return 0;
+  }
+
+  @Override
+  public Response afterReceiveRequest(Invocation invocation, HttpServletRequestEx requestEx) {
+    return null;
+  }
+
+  @Override
+  public void beforeSendResponse(Invocation invocation, HttpServletResponseEx responseEx) {
+    // in 404 situation, invocation is null and a NPE is thrown
+    LOGGER.info("JaxrsDemoHttpServerFilter is called, operation=[{}]", invocation.getOperationName());
+  }
+}
diff --git a/demo/demo-jaxrs/jaxrs-server/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter b/demo/demo-jaxrs/jaxrs-server/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter
new file mode 100644
index 0000000..5e737d8
--- /dev/null
+++ b/demo/demo-jaxrs/jaxrs-server/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.servicecomb.demo.jaxrs.server.JaxrsDemoHttpServerFilter
\ No newline at end of file