|  |  | 
 |  |  | package com.dy.rtuMw.web.webRequest; | 
 |  |  |  | 
 |  |  | import com.dy.common.contant.Constant; | 
 |  |  | import com.dy.common.mw.protocol.Command; | 
 |  |  | import com.dy.rtuMw.web.comResult.WebResponseVo; | 
 |  |  | import com.dy.common.webUtil.BaseResponse; | 
 |  |  | import com.dy.rtuMw.server.ServerProperties; | 
 |  |  | import org.apache.logging.log4j.LogManager; | 
 |  |  | import org.apache.logging.log4j.Logger; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | 
 |  |  | /** | 
 |  |  |  * @Author: liurunyu | 
 |  |  |  * @Date: 2024/11/11 16:29 | 
 |  |  |  * @Description | 
 |  |  |  * @Description 通信中间件对外发出的web请求 | 
 |  |  |  */ | 
 |  |  | @Component() | 
 |  |  | public class WebRequestDeal { | 
 |  |  | 
 |  |  |         this.restTemplate = restTemplate ; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 处理中间件主动发起的web请求 | 
 |  |  |      * @param webUrl | 
 |  |  |      * @param obj | 
 |  |  |      */ | 
 |  |  |     public void deal(String webUrl, Object obj) { | 
 |  |  |         if (webUrl != null | 
 |  |  |                 && !webUrl.trim().equals("") | 
 |  |  | 
 |  |  |             restTemplate.getMessageConverters().set(1,new StringHttpMessageConverter(StandardCharsets.UTF_8)); | 
 |  |  |             HttpHeaders headers = new HttpHeaders(); | 
 |  |  |             headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8")); | 
 |  |  |             headers.set(Constant.TokenKeyInHeader, ServerProperties.orgTag); | 
 |  |  |             HttpEntity<?> httpEntity = new HttpEntity<>(obj, headers); | 
 |  |  |             ResponseEntity<WebResponseVo> response = null; | 
 |  |  |             ResponseEntity<BaseResponse> response = null; | 
 |  |  |             try { | 
 |  |  |                 // 通过Post方式调用接口 | 
 |  |  |                 response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, WebResponseVo.class); | 
 |  |  |                 response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, BaseResponse.class); | 
 |  |  |             } catch (Exception e) { | 
 |  |  |                 log.error("web访问请求发生异常", e); | 
 |  |  |             } |