[
https://issues.apache.org/jira/browse/SCB-728?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16547549#comment-16547549
]
ASF GitHub Bot commented on SCB-728:
------------------------------------
liubao68 closed pull request #810: [SCB-728] Decrypt/signature and adjust form
in edge
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/810
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestObjectMapper.java
b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestObjectMapper.java
index f75b7e98f..b0679f4a0 100644
---
a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestObjectMapper.java
+++
b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestObjectMapper.java
@@ -53,6 +53,7 @@ public StringBuffer format(Date date, StringBuffer
toAppendTo, FieldPosition fie
disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS);
+ enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
}
public String convertToString(Object value) throws Exception {
diff --git
a/demo/demo-edge/authentication/src/main/java/org/apache/servicecomb/demo/edge/authentication/encrypt/EncryptImpl.java
b/demo/demo-edge/authentication/src/main/java/org/apache/servicecomb/demo/edge/authentication/encrypt/EncryptImpl.java
new file mode 100644
index 000000000..1bd47a476
--- /dev/null
+++
b/demo/demo-edge/authentication/src/main/java/org/apache/servicecomb/demo/edge/authentication/encrypt/EncryptImpl.java
@@ -0,0 +1,39 @@
+/*
+ * 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.edge.authentication.encrypt;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@RestSchema(schemaId = "encrypt")
+@RequestMapping(path = "auth/v1")
+public class EncryptImpl {
+ @GetMapping(path = "/queryUserId")
+ public String queryUserId(String serviceToken) {
+ return serviceToken + "-userId";
+ }
+
+ @GetMapping(path = "/queryHcr")
+ public Hcr queryHcr(String hcrId) {
+ Hcr hcr = new Hcr();
+ hcr.setBodyKey("bodyKey-" + hcrId + "-");
+ hcr.setSignatureKey("signatureKey-" + hcrId + "-");
+ return hcr;
+ }
+}
diff --git
a/demo/demo-edge/authentication/src/main/java/org/apache/servicecomb/demo/edge/authentication/encrypt/Hcr.java
b/demo/demo-edge/authentication/src/main/java/org/apache/servicecomb/demo/edge/authentication/encrypt/Hcr.java
new file mode 100644
index 000000000..aafdbcf7d
--- /dev/null
+++
b/demo/demo-edge/authentication/src/main/java/org/apache/servicecomb/demo/edge/authentication/encrypt/Hcr.java
@@ -0,0 +1,39 @@
+/*
+ * 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.edge.authentication.encrypt;
+
+public class Hcr {
+ private String bodyKey;
+
+ private String signatureKey;
+
+ public String getBodyKey() {
+ return bodyKey;
+ }
+
+ public void setBodyKey(String bodyKey) {
+ this.bodyKey = bodyKey;
+ }
+
+ public String getSignatureKey() {
+ return signatureKey;
+ }
+
+ public void setSignatureKey(String signatureKey) {
+ this.signatureKey = signatureKey;
+ }
+}
diff --git
a/demo/demo-edge/business-2.0.0/src/main/java/org/apache/servicecomb/demo/edge/business/Impl.java
b/demo/demo-edge/business-2.0.0/src/main/java/org/apache/servicecomb/demo/edge/business/Impl.java
index dc346fa9c..335d36857 100644
---
a/demo/demo-edge/business-2.0.0/src/main/java/org/apache/servicecomb/demo/edge/business/Impl.java
+++
b/demo/demo-edge/business-2.0.0/src/main/java/org/apache/servicecomb/demo/edge/business/Impl.java
@@ -31,6 +31,7 @@
import org.apache.servicecomb.demo.edge.model.DependTypeA;
import org.apache.servicecomb.demo.edge.model.RecursiveSelfType;
import org.apache.servicecomb.demo.edge.model.ResultWithInstance;
+import org.apache.servicecomb.demo.edge.model.User;
import org.apache.servicecomb.provider.rest.common.RestSchema;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
@@ -106,4 +107,9 @@ public RecursiveSelfType recursiveSelf(@RequestBody
RecursiveSelfType value) {
public DependTypeA dependType(@RequestBody DependTypeA value) {
return value;
}
+
+ @PostMapping(path = "encrypt")
+ public User encrypt(@RequestBody User value) {
+ return value;
+ }
}
diff --git
a/demo/demo-edge/consumer/src/main/java/org/apache/servicecomb/demo/edge/consumer/Consumer.java
b/demo/demo-edge/consumer/src/main/java/org/apache/servicecomb/demo/edge/consumer/Consumer.java
index b09e86842..7796de943 100644
---
a/demo/demo-edge/consumer/src/main/java/org/apache/servicecomb/demo/edge/consumer/Consumer.java
+++
b/demo/demo-edge/consumer/src/main/java/org/apache/servicecomb/demo/edge/consumer/Consumer.java
@@ -22,6 +22,7 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
@@ -43,6 +44,8 @@
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
public class Consumer {
@@ -111,6 +114,32 @@ public void run(String prefix) {
checkResult("v2/dec", decV2Result, "2.0.0");
}
+ public void testEncrypt() {
+ prepareEdge("encryptApi");
+ String url = edgePrefix + "/v2/encrypt";
+
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.MULTIPART_FORM_DATA);
+
+ MultiValueMap<String, String> form = new LinkedMultiValueMap<>();
+ form.add("name", "userName");
+ form.add("age", "10");
+ form.add("serviceToken", "serviceTokenTest");
+ form.add("hcrId", "hcrIdTest");
+ form.add("body",
"bodyKey-hcrIdTest-{\"body1\":\"b1\",\"body2\":\"b2\",\"body3\":\"b3\"}");
+
+ HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(form,
headers);
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> result = (Map<String, Object>)
template.postForObject(url, entity, Map.class);
+ Assert.isTrue(result.containsKey("signature"), "must exist signature");
+ result.remove("signature");
+
+ String expected = "{name=userName, age=10, userId=serviceTokenTest-userId,
body1=b1, body2=b2, body3=b3}";
+ Assert.isTrue(expected.equalsIgnoreCase(result.toString()),
+ String.format("expected: %s\nreal : %s", expected,
result.toString()));
+ }
+
protected void testRecursiveSelf() {
String url = edgePrefix + "/v2/recursiveSelf";
diff --git
a/demo/demo-edge/consumer/src/main/java/org/apache/servicecomb/demo/edge/consumer/ConsumerMain.java
b/demo/demo-edge/consumer/src/main/java/org/apache/servicecomb/demo/edge/consumer/ConsumerMain.java
index 699957768..b4378b524 100644
---
a/demo/demo-edge/consumer/src/main/java/org/apache/servicecomb/demo/edge/consumer/ConsumerMain.java
+++
b/demo/demo-edge/consumer/src/main/java/org/apache/servicecomb/demo/edge/consumer/ConsumerMain.java
@@ -25,11 +25,13 @@ public static void main(String[] args) throws Exception {
Log4jUtils.init();
BeanUtils.init();
- System.out.println("Running api dispater.");
+ new Consumer().testEncrypt();
+
+ System.out.println("Running api dispatcher.");
new Consumer().run("api");
- System.out.println("Running rest dispater.");
+ System.out.println("Running rest dispatcher.");
new Consumer().run("rest");
- System.out.println("Running url dispater.");
+ System.out.println("Running url dispatcher.");
new Consumer().run("url");
System.out.println("All test case finished.");
diff --git
a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/authentication/encrypt/Hcr.java
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/authentication/encrypt/Hcr.java
new file mode 100644
index 000000000..aafdbcf7d
--- /dev/null
+++
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/authentication/encrypt/Hcr.java
@@ -0,0 +1,39 @@
+/*
+ * 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.edge.authentication.encrypt;
+
+public class Hcr {
+ private String bodyKey;
+
+ private String signatureKey;
+
+ public String getBodyKey() {
+ return bodyKey;
+ }
+
+ public void setBodyKey(String bodyKey) {
+ this.bodyKey = bodyKey;
+ }
+
+ public String getSignatureKey() {
+ return signatureKey;
+ }
+
+ public void setSignatureKey(String signatureKey) {
+ this.signatureKey = signatureKey;
+ }
+}
diff --git
a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/EdgeConst.java
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/EdgeConst.java
new file mode 100644
index 000000000..dc5b3f2d4
--- /dev/null
+++
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/EdgeConst.java
@@ -0,0 +1,20 @@
+package org.apache.servicecomb.demo.edge.service;/*
+ * 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.
+ */
+
+public interface EdgeConst {
+ String ENCRYPT_CONTEXT = "encryptContext";
+}
diff --git
a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/Encrypt.java
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/Encrypt.java
new file mode 100644
index 000000000..a85ce903e
--- /dev/null
+++
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/Encrypt.java
@@ -0,0 +1,28 @@
+/*
+ * 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.edge.service.encrypt;
+
+import java.util.concurrent.CompletableFuture;
+
+import org.apache.servicecomb.demo.edge.authentication.encrypt.Hcr;
+
+public interface Encrypt {
+ CompletableFuture<String> queryUserId(String serviceToken);
+
+ CompletableFuture<Hcr> queryHcr(String hcrId);
+}
diff --git
a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/EncryptContext.java
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/EncryptContext.java
new file mode 100644
index 000000000..88c8b2b33
--- /dev/null
+++
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/EncryptContext.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.edge.service.encrypt;
+
+import org.apache.servicecomb.demo.edge.authentication.encrypt.Hcr;
+
+public class EncryptContext {
+ private Hcr hcr;
+
+ private String userId;
+
+ public EncryptContext(Hcr hcr, String userId) {
+ this.hcr = hcr;
+ this.userId = userId;
+ }
+
+ public Hcr getHcr() {
+ return hcr;
+ }
+
+ public void setHcr(Hcr hcr) {
+ this.hcr = hcr;
+ }
+
+ public String getUserId() {
+ return userId;
+ }
+
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+}
diff --git
a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/EncryptEdgeDispatcher.java
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/EncryptEdgeDispatcher.java
new file mode 100644
index 000000000..5c8a9a5b8
--- /dev/null
+++
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/EncryptEdgeDispatcher.java
@@ -0,0 +1,114 @@
+/*
+ * 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.edge.service.encrypt;
+
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+
+import org.apache.servicecomb.demo.edge.authentication.encrypt.Hcr;
+import org.apache.servicecomb.edge.core.AbstractEdgeDispatcher;
+import org.apache.servicecomb.edge.core.CompatiblePathVersionMapper;
+import org.apache.servicecomb.provider.pojo.Invoker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.vertx.core.http.HttpServerRequest;
+import io.vertx.ext.web.Router;
+import io.vertx.ext.web.RoutingContext;
+import io.vertx.ext.web.handler.CookieHandler;
+
+public class EncryptEdgeDispatcher extends AbstractEdgeDispatcher {
+ private static final Logger LOGGER =
LoggerFactory.getLogger(EncryptEdgeDispatcher.class);
+
+ private CompatiblePathVersionMapper versionMapper = new
CompatiblePathVersionMapper();
+
+ private Encrypt encrypt = Invoker.createProxy("auth", "encrypt",
Encrypt.class);
+
+ private String prefix = "encryptApi";
+
+ @Override
+ public int getOrder() {
+ return 10000;
+ }
+
+ @Override
+ public void init(Router router) {
+ {
+ String regex = "/" + prefix + "/([^\\\\/]+)/([^\\\\/]+)/(.*)";
+ router.routeWithRegex(regex).handler(CookieHandler.create());
+ router.routeWithRegex(regex).handler(createBodyHandler());
+
router.routeWithRegex(regex).failureHandler(this::onFailure).handler(this::onRequest);
+ }
+ }
+
+ protected void onRequest(RoutingContext context) {
+ HttpServerRequest httpServerRequest = context.request();
+
+ // queryUserId always success
+ CompletableFuture<String> userIdFuture = queryUserId(httpServerRequest);
+ queryHcr(httpServerRequest).thenCombine(userIdFuture, (hcr, userId) -> {
+ // hcr and userId all success
+ routeToBackend(context, hcr, userId);
+ return null;
+ }).whenComplete((v, e) -> {
+ // failed to query hcr
+ if (e != null) {
+ context.response().end("failed to query hcr: " + e.getMessage());
+ return;
+ }
+ });
+ }
+
+ private CompletableFuture<String> queryUserId(HttpServerRequest
httpServerRequest) {
+ String serviceToken = httpServerRequest.getParam("serviceToken");
+ if (serviceToken == null) {
+ // no need to query userId
+ return CompletableFuture.completedFuture(null);
+ }
+
+ CompletableFuture<String> future = new CompletableFuture<>();
+ encrypt.queryUserId(serviceToken).whenComplete((userId, e) -> {
+ if (e != null) {
+ // treat as success, just userId is null
+ LOGGER.error("Failed to query userId, serviceToken={}.", serviceToken,
e);
+ }
+
+ future.complete(userId);
+ });
+
+ return future;
+ }
+
+ private CompletableFuture<Hcr> queryHcr(HttpServerRequest httpServerRequest)
{
+ String hcrId = httpServerRequest.getParam("hcrId");
+ return encrypt.queryHcr(hcrId);
+ }
+
+ private void routeToBackend(RoutingContext context, Hcr hcr, String userId) {
+ Map<String, String> pathParams = context.pathParams();
+ String microserviceName = pathParams.get("param0");
+ String pathVersion = pathParams.get("param1");
+ String path = context.request().path().substring(prefix.length() + 1);
+
+ EncryptEdgeInvocation edgeInvocation = new EncryptEdgeInvocation(new
EncryptContext(hcr, userId));
+
edgeInvocation.setVersionRule(versionMapper.getOrCreate(pathVersion).getVersionRule());
+
+ edgeInvocation.init(microserviceName, context, path, httpServerFilters);
+ edgeInvocation.edgeInvoke();
+ }
+}
diff --git
a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/EncryptEdgeInvocation.java
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/EncryptEdgeInvocation.java
new file mode 100644
index 000000000..cdeb3355e
--- /dev/null
+++
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/EncryptEdgeInvocation.java
@@ -0,0 +1,34 @@
+/*
+ * 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.edge.service.encrypt;
+
+import org.apache.servicecomb.edge.core.EdgeInvocation;
+
+public class EncryptEdgeInvocation extends EdgeInvocation {
+ private EncryptContext encryptContext;
+
+ public EncryptEdgeInvocation(EncryptContext encryptContext) {
+ this.encryptContext = encryptContext;
+ }
+
+ @Override
+ protected void createInvocation() {
+ super.createInvocation();
+
+ invocation.getHandlerContext().put("encryptContext", encryptContext);
+ }
+}
diff --git
a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/DecodeBodyFilter.java
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/DecodeBodyFilter.java
new file mode 100644
index 000000000..572ed61c0
--- /dev/null
+++
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/DecodeBodyFilter.java
@@ -0,0 +1,65 @@
+/*
+ * 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.edge.service.encrypt.filter;
+
+import java.util.Map;
+
+import org.apache.servicecomb.common.rest.codec.RestObjectMapper;
+import org.apache.servicecomb.common.rest.filter.HttpServerFilter;
+import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.demo.edge.authentication.encrypt.Hcr;
+import org.apache.servicecomb.demo.edge.service.EdgeConst;
+import org.apache.servicecomb.demo.edge.service.encrypt.EncryptContext;
+import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
+import org.apache.servicecomb.swagger.invocation.Response;
+
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.type.TypeFactory;
+
+public class DecodeBodyFilter implements HttpServerFilter {
+ private JavaType bodyType =
TypeFactory.defaultInstance().constructMapType(Map.class, String.class,
String[].class);
+
+ @Override
+ public int getOrder() {
+ return -9000;
+ }
+
+ @Override
+ public Response afterReceiveRequest(Invocation invocation,
HttpServletRequestEx requestEx) {
+ EncryptContext encryptContext = (EncryptContext)
invocation.getHandlerContext().get(EdgeConst.ENCRYPT_CONTEXT);
+ if (encryptContext == null) {
+ return null;
+ }
+ Hcr hcr = encryptContext.getHcr();
+
+ String encodedBody = requestEx.getParameter("body");
+ if (encodedBody == null) {
+ return null;
+ }
+
+ encodedBody = encodedBody.substring(hcr.getBodyKey().length());
+
+ try {
+ Map<String, String[]> decodedBody =
RestObjectMapper.INSTANCE.readValue(encodedBody, bodyType);
+ requestEx.getParameterMap().putAll(decodedBody);
+ } catch (Throwable e) {
+ // should be a meaning exception response
+ return Response.producerFailResp(e);
+ }
+ return null;
+ }
+}
diff --git
a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/EdgeSignatureRequestFilter.java
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/EdgeSignatureRequestFilter.java
new file mode 100644
index 000000000..0eae860c2
--- /dev/null
+++
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/EdgeSignatureRequestFilter.java
@@ -0,0 +1,67 @@
+/*
+ * 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.edge.service.encrypt.filter;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.servicecomb.common.rest.filter.HttpServerFilter;
+import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.demo.edge.authentication.encrypt.Hcr;
+import org.apache.servicecomb.demo.edge.service.EdgeConst;
+import org.apache.servicecomb.demo.edge.service.encrypt.EncryptContext;
+import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
+import org.apache.servicecomb.swagger.invocation.Response;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.hash.Hasher;
+import com.google.common.hash.Hashing;
+
+public class EdgeSignatureRequestFilter implements HttpServerFilter {
+ private static final Logger LOGGER =
LoggerFactory.getLogger(EdgeSignatureRequestFilter.class);
+
+ @Override
+ public int getOrder() {
+ return -10000;
+ }
+
+ @Override
+ public Response afterReceiveRequest(Invocation invocation,
HttpServletRequestEx requestEx) {
+ EncryptContext encryptContext = (EncryptContext)
invocation.getHandlerContext().get(EdgeConst.ENCRYPT_CONTEXT);
+ if (encryptContext == null) {
+ return null;
+ }
+ Hcr hcr = encryptContext.getHcr();
+
+ // signature for query and form
+ List<String> names = Collections.list(requestEx.getParameterNames());
+ names.sort(Comparator.naturalOrder());
+
+ Hasher hasher = Hashing.sha256().newHasher();
+ hasher.putString(hcr.getSignatureKey(), StandardCharsets.UTF_8);
+ for (String name : names) {
+ hasher.putString(name, StandardCharsets.UTF_8);
+ hasher.putString(requestEx.getParameter(name), StandardCharsets.UTF_8);
+ }
+ LOGGER.info("afterReceiveRequest signature: {}", hasher.hash().toString());
+
+ return null;
+ }
+}
diff --git
a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/EdgeSignatureResponseFilter.java
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/EdgeSignatureResponseFilter.java
new file mode 100644
index 000000000..4d9a3805b
--- /dev/null
+++
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/EdgeSignatureResponseFilter.java
@@ -0,0 +1,76 @@
+/*
+ * 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.edge.service.encrypt.filter;
+
+import java.nio.charset.StandardCharsets;
+
+import org.apache.servicecomb.common.rest.filter.HttpServerFilter;
+import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.demo.edge.authentication.encrypt.Hcr;
+import org.apache.servicecomb.demo.edge.service.EdgeConst;
+import org.apache.servicecomb.demo.edge.service.encrypt.EncryptContext;
+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;
+
+import com.google.common.hash.Hasher;
+import com.google.common.hash.Hashing;
+
+import io.vertx.core.buffer.Buffer;
+
+public class EdgeSignatureResponseFilter implements HttpServerFilter {
+ private static final Logger LOGGER =
LoggerFactory.getLogger(EdgeSignatureResponseFilter.class);
+
+ @Override
+ public int getOrder() {
+ return 10000;
+ }
+
+ @Override
+ public Response afterReceiveRequest(Invocation invocation,
HttpServletRequestEx requestEx) {
+ return null;
+ }
+
+ @Override
+ public void beforeSendResponse(Invocation invocation, HttpServletResponseEx
responseEx) {
+ if (invocation == null) {
+ return;
+ }
+
+ EncryptContext encryptContext = (EncryptContext)
invocation.getHandlerContext().get(EdgeConst.ENCRYPT_CONTEXT);
+ if (encryptContext == null) {
+ return;
+ }
+ Hcr hcr = encryptContext.getHcr();
+
+ // bad practice: it's better to set signature in response header
+ Buffer bodyBuffer = responseEx.getBodyBuffer();
+ String body = bodyBuffer.toString();
+ if (body.endsWith("}")) {
+ Hasher hasher = Hashing.sha256().newHasher();
+ hasher.putString(hcr.getSignatureKey(), StandardCharsets.UTF_8);
+ hasher.putString(body, StandardCharsets.UTF_8);
+ String signature = hasher.hash().toString();
+ LOGGER.info("beforeSendResponse signature: {}", signature);
+
+ body = body.substring(0, body.length() - 1) + ",\"signature\":\"" +
signature + "\"}";
+ responseEx.setBodyBuffer(Buffer.buffer(body));
+ }
+ }
+}
diff --git
a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/UserIdFilter.java
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/UserIdFilter.java
new file mode 100644
index 000000000..2212042ef
--- /dev/null
+++
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/encrypt/filter/UserIdFilter.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.edge.service.encrypt.filter;
+
+import org.apache.servicecomb.common.rest.filter.HttpServerFilter;
+import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.demo.edge.service.EdgeConst;
+import org.apache.servicecomb.demo.edge.service.encrypt.EncryptContext;
+import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
+import org.apache.servicecomb.swagger.invocation.Response;
+
+public class UserIdFilter implements HttpServerFilter {
+ @Override
+ public int getOrder() {
+ return -8000;
+ }
+
+ @Override
+ public Response afterReceiveRequest(Invocation invocation,
HttpServletRequestEx requestEx) {
+ EncryptContext encryptContext = (EncryptContext)
invocation.getHandlerContext().get(EdgeConst.ENCRYPT_CONTEXT);
+ if (encryptContext == null) {
+ return null;
+ }
+
+ String userId = encryptContext.getUserId();
+ if (userId != null) {
+ requestEx.setParameter("userId", userId);
+ }
+
+ return null;
+ }
+}
diff --git
a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/handler/Auth.java
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/handler/Auth.java
index 3a6522b17..8cf00fb81 100644
---
a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/handler/Auth.java
+++
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/handler/Auth.java
@@ -17,6 +17,8 @@
package org.apache.servicecomb.demo.edge.service.handler;
+import java.util.concurrent.CompletableFuture;
+
public interface Auth {
- boolean auth(String info);
+ CompletableFuture<Boolean> auth(String info);
}
diff --git
a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/handler/AuthHandler.java
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/handler/AuthHandler.java
index 35f6275d1..183ba3da8 100644
---
a/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/handler/AuthHandler.java
+++
b/demo/demo-edge/edge-service/src/main/java/org/apache/servicecomb/demo/edge/service/handler/AuthHandler.java
@@ -22,6 +22,7 @@
import org.apache.servicecomb.core.Handler;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.definition.MicroserviceMeta;
+import org.apache.servicecomb.demo.edge.service.EdgeConst;
import org.apache.servicecomb.provider.pojo.Invoker;
import org.apache.servicecomb.swagger.invocation.AsyncResponse;
import org.apache.servicecomb.swagger.invocation.InvocationType;
@@ -32,9 +33,9 @@
public class AuthHandler implements Handler {
private static Logger LOGGER = LoggerFactory.getLogger(AuthHandler.class);
- private Auth auth;
+ private static Auth auth;
- public AuthHandler() {
+ static {
auth = Invoker.createProxy("auth", "auth", Auth.class);
}
@@ -44,12 +45,29 @@ public void init(MicroserviceMeta microserviceMeta,
InvocationType invocationTyp
@Override
public void handle(Invocation invocation, AsyncResponse asyncResp) throws
Exception {
- if (!auth.auth("")) {
- asyncResp.consumerFail(new InvocationException(Status.UNAUTHORIZED,
(Object) "auth failed"));
+ if (invocation.getHandlerContext().get(EdgeConst.ENCRYPT_CONTEXT) != null)
{
+ invocation.next(asyncResp);
+ return;
+ }
+
+ auth.auth("").whenComplete((succ, e) -> doHandle(invocation, asyncResp,
succ, e));
+ }
+
+ protected void doHandle(Invocation invocation, AsyncResponse asyncResp,
Boolean authSucc, Throwable authException) {
+ if (authException != null) {
+ asyncResp.consumerFail(new InvocationException(Status.UNAUTHORIZED,
(Object) authException.getMessage()));
return;
}
+ if (!authSucc) {
+ asyncResp.consumerFail(new InvocationException(Status.UNAUTHORIZED,
(Object) "auth failed"));
+ }
+
LOGGER.debug("auth success.");
- invocation.next(asyncResp);
+ try {
+ invocation.next(asyncResp);
+ } catch (Throwable e) {
+ asyncResp.consumerFail(e);
+ }
}
}
diff --git
a/demo/demo-edge/edge-service/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter
b/demo/demo-edge/edge-service/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter
new file mode 100644
index 000000000..eb91526f3
--- /dev/null
+++
b/demo/demo-edge/edge-service/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.filter.HttpServerFilter
@@ -0,0 +1,21 @@
+#
+# 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.edge.service.encrypt.filter.EdgeSignatureRequestFilter
+org.apache.servicecomb.demo.edge.service.encrypt.filter.DecodeBodyFilter
+org.apache.servicecomb.demo.edge.service.encrypt.filter.UserIdFilter
+org.apache.servicecomb.demo.edge.service.encrypt.filter.EdgeSignatureResponseFilter
\ No newline at end of file
diff --git
a/demo/demo-edge/edge-service/src/main/resources/META-INF/services/org.apache.servicecomb.transport.rest.vertx.VertxHttpDispatcher
b/demo/demo-edge/edge-service/src/main/resources/META-INF/services/org.apache.servicecomb.transport.rest.vertx.VertxHttpDispatcher
index 7f00e965a..dffc43239 100644
---
a/demo/demo-edge/edge-service/src/main/resources/META-INF/services/org.apache.servicecomb.transport.rest.vertx.VertxHttpDispatcher
+++
b/demo/demo-edge/edge-service/src/main/resources/META-INF/services/org.apache.servicecomb.transport.rest.vertx.VertxHttpDispatcher
@@ -16,3 +16,4 @@
#
org.apache.servicecomb.demo.edge.service.EdgeDispatcher
+org.apache.servicecomb.demo.edge.service.encrypt.EncryptEdgeDispatcher
diff --git a/demo/demo-edge/edge-service/src/main/resources/microservice.yaml
b/demo/demo-edge/edge-service/src/main/resources/microservice.yaml
index 7bfa1b94c..fefa99231 100644
--- a/demo/demo-edge/edge-service/src/main/resources/microservice.yaml
+++ b/demo/demo-edge/edge-service/src/main/resources/microservice.yaml
@@ -35,8 +35,6 @@ servicecomb:
default: auth,loadbalance
service:
auth: loadbalance
- executors:
- default: cse.executor.groupThreadPool
http:
dispatcher:
edge:
diff --git
a/demo/demo-edge/model/src/main/java/org/apache/servicecomb/demo/edge/model/User.java
b/demo/demo-edge/model/src/main/java/org/apache/servicecomb/demo/edge/model/User.java
new file mode 100644
index 000000000..5c93dddf0
--- /dev/null
+++
b/demo/demo-edge/model/src/main/java/org/apache/servicecomb/demo/edge/model/User.java
@@ -0,0 +1,79 @@
+/*
+ * 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.edge.model;
+
+public class User {
+ private String name;
+
+ private int age;
+
+ private String userId;
+
+ private String body1;
+
+ private String body2;
+
+ private String body3;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public String getUserId() {
+ return userId;
+ }
+
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+
+ public String getBody1() {
+ return body1;
+ }
+
+ public void setBody1(String body1) {
+ this.body1 = body1;
+ }
+
+ public String getBody2() {
+ return body2;
+ }
+
+ public void setBody2(String body2) {
+ this.body2 = body2;
+ }
+
+ public String getBody3() {
+ return body3;
+ }
+
+ public void setBody3(String body3) {
+ this.body3 = body3;
+ }
+}
diff --git
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/HttpServletRequestEx.java
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/HttpServletRequestEx.java
index 61a3b2c03..d2f62f2b0 100644
---
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/HttpServletRequestEx.java
+++
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/HttpServletRequestEx.java
@@ -27,4 +27,8 @@ default void setHeader(String name, String value) {
default void addHeader(String name, String value) {
}
+
+ default void setParameter(String name, String value) {
+
+ }
}
diff --git
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/StandardHttpServletRequestEx.java
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/StandardHttpServletRequestEx.java
index f9b29cacb..359bfae3d 100644
---
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/StandardHttpServletRequestEx.java
+++
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/StandardHttpServletRequestEx.java
@@ -169,4 +169,9 @@ public String getParameter(String name) {
return parameterMap;
}
+
+ @Override
+ public void setParameter(String name, String value) {
+ getParameterMap().put(name, new String[] {value});
+ }
}
diff --git
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/VertxServerRequestToHttpServletRequest.java
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/VertxServerRequestToHttpServletRequest.java
index f19858718..9274bc270 100644
---
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/VertxServerRequestToHttpServletRequest.java
+++
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/VertxServerRequestToHttpServletRequest.java
@@ -107,9 +107,23 @@ public String getContentType() {
@Override
public String getParameter(String name) {
+ if (parameterMap != null) {
+ String[] values = parameterMap.get(name);
+ return values == null ? null : values[0];
+ }
+
return this.vertxRequest.getParam(name);
}
+ @Override
+ public Enumeration<String> getParameterNames() {
+ if (parameterMap != null) {
+ return Collections.enumeration(parameterMap.keySet());
+ }
+
+ return Collections.enumeration(this.vertxRequest.params().names());
+ }
+
@Override
public String[] getParameterValues(String name) {
if (parameterMap != null) {
@@ -135,6 +149,16 @@ public String getParameter(String name) {
return parameterMap;
}
+ @Override
+ public void setParameter(String name, String value) {
+ if (parameterMap != null) {
+ parameterMap.put(name, new String[] {value});
+ return;
+ }
+
+ vertxRequest.params().set(name, value);
+ }
+
@Override
public String getScheme() {
return this.vertxRequest.scheme();
diff --git
a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestStandardHttpServletRequestEx.java
b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestStandardHttpServletRequestEx.java
index f87e83c81..cbc2a387c 100644
---
a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestStandardHttpServletRequestEx.java
+++
b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestStandardHttpServletRequestEx.java
@@ -37,6 +37,7 @@
import org.junit.Test;
import io.vertx.core.buffer.Buffer;
+import mockit.Deencapsulation;
import mockit.Expectations;
import mockit.Mocked;
@@ -132,4 +133,20 @@ public void parameterMap_merge() throws IOException {
Assert.assertThat(requestEx.getParameterValues("p1"),
Matchers.arrayContaining("v1-1", "v1-2", "v1-3"));
Assert.assertEquals("v1-1", requestEx.getParameter("p1"));
}
+
+ @Test
+ public void setParameter() {
+ Map<String, String[]> parameterMap = new HashMap<>();
+ Deencapsulation.setField(requestEx, "parameterMap", parameterMap);
+
+ requestEx.setParameter("k1", "v1");
+ requestEx.setParameter("k2", "v2");
+
+ Assert.assertEquals("v1", requestEx.getParameter("k1"));
+ Assert.assertEquals("v2", requestEx.getParameter("k2"));
+
+ Assert.assertSame(parameterMap, requestEx.getParameterMap());
+
+ Assert.assertThat(Collections.list(requestEx.getParameterNames()),
Matchers.contains("k1", "k2"));
+ }
}
diff --git
a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxServerRequestToHttpServletRequest.java
b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxServerRequestToHttpServletRequest.java
index df7221551..2e98a8377 100644
---
a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxServerRequestToHttpServletRequest.java
+++
b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestVertxServerRequestToHttpServletRequest.java
@@ -19,6 +19,7 @@
import java.io.IOException;
import java.util.Collections;
+import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
@@ -452,4 +453,21 @@ public void getCharacterEncoding() {
Assert.assertEquals("ce", request.getCharacterEncoding());
}
+
+
+ @Test
+ public void setParameter() {
+ Map<String, String[]> parameterMap = new HashMap<>();
+ Deencapsulation.setField(request, "parameterMap", parameterMap);
+
+ request.setParameter("k1", "v1");
+ request.setParameter("k2", "v2");
+
+ Assert.assertEquals("v1", request.getParameter("k1"));
+ Assert.assertEquals("v2", request.getParameter("k2"));
+
+ Assert.assertSame(parameterMap, request.getParameterMap());
+
+ Assert.assertThat(Collections.list(request.getParameterNames()),
Matchers.contains("k1", "k2"));
+ }
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> add decrypt/signature/... to edge demo
> --------------------------------------
>
> Key: SCB-728
> URL: https://issues.apache.org/jira/browse/SCB-728
> Project: Apache ServiceComb
> Issue Type: Task
> Components: Java-Chassis
> Reporter: wujimin
> Assignee: wujimin
> Priority: Major
>
> 1.add "decrypt“ logic, decrypt field named "body" in form, generate new
> multiple fields to form by "body"
> 2.move "signature" to edge, and only signature for one operation
> 3.request with form-data or x-www-form-urlencoded, edge convert to json
> automatically
> 4.query userId by serviceToken, and put userId back to form
> 5.calc signature from response buffer, and add "signature" field to response
> body, eg:
> before: \{"k":"v"}
> after: \{"k":"v","signature":"xxxxx"}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)