use of org.apache.servicecomb.it.authentication.encrypt.Hcr in project incubator-servicecomb-java-chassis by apache.
the class DecodeBodyFilter method afterReceiveRequest.
@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 = RestObjectMapperFactory.getRestObjectMapper().readValue(encodedBody, bodyType);
requestEx.getParameterMap().putAll(decodedBody);
} catch (Throwable e) {
// should be a meaning exception response
return Response.producerFailResp(e);
}
return null;
}
use of org.apache.servicecomb.it.authentication.encrypt.Hcr in project java-chassis by ServiceComb.
the class DecodeBodyFilter method afterReceiveRequest.
@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 = RestObjectMapperFactory.getRestObjectMapper().readValue(encodedBody, bodyType);
requestEx.getParameterMap().putAll(decodedBody);
} catch (Throwable e) {
// should be a meaning exception response
return Response.producerFailResp(e);
}
return null;
}
use of org.apache.servicecomb.it.authentication.encrypt.Hcr in project incubator-servicecomb-java-chassis by apache.
the class EncryptEdgeDispatcher method 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;
}
});
}
Aggregations