浏览代码

转发header

lirong 2 年之前
父节点
当前提交
9d5677e76f

+ 1 - 1
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RedirectUtil.java

@@ -103,7 +103,7 @@ public class RedirectUtil {
 			} else {
 				postString = postBody.toString();
 			}
-			resultString = HttpClientUtil.instance("redirect").post(url, postString, null, ConfigRedirect.headerMap);
+			resultString = HttpClientUtil.instance("redirect").post(url, postString, null, ConfigRedirect.headerMap,null);
 		}
 		Object result;
 		try {

+ 3 - 2
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RestApi.java

@@ -1,6 +1,7 @@
 package com.persagy.ibms.data.sdk.service.rest;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -134,8 +135,8 @@ public class RestApi {
 
 	// 登录
 	@PostMapping(path = { "/login", "/zkt-sdk/login" }, produces = "application/json;charset=UTF-8")
-	public String login(@RequestBody String param, HttpServletRequest request) {
-		String result = RestUtil.login(param);
+	public String login(@RequestBody String param, HttpServletRequest request, HttpServletResponse response) {
+		String result = RestUtil.login(param,response);
 		return result;
 	}
 }

+ 4 - 3
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RestUtil.java

@@ -8,6 +8,7 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 import cn.hutool.core.lang.Tuple;
 import com.alibaba.fastjson.JSON;
@@ -389,7 +390,7 @@ public class RestUtil {
 			// http://39.102.40.239:28888/labsl/graph/pub/query
 			// String post_url ="http://39.102.40.239:28888"+ "/labsl/graph/pub/query";
 			String post_url = Constant.adm_project_url + "/labsl/graph/pub/query";
-			String post_result = HttpClientUtil.instance("adm").post(post_url, postJSON.toJSONString(), null, head);
+			String post_result = HttpClientUtil.instance("adm").post(post_url, postJSON.toJSONString(), null, head,null);
 			// 4.解析返回结果
 			JSONObject resultJSON = JSON.parseObject(post_result);
 			Map<String, String> map = new ConcurrentHashMap<>();
@@ -476,11 +477,11 @@ public class RestUtil {
 	}
 
 	// 登录
-	public static String login(String param) {
+	public static String login(String param,HttpServletResponse response) {
 		JSONObject result = new JSONObject();
 		try {
 			JSONObject queryCriteria = JSON.parseObject(param);
-			String post_result = PersonUtil.Login(queryCriteria);
+			String post_result = PersonUtil.Login(queryCriteria,response);
 			String respMsg=JSON.parseObject(post_result).getString("respMsg");
 			JSONObject resultJSON = JSON.parseObject(post_result).getJSONObject("content");
 			result.put("Content", resultJSON);

+ 15 - 2
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/HttpClientUtil.java

@@ -8,11 +8,13 @@ import java.util.Date;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
+import org.apache.http.Header;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.config.RequestConfig;
 import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpHead;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.client.methods.HttpPut;
 import org.apache.http.entity.StringEntity;
@@ -139,11 +141,17 @@ public class HttpClientUtil {
 	}
 
 	public synchronized String post(String url, String content) throws Exception {
-		String result = post(url, content, 300000, null);
+		String result = post(url, content, 300000, null,null);
 		return result;
 	}
 
-	public synchronized String post(String url, String content, Integer timeout, Map<String, String> headerMap) throws Exception {
+	public synchronized String post(String url, String content,HttpServletResponse response) throws Exception {
+		String result = post(url, content, 300000, null,response);
+		return result;
+	}
+
+
+	public synchronized String post(String url, String content, Integer timeout, Map<String, String> headerMap,HttpServletResponse response) throws Exception {
 		if (Constant.http_interval > 0) {
 			Thread.sleep(Constant.http_interval);
 		}
@@ -166,6 +174,11 @@ public class HttpClientUtil {
 		httpost.setEntity(entity);
 		entity.setContentType("application/json");
 		HttpResponse httpResponse = client.execute(httpost);
+		if(url.contains("login"))
+		{
+			Header responseFirstHeader= httpResponse.getFirstHeader("app-token");
+			response.setHeader(responseFirstHeader.getName(),responseFirstHeader.getValue());
+		}
 		InputStream is = httpResponse.getEntity().getContent();
 		ByteArrayOutputStream baos = new ByteArrayOutputStream();
 		int b = -1;

+ 3 - 2
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/PersonUtil.java

@@ -8,15 +8,16 @@ import com.alibaba.fastjson.JSONObject;
 import com.persagy.ibms.core.data.SceneDataObject;
 import com.persagy.ibms.core.data.SceneDataSet;
 
+import javax.servlet.http.HttpServletResponse;
 import java.nio.charset.StandardCharsets;
 import java.util.List;
 
 public class PersonUtil {
-    public static String Login(JSONObject queryCriteria) throws Exception {
+    public static String Login(JSONObject queryCriteria, HttpServletResponse response) throws Exception {
         RepositoryImpl Repository = RepositoryContainer.instance;
         String groupCode = RepositoryContainer.RepositoryProject.groupCode;
         queryCriteria.put("groupCode",groupCode);
-        String post_result = HttpClientUtil.instance("person_center").post(Constant.person_center_url + "/user/login", queryCriteria.toJSONString());
+        String post_result = HttpClientUtil.instance("person_center").post(Constant.person_center_url + "/user/login", queryCriteria.toJSONString(),response);
         return post_result;
     }
 }