|
@@ -0,0 +1,78 @@
|
|
|
+package com.persagy.dmp.admin.controller;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
+import com.persagy.common.web.ServletUtils;
|
|
|
+import com.persagy.dmp.common.http.HttpUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: yaoll
|
|
|
+ * @date: 2020-12-29
|
|
|
+ * @verison: 1.0
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/admin/dmp")
|
|
|
+public class DmpGatewayController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private HttpUtils httpUtils;
|
|
|
+
|
|
|
+ @PostMapping("/report/**")
|
|
|
+ public void report(HttpServletRequest request, HttpServletResponse response, @RequestBody JsonNode param) {
|
|
|
+ dispatch(request, response, param);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/dic/**")
|
|
|
+ public void dic(HttpServletRequest request, HttpServletResponse response, @RequestBody JsonNode param) {
|
|
|
+ dispatch(request, response, param);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/org/**")
|
|
|
+ public void org(HttpServletRequest request, HttpServletResponse response, @RequestBody JsonNode param) {
|
|
|
+ dispatch(request, response, param);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/rwd/**")
|
|
|
+ public void rwd(HttpServletRequest request, HttpServletResponse response, @RequestBody JsonNode param) {
|
|
|
+ dispatch(request, response, param);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void dispatch(HttpServletRequest request, HttpServletResponse response, @RequestBody JsonNode param) {
|
|
|
+ Map<String, String[]> parameterMap = request.getParameterMap();
|
|
|
+ String[] dmpServers = parameterMap.get("dmpServer");
|
|
|
+ if (dmpServers == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ StringBuilder url = new StringBuilder(dmpServers[0]);
|
|
|
+ String uri = request.getRequestURI().replace("/admin/dmp", "");
|
|
|
+ url.append(uri);
|
|
|
+ String queryString = request.getQueryString();
|
|
|
+ if (!"/rwd/def/class".equalsIgnoreCase(uri) && !"/rwd/def/funcid".equalsIgnoreCase(uri)) {
|
|
|
+ queryString = appendParamIfNotExists(queryString, "appId", "iotTool");
|
|
|
+ queryString = appendParamIfNotExists(queryString, "userId", "admin");
|
|
|
+ }
|
|
|
+ url.append("?").append(queryString);
|
|
|
+
|
|
|
+ HttpUtils.HttpResult post = httpUtils.post(url.toString(), param.toString(), 30000);
|
|
|
+ String content = post.getContent();
|
|
|
+ ServletUtils.writeJson(response, content);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String appendParamIfNotExists(String queryString, String key, String value) {
|
|
|
+ if (queryString == null) {
|
|
|
+ return key + "=" + value;
|
|
|
+ } else {
|
|
|
+ return queryString + "&" + key + "=" + value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|