针对bpm接口增加认证
This commit is contained in:
		
							parent
							
								
									3b9ce88b1e
								
							
						
					
					
						commit
						14f108c199
					
				| @ -28,10 +28,7 @@ import javax.servlet.http.HttpServletRequest; | |||||||
| import javax.servlet.http.HttpServletResponse; | import javax.servlet.http.HttpServletResponse; | ||||||
| import java.io.IOException; | import java.io.IOException; | ||||||
| import java.math.BigDecimal; | import java.math.BigDecimal; | ||||||
| import java.util.ArrayList; | import java.util.*; | ||||||
| import java.util.HashMap; |  | ||||||
| import java.util.List; |  | ||||||
| import java.util.Map; |  | ||||||
| 
 | 
 | ||||||
| import static com.jsh.erp.utils.ResponseJsonUtil.returnJson; | import static com.jsh.erp.utils.ResponseJsonUtil.returnJson; | ||||||
| import static com.jsh.erp.utils.ResponseJsonUtil.returnStr; | import static com.jsh.erp.utils.ResponseJsonUtil.returnStr; | ||||||
| @ -579,6 +576,10 @@ public class DepotHeadController extends BaseController { | |||||||
|          depotHeadService.addDepotHeadAndDetail(beanJson, rows, request); |          depotHeadService.addDepotHeadAndDetail(beanJson, rows, request); | ||||||
|         //获取application.properties中的值awspaas.bpm.url |         //获取application.properties中的值awspaas.bpm.url | ||||||
|         String bpmUrl = systemConfigService.getBpmUrl(); |         String bpmUrl = systemConfigService.getBpmUrl(); | ||||||
|  |         String bpmApiName = systemConfigService.getBpmApiName(); | ||||||
|  |         String bpmApiPwd = systemConfigService.getBpmApiPwd(); | ||||||
|  |         String authorization = bpmApiName + ":" + bpmApiPwd; | ||||||
|  |         authorization = "Basic "+Base64.getEncoder().encodeToString(authorization.getBytes()); | ||||||
|         JSONObject beanjsonObject = JSONObject.parseObject(beanJson); |         JSONObject beanjsonObject = JSONObject.parseObject(beanJson); | ||||||
|         JSONArray rowsObject = JSONObject.parseArray(rows); |         JSONArray rowsObject = JSONObject.parseArray(rows); | ||||||
| 
 | 
 | ||||||
| @ -602,8 +603,9 @@ public class DepotHeadController extends BaseController { | |||||||
|                 requestBodyJson.toJSONString() |                 requestBodyJson.toJSONString() | ||||||
|         ); |         ); | ||||||
|         // 构建完整POST请求 |         // 构建完整POST请求 | ||||||
|         Request requestBpm = new Request.Builder().url(urlBuilder.build().toString()).post(requestBody).build(); |             Request.Builder authorization1 = new Request.Builder().addHeader("Authorization", authorization).url(urlBuilder.build().toString()).post(requestBody); | ||||||
|         OkHttpClient client = new OkHttpClient(); |             Request requestBpm = authorization1.build(); | ||||||
|  |             OkHttpClient client = new OkHttpClient(); | ||||||
|         // 发送请求 |         // 发送请求 | ||||||
|         try { |         try { | ||||||
| 
 | 
 | ||||||
| @ -755,6 +757,10 @@ public class DepotHeadController extends BaseController { | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     public String sendPostRequest(HttpUrl.Builder urlBuilder, Object requestBodyJson, String requestType) { |     public String sendPostRequest(HttpUrl.Builder urlBuilder, Object requestBodyJson, String requestType) { | ||||||
|  |         String bpmApiName = systemConfigService.getBpmApiName(); | ||||||
|  |         String bpmApiPwd = systemConfigService.getBpmApiPwd(); | ||||||
|  |         String authorization = bpmApiName + ":" + bpmApiPwd; | ||||||
|  |         authorization = "Basic "+Base64.getEncoder().encodeToString(authorization.getBytes()); | ||||||
|         OkHttpClient client = new OkHttpClient(); |         OkHttpClient client = new OkHttpClient(); | ||||||
|         okhttp3.RequestBody requestBody = okhttp3.RequestBody.create( |         okhttp3.RequestBody requestBody = okhttp3.RequestBody.create( | ||||||
|                 MediaType.get("application/json; charset=utf-8"), |                 MediaType.get("application/json; charset=utf-8"), | ||||||
| @ -763,9 +769,9 @@ public class DepotHeadController extends BaseController { | |||||||
|         // 构建完整POST请求 |         // 构建完整POST请求 | ||||||
|         Request requestBpm; |         Request requestBpm; | ||||||
|         if (requestType.equals("post")) { |         if (requestType.equals("post")) { | ||||||
|             requestBpm = new Request.Builder().url(urlBuilder.build().toString()).post(requestBody).build(); |             requestBpm = new Request.Builder().addHeader("Authorization", authorization).url(urlBuilder.build().toString()).post(requestBody).build(); | ||||||
|         } else { |         } else { | ||||||
|             requestBpm = new Request.Builder().url(urlBuilder.build().toString()).put(requestBody).build(); |             requestBpm = new Request.Builder().addHeader("Authorization", authorization).url(urlBuilder.build().toString()).put(requestBody).build(); | ||||||
|         } |         } | ||||||
|         try { |         try { | ||||||
|             Response response = client.newCall(requestBpm).execute(); |             Response response = client.newCall(requestBpm).execute(); | ||||||
|  | |||||||
| @ -667,5 +667,17 @@ public class SystemConfigService { | |||||||
|     public String getBpmUrl() { |     public String getBpmUrl() { | ||||||
|         return bpmUrl; |         return bpmUrl; | ||||||
|     } |     } | ||||||
|  |     @Value("${awspaas.bpm.api.name}") | ||||||
|  |     private String bpmApiName; | ||||||
|  | 
 | ||||||
|  |     public String getBpmApiName() { | ||||||
|  |         return bpmApiName; | ||||||
|  |     } | ||||||
|  |     @Value("${awspaas.bpm.api.pwd}") | ||||||
|  |     private String bpmApiPwd; | ||||||
|  | 
 | ||||||
|  |     public String getBpmApiPwd() { | ||||||
|  |         return bpmApiPwd; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
| @ -34,4 +34,7 @@ server.tomcat.basedir=/opt/tmp/tomcat | |||||||
| spring.servlet.multipart.max-file-size=10485760 | spring.servlet.multipart.max-file-size=10485760 | ||||||
| spring.servlet.multipart.max-request-size=10485760  | spring.servlet.multipart.max-request-size=10485760  | ||||||
| #bpm接口地址 | #bpm接口地址 | ||||||
| awspaas.bpm.url=http://127.0.0.1:8088/api | awspaas.bpm.url=http://172.17.2.161:8088/api | ||||||
|  | #bpm接口用户名密码 | ||||||
|  | awspaas.bpm.api.name=aws | ||||||
|  | awspaas.bpm.api.pwd=123456 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user