admin 1 year ago
parent
commit
8ac1080229

+ 2 - 2
.idea/misc.xml

@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="ExternalStorageConfigurationManager" enabled="true" />
   <component name="JsBuildToolPackageJson" sorting="DEFINITION_ORDER" />
@@ -7,9 +8,8 @@
         <option value="$PROJECT_DIR$/pom.xml" />
       </list>
     </option>
-    <option name="workspaceImportForciblyTurnedOn" value="true" />
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/out" />
   </component>
 </project>

+ 124 - 0
.idea/uiDesigner.xml

@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Palette2">
+    <group name="Swing">
+      <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
+      </item>
+      <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
+      </item>
+      <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
+        <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
+        <initial-values>
+          <property name="text" value="Button" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="RadioButton" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="CheckBox" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="Label" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
+          <preferred-size width="200" height="200" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
+          <preferred-size width="200" height="200" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
+      </item>
+      <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
+          <preferred-size width="-1" height="20" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
+      </item>
+      <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
+      </item>
+    </group>
+  </component>
+</project>

+ 1 - 0
file-starter/pom.xml

@@ -43,6 +43,7 @@
         <dependency>
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>
+            <version>1.18.30</version>
         </dependency>
     </dependencies>
 

+ 77 - 0
xsky-service/pom.xml

@@ -39,6 +39,15 @@
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-lang3</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
 
         <!-- https://mvnrepository.com/artifact/com.dameng/DmJdbcDriver18 -->
 
@@ -61,5 +70,73 @@
             <version>1.0-SNAPSHOT</version>
         </dependency>
 
+        <!-- HttpClient -->
+      <!--  <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+        </dependency>-->
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.8.18</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>1.3.2</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.httpcomponents.client5</groupId>
+            <artifactId>httpclient5</artifactId>
+            <version>5.1.3</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents.client5</groupId>
+            <artifactId>httpclient5-fluent</artifactId>
+            <version>5.1.3</version>
+        </dependency>
+
+        <!-- Apache HttpClient 4.5.x (请检查并使用最新版本) -->
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>4.5.13</version> <!-- 请检查并使用最新版本 -->
+        </dependency>
+
+        <!-- Apache HttpClient SSL支持(如果需要) -->
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient-osgi</artifactId>
+            <version>4.5.13</version> <!-- 通常与httpclient版本相同 -->
+            <scope>provided</scope> <!-- 如果你不是在OSGi环境中运行,可以省略这个依赖 -->
+        </dependency>
+
+        <!-- 如果你需要处理HTTP/2,可以添加这个依赖(可选) -->
+<!--        <dependency>-->
+<!--            <groupId>org.apache.httpcomponents.httpcore-nio</groupId>-->
+<!--            <artifactId>httpcore-nio</artifactId>-->
+<!--            <version>4.4.14</version> &lt;!&ndash; 请检查并使用与httpclient兼容的版本 &ndash;&gt;-->
+<!--        </dependency>-->
+
+        <!-- 如果你使用PoolingHttpClientConnectionManager,你可能还需要这个依赖 -->
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpcore</artifactId>
+            <version>4.4.14</version> <!-- 请检查并使用与httpclient兼容的版本 -->
+        </dependency>
+        <dependency>
+            <groupId>commons-httpclient</groupId>
+            <artifactId>commons-httpclient</artifactId>
+            <version>3.1</version>
+        </dependency>
+
+        <!-- 如果你需要处理cookies,可以添加这个依赖(可选) -->
+<!--        <dependency>-->
+<!--            <groupId>org.apache.httpcomponents</groupId>-->
+<!--            <artifactId>httpclient-client</artifactId>-->
+<!--            <version>4.5.13</version> &lt;!&ndash; 请检查并使用与httpclient相同的版本 &ndash;&gt;-->
+<!--        </dependency>-->
+
     </dependencies>
 </project>

+ 42 - 0
xsky-service/src/main/java/com/itheima/file/controller/ApiController.java

@@ -0,0 +1,42 @@
+package com.itheima.file.controller;
+
+import com.itheima.file.util.HTTPHelper;
+import dm.jdbc.filter.stat.json.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Base64;
+import java.util.LinkedHashMap;
+
+@Slf4j
+@RestController
+@RequestMapping("/api")
+public class ApiController {
+
+    @GetMapping("/test")
+    public String test(){
+
+        JSONObject reqBodyObj = new JSONObject();
+        reqBodyObj.put("app_id", "hcmcloud");
+        reqBodyObj.put("table_name", "");
+        reqBodyObj.put("stringDate", "20210301");
+        reqBodyObj.put("condition", "1=1");
+        reqBodyObj.put("secretKey", "f3ac852124d2f991a3f63f2e33dae18b");
+
+        LinkedHashMap<String, String> header = new LinkedHashMap<String, String>();
+        header.put("username", "po_soap1");
+        header.put("password", "z123456789");
+        header.put("Authorization", "Basic "+ Base64.getUrlEncoder().encodeToString(("po_soap1" + ":" + "z123456789").getBytes()));
+        String postUrl = "https://podev.minmetals.com.cn:50001/RESTAdapter/BS_OA/BS_MDM/DeleteAssHrtree";
+        try {
+            String result = HTTPHelper.sendPOST(postUrl, reqBodyObj.toString(), header, "UTF-8");
+            System.out.println(result);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+
+        return "";
+    }
+}

+ 2 - 0
xsky-service/src/main/java/com/itheima/file/mapper/Demo1Mapper.java

@@ -2,6 +2,8 @@ package com.itheima.file.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.itheima.file.pojo.Demo1;
+import org.apache.ibatis.annotations.Mapper;
 
+@Mapper
 public interface Demo1Mapper  extends BaseMapper<Demo1> {
 }

+ 2 - 0
xsky-service/src/main/java/com/itheima/file/service/impl/Demo1ServiceImpl.java

@@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.itheima.file.mapper.Demo1Mapper;
 import com.itheima.file.service.Demo1Service;
 import com.itheima.file.pojo.Demo1;
+import org.springframework.stereotype.Service;
 
+@Service
 public class Demo1ServiceImpl extends ServiceImpl<Demo1Mapper, Demo1> implements Demo1Service {
 
 }

+ 0 - 4
xsky-service/src/main/java/com/itheima/file/service/impl/WmMaterialServiceImpl.java

@@ -17,10 +17,6 @@ public class WmMaterialServiceImpl implements WmMaterialService {
 
     @Autowired
     private FileStorageService fileStorageService;
-
-    @Autowired
-    private Demo1Service demo1Service;
-
     @Override
     public String uploadPicture(MultipartFile multipartFile) {
         // 1 检查参数

+ 346 - 0
xsky-service/src/main/java/com/itheima/file/util/HTTPHelper.java

@@ -0,0 +1,346 @@
+package com.itheima.file.util;
+
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.UnknownHostException;
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map.Entry;
+
+@Slf4j
+public class HTTPHelper {
+  // slf4j日志记录器
+
+  /***
+   * 向指定URL发送GET方法的请求
+   *
+   * @param apiUrl
+   * @param encoding
+   * @return
+   * @throws Exception
+   */
+  public static String sendGet(String apiUrl, HashMap<String, Object> param,
+                               LinkedHashMap<String, String> headers, String encoding) throws Exception {
+    // 获得响应内容
+    String http_RespContent = null;
+    HttpURLConnection httpURLConnection = null;
+    int http_StatusCode = 0;
+    String http_RespMessage = null;
+    try {
+      // 实际请求完整Url
+      StringBuffer fullUrl = new StringBuffer();
+      if (null != param) {
+        if (0 != param.size()) {
+          StringBuffer params = new StringBuffer();
+          for (Entry<String, Object> entry : param.entrySet()) {
+            params.append(entry.getKey());
+            params.append("=");
+            params.append(entry.getValue().toString());
+            params.append("&");
+          }
+          if (params.length() > 0) {
+            params.deleteCharAt(params.lastIndexOf("&"));
+          }
+          fullUrl.append(apiUrl).append((params.length() > 0) ? "?" + params.toString() : "");
+        } else {
+          fullUrl.append(apiUrl);
+        }
+      } else {
+        fullUrl.append(apiUrl);
+      }
+ 
+      log.info(">>>> 实际请求Url: " + fullUrl.toString());
+ 
+      // 建立连接
+      URL url = new URL(fullUrl.toString());
+      httpURLConnection = (HttpURLConnection) url.openConnection();
+      // 需要输出
+      httpURLConnection.setDoOutput(true);
+      // 需要输入
+      httpURLConnection.setDoInput(true);
+      // 不允许缓存
+      httpURLConnection.setUseCaches(false);
+      // HTTP请求方式
+      httpURLConnection.setRequestMethod("GET");
+      // 设置Headers
+      if (null != headers) {
+        for (String key : headers.keySet()) {
+          httpURLConnection.setRequestProperty(key, headers.get(key));
+        }
+      }
+      // 连接会话
+      httpURLConnection.connect();
+      // 获得响应状态(HTTP状态码)
+      http_StatusCode = httpURLConnection.getResponseCode();
+      // 获得响应消息(HTTP状态码描述)
+      http_RespMessage = httpURLConnection.getResponseMessage();
+      // 获得响应内容
+      if (HttpURLConnection.HTTP_OK == http_StatusCode) {
+        // 返回响应结果
+        http_RespContent = getResponseContent(httpURLConnection);
+      } else {
+        // 返回非200状态时响应结果
+        http_RespContent = getErrorResponseContent(httpURLConnection);
+        String msg =
+            MessageFormat.format("请求失败: Http状态码 = {0} , {1}", http_StatusCode, http_RespMessage);
+        log.info(msg);
+      }
+    } catch (UnknownHostException e) {
+      String message = MessageFormat.format("网络请求时发生异常: {0}", e.getMessage());
+      Exception ex = new Exception(message);
+      ex.initCause(e);
+      throw ex;
+    } catch (MalformedURLException e) {
+      String message = MessageFormat.format("格式错误的URL: {0}", e.getMessage());
+      Exception ex = new Exception(message);
+      ex.initCause(e);
+      throw ex;
+    } catch (IOException e) {
+      String message = MessageFormat.format("网络请求时发生异常: {0}", e.getMessage());
+      Exception ex = new Exception(message);
+      ex.initCause(e);
+      throw ex;
+    } catch (Exception e) {
+      String message = MessageFormat.format("网络请求时发生异常: {0}", e.getMessage());
+      Exception ex = new Exception(message);
+      ex.initCause(e);
+      throw ex;
+    } finally {
+      if (null != httpURLConnection) {
+        httpURLConnection.disconnect();
+      }
+    }
+    return http_RespContent;
+  }
+
+  /***
+   * 向指定URL发送PuT方法的请求
+   *
+   * @param apiUrl
+   * @param data
+   * @param encoding
+   * @return
+   * @throws Exception
+   */
+  public static String sendPUT(String apiUrl, String data, LinkedHashMap<String, String> headers,
+                                String encoding) throws Exception {
+    // 获得响应内容
+    String http_RespContent = null;
+    HttpURLConnection httpURLConnection = null;
+    int http_StatusCode = 0;
+    String http_RespMessage = null;
+    try {
+      // 建立连接
+      URL url = new URL(apiUrl);
+      httpURLConnection = (HttpURLConnection) url.openConnection();
+      // 需要输出
+      httpURLConnection.setDoOutput(true);
+      // 需要输入
+      httpURLConnection.setDoInput(true);
+      // 不允许缓存
+      httpURLConnection.setUseCaches(false);
+      // HTTP请求方式
+      httpURLConnection.setRequestMethod("PUT");
+      // 设置Headers
+      if (null != headers) {
+        for (String key : headers.keySet()) {
+          httpURLConnection.setRequestProperty(key, headers.get(key));
+        }
+      }
+      // 连接会话
+      httpURLConnection.connect();
+      // 建立输入流,向指向的URL传入参数
+      DataOutputStream dos = new DataOutputStream(httpURLConnection.getOutputStream());
+      // 设置请求参数
+      dos.write(data.getBytes(encoding));
+      dos.flush();
+      dos.close();
+      // 获得响应状态(HTTP状态码)
+      http_StatusCode = httpURLConnection.getResponseCode();
+      // 获得响应消息(HTTP状态码描述)
+      http_RespMessage = httpURLConnection.getResponseMessage();
+      // 获得响应内容
+      if (HttpURLConnection.HTTP_OK == http_StatusCode) {
+        // 返回响应结果
+        http_RespContent = getResponseContent(httpURLConnection);
+      } else {
+        // 返回非200状态时响应结果
+        http_RespContent = getErrorResponseContent(httpURLConnection);
+        String msg =
+                MessageFormat.format("请求失败: Http状态码 = {0} , {1}", http_StatusCode, http_RespMessage);
+        log.info(msg);
+      }
+    } catch (UnknownHostException e) {
+      String message = MessageFormat.format("网络请求时发生异常: {0}", e.getMessage());
+      Exception ex = new Exception(message);
+      ex.initCause(e);
+      throw ex;
+    } catch (MalformedURLException e) {
+      String message = MessageFormat.format("格式错误的URL: {0}", e.getMessage());
+      Exception ex = new Exception(message);
+      ex.initCause(e);
+      throw ex;
+    } catch (IOException e) {
+      String message = MessageFormat.format("网络请求时发生异常: {0}", e.getMessage());
+      Exception ex = new Exception(message);
+      ex.initCause(e);
+      throw ex;
+    } catch (Exception e) {
+      String message = MessageFormat.format("网络请求时发生异常: {0}", e.getMessage());
+      Exception ex = new Exception(message);
+      ex.initCause(e);
+      throw ex;
+    } finally {
+      if (null != httpURLConnection) {
+        httpURLConnection.disconnect();
+      }
+    }
+    return http_RespContent;
+  }
+  /***
+   * 向指定URL发送POST方法的请求
+   *
+   * @param apiUrl
+   * @param data
+   * @param encoding
+   * @return
+   * @throws Exception
+   */
+  public static String sendPOST(String apiUrl, String data, LinkedHashMap<String, String> headers,
+      String encoding) throws Exception {
+    // 获得响应内容
+    String http_RespContent = null;
+    HttpURLConnection httpURLConnection = null;
+    int http_StatusCode = 0;
+    String http_RespMessage = null;
+    try {
+      // 建立连接
+      URL url = new URL(apiUrl);
+      httpURLConnection = (HttpURLConnection) url.openConnection();
+      // 需要输出
+      httpURLConnection.setDoOutput(true);
+      // 需要输入
+      httpURLConnection.setDoInput(true);
+      // 不允许缓存
+      httpURLConnection.setUseCaches(false);
+      // HTTP请求方式
+      httpURLConnection.setRequestMethod("POST");
+      // 设置Headers
+      if (null != headers) {
+        for (String key : headers.keySet()) {
+          httpURLConnection.setRequestProperty(key, headers.get(key));
+        }
+      }
+      // 连接会话
+      httpURLConnection.connect();
+      // 建立输入流,向指向的URL传入参数
+      DataOutputStream dos = new DataOutputStream(httpURLConnection.getOutputStream());
+      // 设置请求参数
+      dos.write(data.getBytes(encoding));
+      dos.flush();
+      dos.close();
+      // 获得响应状态(HTTP状态码)
+      http_StatusCode = httpURLConnection.getResponseCode();
+      // 获得响应消息(HTTP状态码描述)
+      http_RespMessage = httpURLConnection.getResponseMessage();
+      // 获得响应内容
+      if (HttpURLConnection.HTTP_OK == http_StatusCode) {
+        // 返回响应结果
+        http_RespContent = getResponseContent(httpURLConnection);
+      } else {
+        // 返回非200状态时响应结果
+        http_RespContent = getErrorResponseContent(httpURLConnection);
+        String msg =
+            MessageFormat.format("请求失败: Http状态码 = {0} , {1}", http_StatusCode, http_RespMessage);
+        log.info(msg);
+      }
+    } catch (UnknownHostException e) {
+      String message = MessageFormat.format("网络请求时发生异常: {0}", e.getMessage());
+      Exception ex = new Exception(message);
+      ex.initCause(e);
+      throw ex;
+    } catch (MalformedURLException e) {
+      String message = MessageFormat.format("格式错误的URL: {0}", e.getMessage());
+      Exception ex = new Exception(message);
+      ex.initCause(e);
+      throw ex;
+    } catch (IOException e) {
+      String message = MessageFormat.format("网络请求时发生异常: {0}", e.getMessage());
+      Exception ex = new Exception(message);
+      ex.initCause(e);
+      throw ex;
+    } catch (Exception e) {
+      String message = MessageFormat.format("网络请求时发生异常: {0}", e.getMessage());
+      Exception ex = new Exception(message);
+      ex.initCause(e);
+      throw ex;
+    } finally {
+      if (null != httpURLConnection) {
+        httpURLConnection.disconnect();
+      }
+    }
+    return http_RespContent;
+  }
+
+ 
+  /***
+   * 读取HttpResponse响应内容
+   *
+   * @param httpURLConnection
+   * @return
+   * @throws UnsupportedEncodingException
+   * @throws IOException
+   */
+  private static String getResponseContent(HttpURLConnection httpURLConnection)
+      throws UnsupportedEncodingException, IOException {
+    StringBuffer contentBuffer = null;
+    BufferedReader responseReader = null;
+    try {
+      contentBuffer = new StringBuffer();
+      String readLine = null;
+      responseReader =
+          new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream(), "UTF-8"));
+      while ((readLine = responseReader.readLine()) != null) {
+        contentBuffer.append(readLine);
+      }
+    } finally {
+      if (null != responseReader) {
+        responseReader.close();
+      }
+    }
+    return contentBuffer.toString();
+  }
+ 
+  /***
+   * 读取HttpResponse响应内容
+   *
+   * @param httpURLConnection
+   * @return
+   * @throws UnsupportedEncodingException
+   * @throws IOException
+   */
+  private static String getErrorResponseContent(HttpURLConnection httpURLConnection)
+      throws UnsupportedEncodingException, IOException {
+    StringBuffer contentBuffer = null;
+    BufferedReader responseReader = null;
+    try {
+      contentBuffer = new StringBuffer();
+      String readLine = null;
+      responseReader =
+          new BufferedReader(new InputStreamReader(httpURLConnection.getErrorStream(), "UTF-8"));
+      while ((readLine = responseReader.readLine()) != null) {
+        contentBuffer.append(readLine);
+      }
+    } finally {
+      if (null != responseReader) {
+        responseReader.close();
+      }
+    }
+    return contentBuffer.toString();
+  }
+}

+ 157 - 0
xsky-service/src/main/java/com/itheima/file/util/InstallCert.java

@@ -0,0 +1,157 @@
+package com.itheima.file.util;
+
+import java.io.*;
+import java.net.URL;
+ 
+import java.security.*;
+import java.security.cert.*;
+ 
+import javax.net.ssl.*;
+ 
+public class InstallCert {
+ 
+    public static void main(String[] args) throws Exception {
+    String host;
+    int port;
+    char[] passphrase;
+    if ((args.length == 1) || (args.length == 2)) {
+        String[] c = args[0].split(":");
+        host = c[0];
+        port = (c.length == 1) ? 443 : Integer.parseInt(c[1]);
+        String p = (args.length == 1) ? "changeit" : args[1];
+        passphrase = p.toCharArray();
+    } else {
+        System.out.println("Usage: java InstallCert <host>[:port] [passphrase]");
+        return;
+    }
+ 
+    File file = new File("jssecacerts");
+    if (file.isFile() == false) {
+        char SEP = File.separatorChar;
+        File dir = new File(System.getProperty("java.home") + SEP
+            + "lib" + SEP + "security");
+        file = new File(dir, "jssecacerts");
+        if (file.isFile() == false) {
+        file = new File(dir, "cacerts");
+        }
+    }
+    System.out.println("Loading KeyStore " + file + "...");
+    InputStream in = new FileInputStream(file);
+    KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
+    ks.load(in, passphrase);
+    in.close();
+ 
+    SSLContext context = SSLContext.getInstance("TLS");
+    TrustManagerFactory tmf =
+        TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+    tmf.init(ks);
+    X509TrustManager defaultTrustManager = (X509TrustManager)tmf.getTrustManagers()[0];
+    SavingTrustManager tm = new SavingTrustManager(defaultTrustManager);
+    context.init(null, new TrustManager[] {tm}, null);
+    SSLSocketFactory factory = context.getSocketFactory();
+ 
+    System.out.println("Opening connection to " + host + ":" + port + "...");
+    SSLSocket socket = (SSLSocket)factory.createSocket(host, port);
+    socket.setSoTimeout(10000);
+    try {
+        System.out.println("Starting SSL handshake...");
+        socket.startHandshake();
+        socket.close();
+        System.out.println();
+        System.out.println("No errors, certificate is already trusted");
+    } catch (SSLException e) {
+        System.out.println();
+        e.printStackTrace(System.out);
+    }
+ 
+    X509Certificate[] chain = tm.chain;
+    if (chain == null) {
+        System.out.println("Could not obtain server certificate chain");
+        return;
+    }
+ 
+    BufferedReader reader =
+        new BufferedReader(new InputStreamReader(System.in));
+ 
+    System.out.println();
+    System.out.println("Server sent " + chain.length + " certificate(s):");
+    System.out.println();
+    MessageDigest sha1 = MessageDigest.getInstance("SHA1");
+    MessageDigest md5 = MessageDigest.getInstance("MD5");
+    for (int i = 0; i < chain.length; i++) {
+        X509Certificate cert = chain[i];
+        System.out.println
+            (" " + (i + 1) + " Subject " + cert.getSubjectDN());
+        System.out.println("   Issuer  " + cert.getIssuerDN());
+        sha1.update(cert.getEncoded());
+        System.out.println("   sha1    " + toHexString(sha1.digest()));
+        md5.update(cert.getEncoded());
+        System.out.println("   md5     " + toHexString(md5.digest()));
+        System.out.println();
+    }
+ 
+    System.out.println("Enter certificate to add to trusted keystore or 'q' to quit: [1]");
+    String line = reader.readLine().trim();
+    int k;
+    try {
+        k = (line.length() == 0) ? 0 : Integer.parseInt(line) - 1;
+    } catch (NumberFormatException e) {
+        System.out.println("KeyStore not changed");
+        return;
+    }
+ 
+    X509Certificate cert = chain[k];
+    String alias = host + "-" + (k + 1);
+    ks.setCertificateEntry(alias, cert);
+ 
+    OutputStream out = new FileOutputStream("jssecacerts");
+    ks.store(out, passphrase);
+    out.close();
+ 
+    System.out.println();
+    System.out.println(cert);
+    System.out.println();
+    System.out.println
+        ("Added certificate to keystore 'jssecacerts' using alias '"
+        + alias + "'");
+    }
+ 
+    private static final char[] HEXDIGITS = "0123456789abcdef".toCharArray();
+ 
+    private static String toHexString(byte[] bytes) {
+    StringBuilder sb = new StringBuilder(bytes.length * 3);
+    for (int b : bytes) {
+        b &= 0xff;
+        sb.append(HEXDIGITS[b >> 4]);
+        sb.append(HEXDIGITS[b & 15]);
+        sb.append(' ');
+    }
+    return sb.toString();
+    }
+ 
+    private static class SavingTrustManager implements X509TrustManager {
+ 
+    private final X509TrustManager tm;
+    private X509Certificate[] chain;
+ 
+    SavingTrustManager(X509TrustManager tm) {
+        this.tm = tm;
+    }
+ 
+    public X509Certificate[] getAcceptedIssuers() {
+        throw new UnsupportedOperationException();
+    }
+ 
+    public void checkClientTrusted(X509Certificate[] chain, String authType)
+        throws CertificateException {
+        throw new UnsupportedOperationException();
+    }
+ 
+    public void checkServerTrusted(X509Certificate[] chain, String authType)
+        throws CertificateException {
+        this.chain = chain;
+        tm.checkServerTrusted(chain, authType);
+    }
+    }
+ 
+}

+ 66 - 0
xsky-service/src/main/java/com/itheima/file/util/PostMethodUtils.java

@@ -0,0 +1,66 @@
+package com.itheima.file.util;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+
+import java.io.*;
+import java.nio.charset.Charset;
+import java.util.Base64;
+
+/**
+ * TODO
+ * 外部接口调用Post
+ *
+ * @author hejie
+ * @date 2021/7/29 17:13
+ */
+@Slf4j
+public class PostMethodUtils {
+
+    /**
+     * 发送HttpClient请求
+     *
+     * @param requestUrl
+     * @param params
+     * @return
+     */
+    public static String sendPost(String requestUrl, String params, String username, String password) {
+        InputStream inputStream = null;
+        try {
+            HttpClient httpClient = new HttpClient();
+            PostMethod postMethod = new PostMethod(requestUrl);
+            // 设置请求头  Content-Type
+            postMethod.setRequestHeader("Content-Type", "application/json");
+            // Base64加密方式认证方式下的basic auth HAIN460000:用户名    topicis123:密码
+            postMethod.setRequestHeader("Authorization", "Basic " + Base64.getUrlEncoder().encodeToString((username + ":" + password).getBytes()));
+            RequestEntity requestEntity = new StringRequestEntity(params, "application/json", "UTF-8");
+            postMethod.setRequestEntity(requestEntity);
+            httpClient.executeMethod(postMethod);// 执行请求
+            inputStream = postMethod.getResponseBodyAsStream();// 获取返回的流
+            BufferedReader br = null;
+            StringBuffer buffer = new StringBuffer();
+            // 将返回的输入流转换成字符串
+            br = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8")));
+            String temp;
+            while ((temp = br.readLine()) != null) {
+                buffer.append(temp);
+            }
+            log.info("接口返回内容为:" + buffer);
+            return buffer.toString();
+        } catch (Exception e) {
+            log.info("请求异常" + e.getMessage());
+            throw new RuntimeException(e.getMessage());
+        } finally {
+            if (inputStream != null) {
+                try {
+                    inputStream.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+}

+ 53 - 0
xsky-service/src/main/java/com/itheima/file/util/SslUtils.java

@@ -0,0 +1,53 @@
+package com.itheima.file.util;
+
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+public class SslUtils {
+	private static void trustAllHttpsCertificates() throws Exception {
+		TrustManager[] trustAllCerts = new TrustManager[1];
+		TrustManager tm = new miTM();
+		trustAllCerts[0] = tm;
+		SSLContext sc = SSLContext.getInstance("SSL");
+		sc.init(null, trustAllCerts, null);
+		HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
+	}
+	static class miTM implements TrustManager,X509TrustManager {
+		public X509Certificate[] getAcceptedIssuers() {
+			return null;
+		}
+		public boolean isServerTrusted(X509Certificate[] certs) {
+			return true;
+		}
+		public boolean isClientTrusted(X509Certificate[] certs) {
+			return true;
+		}
+		public void checkServerTrusted(X509Certificate[] certs, String authType)
+				throws CertificateException {
+			return;
+		}
+		public void checkClientTrusted(X509Certificate[] certs, String authType)
+				throws CertificateException {
+			return;
+		}
+	}
+	/**
+	 * 忽略HTTPS请求的SSL证书,必须在openConnection之前调用
+	 * @throws Exception
+	 */
+	public static void ignoreSsl() throws Exception{
+		HostnameVerifier hv = new HostnameVerifier() {
+			public boolean verify(String urlHostName, SSLSession session) {
+				System.out.println("Warning: URL Host: " + urlHostName + " vs. " + session.getPeerHost());
+				return true;
+			}
+		};
+		trustAllHttpsCertificates();
+		HttpsURLConnection.setDefaultHostnameVerifier(hv);
+	}
+}

+ 194 - 0
xsky-service/src/test/java/com/itheima/file/ApiTestData.java

@@ -0,0 +1,194 @@
+package com.itheima.file;
+
+import com.itheima.file.util.HTTPHelper;
+import com.itheima.file.util.PostMethodUtils;
+import com.itheima.file.util.SslUtils;
+import dm.jdbc.filter.stat.json.JSONObject;
+import org.apache.hc.client5.http.auth.AuthScope;
+import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
+import org.apache.hc.client5.http.classic.methods.HttpGet;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.io.entity.StringEntity;
+
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+import java.util.LinkedHashMap;
+
+// @RunWith(SpringRunner.class)
+// @SpringBootTest
+public class ApiTestData {
+
+    public static void main(final String[] args) throws Exception {
+        // 忽略SSL证书验证的TrustManager
+        TrustManager[] trustAllCerts = new TrustManager[] {
+                new X509TrustManager() {
+                    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
+                        return null;
+                    }
+
+                    public void checkClientTrusted(
+                            java.security.cert.X509Certificate[] certs, String authType) {
+                    }
+
+                    public void checkServerTrusted(
+                            java.security.cert.X509Certificate[] certs, String authType) {
+                    }
+                }
+        };
+
+
+        // 创建请求体
+        JSONObject reqBodyObj = new JSONObject();
+        reqBodyObj.put("app_id", "hcmcloud");
+        reqBodyObj.put("table_name", ""); // 确保这里有一个有效的值
+        reqBodyObj.put("stringDate", "20210301");
+        reqBodyObj.put("condition", "1=1");
+
+        // 设置Basic Authentication的凭证(用户名和密码)
+        String username = "po_soap1";
+        String password = "z123456789";
+
+        final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
+        credsProvider.setCredentials(
+                new AuthScope("httpbin.org", 80),
+                new UsernamePasswordCredentials(username, password.toCharArray()));
+
+        // String baseAuth = getBaseAuth(username, password);
+
+        try (final CloseableHttpClient httpclient = HttpClients.custom()
+                .setDefaultCredentialsProvider(credsProvider)
+                .build()) {
+            // final HttpGet httpget = new HttpGet("http://httpbin.org/basic-auth/admin/123456");
+            SslUtils.ignoreSsl();
+            // D:\developer\jdk-17.0.10\lib\security
+            final HttpPost httpget = new HttpPost("https://podev.minmetals.com.cn:50001/RESTAdapter/BS_OA/BS_MDM/DeleteAssHrtree");
+            // final HttpGet httpget = new HttpGet("https://segmentfault.com/a/1190000042354971#item-9");
+
+            // 设置请求体
+            final StringEntity reqEntity = new StringEntity(reqBodyObj.toString(), StandardCharsets.UTF_8);
+            httpget.setEntity(reqEntity);
+            System.out.println("执行请求" + httpget.getMethod() + " " + httpget.getUri());
+            try (final CloseableHttpResponse response = httpclient.execute(httpget)) {
+                System.out.println("----------------------------------------");
+                System.out.println(response.getCode() + " " + response.getReasonPhrase());
+                System.out.println(EntityUtils.toString(response.getEntity()));
+            }
+        }
+    }
+
+    /**
+     * 401
+     * @param args
+     * @throws Exception
+     */
+    public static void main4(String[] args) throws Exception {
+        // 设置Basic Authentication的凭证(用户名和密码)
+        String username = "po_soap1";
+        String password = "z123456789";
+        final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
+        credsProvider.setCredentials(
+                new AuthScope("httpbin.org", 80),
+                new UsernamePasswordCredentials(username, password.toCharArray()));
+
+        String baseAuth = getBaseAuth(username, password);
+        // 计算基本认证编码
+        // String auth = Base64.getEncoder().encodeToString(
+        //         ("po_soap1" + ":" + "z123456789").getBytes(StandardCharsets.UTF_8)
+        // );
+
+        JSONObject reqBodyObj = new JSONObject();
+        reqBodyObj.put("app_id", "hcmcloud");
+        reqBodyObj.put("table_name", "");
+        reqBodyObj.put("stringDate", "20210301");
+        reqBodyObj.put("condition", "1=1");
+        reqBodyObj.put("secretKey", "f3ac852124d2f991a3f63f2e33dae18b");
+
+        LinkedHashMap<String, String> header = new LinkedHashMap<String, String>();
+        // header.put("Authorization", "Basic " + credsProvider);
+        header.put("Authorization", baseAuth);
+        String postUrl = "https://podev.minmetals.com.cn:50001/RESTAdapter/BS_OA/BS_MDM/DeleteAssHrtree";
+        try {
+            SslUtils.ignoreSsl();
+            String result = HTTPHelper.sendPOST(postUrl, reqBodyObj.toString(), header, "UTF-8");
+            System.out.println(result);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * 响应401
+     * @param args
+     * @throws URISyntaxException
+     */
+    public static void main401(String[] args) throws URISyntaxException {
+        // 设置Basic Authentication的凭证(用户名和密码)
+        String username = "po_soap1";
+        String password = "z123456789";
+        final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
+        credsProvider.setCredentials(
+                new AuthScope("httpbin.org", 80),
+                new UsernamePasswordCredentials(username, password.toCharArray()));
+
+        String baseAuth = getBaseAuth(username, password);
+
+        JSONObject reqBodyObj = new JSONObject();
+        reqBodyObj.put("app_id", "hcmcloud");
+        reqBodyObj.put("table_name", "");
+        reqBodyObj.put("stringDate", "20210301");
+        reqBodyObj.put("condition", "1=1");
+        reqBodyObj.put("secretKey", "f3ac852124d2f991a3f63f2e33dae18b");
+
+        String postUrl = "https://podev.minmetals.com.cn:50001/RESTAdapter/BS_OA/BS_MDM/DeleteAssHrtree";
+
+        // 计算基本认证编码
+ /*       String auth = "Basic " + Base64.getEncoder().encodeToString(
+                (username + ":" + password).getBytes(StandardCharsets.UTF_8)
+        );*/
+
+        // 设置HTTP头部
+        LinkedHashMap<String, String> header = new LinkedHashMap<>();
+        // header.put("Authorization", auth);
+        header.put("Authorization", baseAuth);
+        header.put("Content-Type", "application/json");
+
+        // 发送请求(这里假设HTTPHelper.sendPOST方法支持自定义头部)
+        try {
+            SslUtils.ignoreSsl();
+            String result = HTTPHelper.sendPOST(postUrl, reqBodyObj.toString(), header, "UTF-8");
+            System.out.println(result);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+
+    }
+
+    public static String getBaseAuth(String userName, String password){
+        String auth = userName + ":" + password;
+        String base64Auth = cn.hutool.core.codec.Base64.encodeUrlSafe(auth.getBytes());
+        return  "Basic " + base64Auth;
+    }
+
+    public static void main11(String[] args) {
+        JSONObject reqBodyObj = new JSONObject();
+        reqBodyObj.put("app_id", "hcmcloud");
+        reqBodyObj.put("table_name", "");
+        reqBodyObj.put("stringDate", "20210301");
+        reqBodyObj.put("condition", "1=1");
+        reqBodyObj.put("secretKey", "f3ac852124d2f991a3f63f2e33dae18b");
+        String username = "po_soap1";
+        String password = "z123456789";
+        String postUrl = "https://podev.minmetals.com.cn:50001/RESTAdapter/BS_OA/BS_MDM/DeleteAssHrtree";
+        String s = PostMethodUtils.sendPost(postUrl, reqBodyObj.toString(), username, password);
+        System.out.println(s);
+    }
+
+}

+ 107 - 0
xsky-service/src/test/java/com/itheima/file/HttpClientExample.java

@@ -0,0 +1,107 @@
+package com.itheima.file;
+
+import dm.jdbc.filter.stat.json.JSONObject;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.conn.ssl.NoopHostnameVerifier;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;  
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.util.EntityUtils;
+  
+import javax.net.ssl.SSLContext;  
+import javax.net.ssl.TrustManager;  
+import javax.net.ssl.X509TrustManager;
+import java.nio.charset.StandardCharsets;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;  
+  
+public class HttpClientExample {  
+  
+    public static void main(String[] args) throws Exception {
+  
+        // 忽略SSL证书验证的TrustManager(仅用于测试,不要在生产环境中使用)  
+        TrustManager[] trustAllCerts = new TrustManager[]{  
+            new X509TrustManager() {  
+                @Override  
+                public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {  
+                }  
+  
+                @Override  
+                public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {  
+                }  
+  
+                @Override  
+                public X509Certificate[] getAcceptedIssuers() {  
+                    return new X509Certificate[]{};  
+                }  
+            }  
+        };  
+  
+        // 初始化一个信任所有证书的SSLContext  
+        SSLContext sslContext = SSLContext.getInstance("SSL");  
+        sslContext.init(null, trustAllCerts, new java.security.SecureRandom());  
+  
+        // 使用SSLConnectionSocketFactoryBuilder来设置SSL上下文和主机名验证器  
+        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);  
+  
+        // 创建连接管理器  
+        PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();  
+  
+        // 设置最大连接数等参数(可选)  
+        cm.setMaxTotal(200);  
+        cm.setDefaultMaxPerRoute(20);
+
+        // 设置Basic Authentication的凭证(用户名和密码)
+        String username = "po_soap1";
+        String password = "z123456789";
+
+        // 创建Basic Auth的凭据
+        CredentialsProvider credsProvider = new BasicCredentialsProvider();
+        credsProvider.setCredentials(
+                AuthScope.ANY,
+                new UsernamePasswordCredentials(username, password)
+        );
+  
+        // 使用连接管理器和SSL上下文创建HttpClient  
+        CloseableHttpClient httpclient = HttpClients.custom()
+                .setDefaultCredentialsProvider(credsProvider)
+                .setSSLSocketFactory(sslsf) // 使用自定义的SSLSocketFactory  
+                .setConnectionManager(cm) // 使用自定义的连接管理器  
+                .build();
+
+        // 创建请求体
+        JSONObject reqBodyObj = new JSONObject();
+        reqBodyObj.put("app_id", "hcmcloud");
+        reqBodyObj.put("table_name", ""); // 确保这里有一个有效的值
+        reqBodyObj.put("stringDate", "20210301");
+        reqBodyObj.put("condition", "1=1");
+
+        try {  
+            HttpPost httpPost = new HttpPost("https://podev.minmetals.com.cn:50001/RESTAdapter/BS_OA/BS_MDM/DeleteAssHrtree");
+
+            // ... (设置请求体、头部等)
+            final StringEntity reqEntity = new StringEntity(reqBodyObj.toString(), StandardCharsets.UTF_8);
+            // 将HttpEntity设置为请求体
+            httpPost.setEntity(reqEntity);
+
+            HttpResponse response = httpclient.execute(httpPost);
+  
+            System.out.println("----------------------------------------");  
+            System.out.println(response.getStatusLine());  
+            HttpEntity entity = response.getEntity();  
+            if (entity != null) {  
+                System.out.println(EntityUtils.toString(entity));  
+            }
+        } finally {  
+            httpclient.close();  
+        }  
+    }  
+}