提交 69fb415b authored 作者: inroi's avatar inroi

微调

上级 7c825117
...@@ -61,9 +61,14 @@ ...@@ -61,9 +61,14 @@
</dependency> </dependency>
<!-- Mysql --> <!-- Mysql -->
<dependency> <!--<dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
</dependency>-->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.2.0.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
......
...@@ -2,12 +2,21 @@ package com.shr.api; ...@@ -2,12 +2,21 @@ package com.shr.api;
import com.kingdee.shr.api.Response; import com.kingdee.shr.api.Response;
import com.kingdee.shr.api.SHRClient; import com.kingdee.shr.api.SHRClient;
import com.kingdee.shr.api.Token;
import com.kingdee.shr.sso.client.ltpa.LtpaTokenManager;
import com.kingdee.shr.sso.client.util.UrlUtil;
import com.shr.exception.ShrException; import com.shr.exception.ShrException;
import com.shr.utils.JsonUtil;
import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
...@@ -21,14 +30,15 @@ public class CallShrOsfApi { ...@@ -21,14 +30,15 @@ public class CallShrOsfApi {
private String serverUrl; private String serverUrl;
public CallShrOsfApi() { public CallShrOsfApi() {
serverUrl = "http://172.16.1.67:8090/shr"; serverUrl = "http://172.16.1.67:6890/shr";
} }
public Response callShrOsf(String serviceName, Map<String, Object> param) { public Response callShrOsf(String serviceName, Map<String, Object> param) {
SHRClient shrClient = new SHRClient(); SHRClient shrClient = new SHRClient();
try { try {
Response response = shrClient.executeService(serverUrl, serviceName, param); Token token = this.loginShrByUser(serverUrl);
log.info("SHR返回结果: {}", response); Response response = shrClient.executeOSFService(serverUrl, token, serviceName, param);
log.info("SHR返回结果: {}", JsonUtil.toString(response.getData()));
return response; return response;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -36,5 +46,71 @@ public class CallShrOsfApi { ...@@ -36,5 +46,71 @@ public class CallShrOsfApi {
} }
} }
public Token loginShrByUser(String serverUrl) throws IOException {
String loginUrl = serverUrl + "/OTP2sso.jsp";
Map<String, Object> parameters = new HashMap<>(10);
parameters.put("username", "0196");
String password = LtpaTokenManager.generate((String) parameters.get("username"), LtpaTokenManager.getDefaultLtpaConfig(), "OTP").toString();
parameters.put("password", password);
parameters.put("userAuthPattern", "OTP");
parameters.put("isNotCheckRelogin", "true");
String url = UrlUtil.assembleUrl(loginUrl, parameters);
HttpClient client = new HttpClient();
client.getParams().setParameter("http.protocol.allow-circular-redirects", true);
GetMethod method = new GetMethod(url);
method.addRequestHeader("Referer", serverUrl);
method.getParams().setParameter("http.protocol.single-cookie-header", true);
method.getParams().setParameter("http.protocol.cookie-policy", "compatibility");
method.setFollowRedirects(true);
int status = client.executeMethod(method);
Token token;
if (status != 200) {
System.err.println("Method failed: " + method.getStatusLine());
throw new HttpException("login shr fail, status: " + status);
} else {
token = this.getToken(client.getState().getCookies());
return token;
}
}
private Token getToken(Cookie[] cookies) throws HttpException {
Cookie cookie;
for (Cookie value : cookies) {
cookie = value;
if ("JSESSIONID".equalsIgnoreCase(cookie.getName()) && !cookie.getPath().contains("sso")) {
Token token = new Token();
token.setDomain(cookie.getDomain());
token.setPath(cookie.getPath());
token.setValue(cookie.getValue());
return token;
}
}
throw new HttpException("getToken fail, cookies: " + this.cookieToString(cookies));
}
private String cookieToString(Cookie[] cookies) {
Cookie cookie;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < cookies.length; ++i) {
cookie = cookies[i];
if (i != 0) {
sb.append(",");
}
sb.append("[name=");
sb.append(cookie.getName());
sb.append(", path=");
sb.append(cookie.getPath());
sb.append(", value=");
sb.append(cookie.getValue());
sb.append("]");
}
return sb.toString();
}
} }
package com.shr.controller; package com.shr.controller;
import com.kingdee.shr.sso.client.ltpa.LtpaTokenManager; import com.kingdee.shr.sso.client.ltpa.LtpaTokenManager;
import com.shr.config.ThreadLocalConfig;
import com.shr.utils.StringUtil;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -28,10 +26,11 @@ public class EasController { ...@@ -28,10 +26,11 @@ public class EasController {
//要跳转的url '//'代表首页 //要跳转的url '//'代表首页
String redirectTo = "//"; String redirectTo = "//";
//调用LtpaTokenManager,根据密钥生成用户令牌 //调用LtpaTokenManager,根据密钥生成用户令牌
String ssoUsername = ThreadLocalConfig.get().get("ssoUsername").toString(); /*String ssoUsername = ThreadLocalConfig.get().get("ssoUsername").toString();
if (StringUtil.isBlank(ssoUsername)) { if (StringUtil.isBlank(ssoUsername)) {
ssoUsername = "administrator"; return;
} }*/
String ssoUsername = "administrator";
String password = LtpaTokenManager.generate(ssoUsername, LtpaTokenManager.getDefaultLtpaConfig()).toString(); String password = LtpaTokenManager.generate(ssoUsername, LtpaTokenManager.getDefaultLtpaConfig()).toString();
System.out.println("password: " + password); System.out.println("password: " + password);
...@@ -47,14 +46,15 @@ public class EasController { ...@@ -47,14 +46,15 @@ public class EasController {
@GetMapping(value = "/shr/ssoLogin") @GetMapping(value = "/shr/ssoLogin")
public void shrSsoLogin(HttpServletResponse response) throws IOException { public void shrSsoLogin(HttpServletResponse response) throws IOException {
//s-HR地址 //s-HR地址
String shrLocal = "http://127.0.0.1:6888/shr/home.do"; String shrLocal = "http://172.16.1.67:8090/shr/home.do";
String redirectTo = URLEncoder.encode(shrLocal); String redirectTo = URLEncoder.encode(shrLocal);
//登陆用户名 //登陆用户名
String ssoUsername = ThreadLocalConfig.get().get("ssoUsername").toString(); /*String ssoUsername = ThreadLocalConfig.get().get("ssoUsername").toString();
if (StringUtil.isBlank(ssoUsername)) { if (StringUtil.isBlank(ssoUsername)) {
ssoUsername = "administrator"; return;
} }*/
String ssoUsername = "administrator";
//根据密钥生成的密码串 //根据密钥生成的密码串
String password = LtpaTokenManager.generate(ssoUsername, LtpaTokenManager.getDefaultLtpaConfig(), "OTP").toString(); String password = LtpaTokenManager.generate(ssoUsername, LtpaTokenManager.getDefaultLtpaConfig(), "OTP").toString();
System.out.println("password: " + password); System.out.println("password: " + password);
......
...@@ -6,10 +6,7 @@ import com.shr.serivce.IEmployeeService; ...@@ -6,10 +6,7 @@ import com.shr.serivce.IEmployeeService;
import com.shr.transfer.employee.*; import com.shr.transfer.employee.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/** /**
* @author Inori * @author Inori
...@@ -23,8 +20,8 @@ public class EmployeeController { ...@@ -23,8 +20,8 @@ public class EmployeeController {
@AccessLog("员工列表") @AccessLog("员工列表")
@PostMapping("/employee/list") @GetMapping("/employee/list")
public RestResponse employeeList(@RequestBody(required = true) @Validated EmployeeListInVo inVo) { public RestResponse employeeList(@ModelAttribute @Validated EmployeeListInVo inVo) {
EmployeeListOutVo outVo = employeeService.employeeList(inVo); EmployeeListOutVo outVo = employeeService.employeeList(inVo);
return RestResponse.success(outVo); return RestResponse.success(outVo);
} }
......
package com.shr.controller;
import com.shr.annotion.AccessLog;
import com.shr.common.response.RestResponse;
import com.shr.serivce.IToDoTaskService;
import com.shr.transfer.task.ToDoTaskDetailListInVo;
import com.shr.transfer.task.ToDoTaskDetailListOutVo;
import com.shr.transfer.task.ToDoTaskListInVo;
import com.shr.transfer.task.ToDoTaskListOutVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Inori
*/
@RestController
@RequestMapping("/api")
public class ToDoTaskController {
@Autowired
private IToDoTaskService toDoTaskService;
@AccessLog("待办任务列表总数")
@GetMapping("/to/do/task/list")
public RestResponse toDoTaskList(@ModelAttribute @Validated ToDoTaskListInVo inVo) {
ToDoTaskListOutVo outVo = toDoTaskService.toDoTaskList(inVo);
return RestResponse.success(outVo);
}
@AccessLog("待办任务明细列表")
@GetMapping("/to/do/task/detail/list")
public RestResponse toDoTaskDetailList(@ModelAttribute @Validated ToDoTaskDetailListInVo inVo) {
ToDoTaskDetailListOutVo outVo = toDoTaskService.toDoTaskDetailList(inVo);
return RestResponse.success(outVo);
}
}
...@@ -23,5 +23,17 @@ public interface LogMapper extends BaseMapper<Log> { ...@@ -23,5 +23,17 @@ public interface LogMapper extends BaseMapper<Log> {
*/ */
List<LogListOutVoRecords> logList(@Param("page") Page<LogListOutVoRecords> page, @Param("inVo") LogListInVo inVo); List<LogListOutVoRecords> logList(@Param("page") Page<LogListOutVoRecords> page, @Param("inVo") LogListInVo inVo);
/**
* 是否存在表
*
* @return 0-不存在 1-已存在
*/
Integer isTable();
/**
* 创建日志表
*/
void createTable();
} }
...@@ -28,4 +28,25 @@ ...@@ -28,4 +28,25 @@
<select id="isTable" resultType="java.lang.Integer">
select count(*) from user_tables where table_name =upper('tb_log')
</select>
<insert id="createTable">
create table tb_log (
`id` VARCHAR2(32) DEFAULT SYS_GUID() PRIMARY KEY,
`content` VARCHAR2(500) default null,
`system_type` VARCHAR2(50) default null,
`result` BLOB default null
)
</insert>
</mapper> </mapper>
package com.shr.model; package com.shr.model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName; import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
/** /**
* @author Inori * @author Inori
...@@ -14,8 +11,7 @@ public class Log { ...@@ -14,8 +11,7 @@ public class Log {
/** /**
* 用户ID * 用户ID
*/ */
@TableId(value = "id", type = IdType.AUTO) private String id;
private Integer id;
/** /**
...@@ -27,7 +23,6 @@ public class Log { ...@@ -27,7 +23,6 @@ public class Log {
/** /**
* 系统类型 * 系统类型
*/ */
@TableField("system_type")
private String systemType; private String systemType;
...@@ -40,18 +35,17 @@ public class Log { ...@@ -40,18 +35,17 @@ public class Log {
/** /**
* 创建时间 * 创建时间
*/ */
@TableField("create_time")
private String createTime; private String createTime;
public Log() { public Log() {
} }
public Integer getId() { public String getId() {
return id; return id;
} }
public void setId(Integer id) { public void setId(String id) {
this.id = id; this.id = id;
} }
......
package com.shr.serivce;
import com.shr.transfer.task.ToDoTaskDetailListInVo;
import com.shr.transfer.task.ToDoTaskDetailListOutVo;
import com.shr.transfer.task.ToDoTaskListInVo;
import com.shr.transfer.task.ToDoTaskListOutVo;
/**
* @author Inori
*/
public interface IToDoTaskService {
/**
* 待办列表总数
*
* @param inVo 条件
* @return 列表
*/
ToDoTaskListOutVo toDoTaskList(ToDoTaskListInVo inVo);
/**
* 待办任务明细列表
*
* @param inVo 条件
* @return 列表
*/
ToDoTaskDetailListOutVo toDoTaskDetailList(ToDoTaskDetailListInVo inVo);
}
...@@ -9,6 +9,7 @@ import com.shr.transfer.log.LogListOutVoRecords; ...@@ -9,6 +9,7 @@ import com.shr.transfer.log.LogListOutVoRecords;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.List; import java.util.List;
/** /**
...@@ -21,6 +22,15 @@ public class LogServiceImpl implements ILogService { ...@@ -21,6 +22,15 @@ public class LogServiceImpl implements ILogService {
private LogMapper logMapper; private LogMapper logMapper;
@PostConstruct
public void init() {
Integer isTable = logMapper.isTable();
System.out.println(isTable);
if (isTable == 0) {
logMapper.createTable();
}
}
@Override @Override
public LogListOutVo logList(LogListInVo inVo) { public LogListOutVo logList(LogListInVo inVo) {
Page<LogListOutVoRecords> page = new Page<>(inVo.getPageNo(), inVo.getPageSize()); Page<LogListOutVoRecords> page = new Page<>(inVo.getPageNo(), inVo.getPageSize());
......
package com.shr.serivce.impl;
import com.kingdee.shr.api.Response;
import com.shr.api.CallShrOsfApi;
import com.shr.common.response.RestResponse;
import com.shr.serivce.IToDoTaskService;
import com.shr.transfer.task.ToDoTaskDetailListInVo;
import com.shr.transfer.task.ToDoTaskDetailListOutVo;
import com.shr.transfer.task.ToDoTaskListInVo;
import com.shr.transfer.task.ToDoTaskListOutVo;
import com.shr.utils.HttpClientUtil;
import com.shr.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author Inori
*/
@Service
public class ToDoTaskServiceImpl implements IToDoTaskService {
@Autowired
private CallShrOsfApi callShrOsfApi;
@Override
public ToDoTaskListOutVo toDoTaskList(ToDoTaskListInVo inVo) {
Response totalResponse = callShrOsfApi.callShrOsf("getUnProcessAssignCount", null);
Map<String, Object> map = JsonUtil.toMap(JsonUtil.toString(totalResponse.getData()), String.class, Object.class);
Map<String, Object> temp = new HashMap<>();
temp.put("total", Integer.parseInt((String) map.get("total")));
temp.put("page", 1);
temp.put("rows", 9999);
Response detailResponse = callShrOsfApi.callShrOsf("getUnProcessAssign", temp);
ToDoTaskListOutVo outVo = new ToDoTaskListOutVo();
outVo.setTotal(Integer.parseInt((String) map.get("total")));
outVo.setTotalRecords(JsonUtil.toList(JsonUtil.toString(map.get("categoryCount")), Object.class));
outVo.setDetailRecords(JsonUtil.toList(JsonUtil.toString(detailResponse.getData()), Object.class));
this.toDoTaskSynchronization(outVo);
return outVo;
}
@Override
public ToDoTaskDetailListOutVo toDoTaskDetailList(ToDoTaskDetailListInVo inVo) {
Response response = callShrOsfApi.callShrOsf("getUnProcessAssign", null);
ToDoTaskDetailListOutVo outVo = new ToDoTaskDetailListOutVo();
outVo.setRecords(JsonUtil.toList(JsonUtil.toString(response.getData()), Object.class));
return outVo;
}
public RestResponse toDoTaskSynchronization(ToDoTaskListOutVo outVo) {
String url = "http://172.16.1.78:81";
String json = "{\"userName\":\"hrrest\",\"password\":\"hrhdrest123\"}";
String toekn = HttpClientUtil.sendPost(url + "/seeyon/rest/token", json);
Map<String, Object> temp = JsonUtil.toMap(toekn, String.class, Object.class);
if (CollectionUtils.isEmpty(temp) && !temp.containsKey("id")) {
return RestResponse.fail("OA登陆失败");
}
List<Map<String, Object>> tempList = new ArrayList<>();
for (Object object : outVo.getDetailRecords()) {
Map<String, Object> map = JsonUtil.toMap(JsonUtil.toString(object), String.class, Object.class);
Map<String, Object> reqeust = new HashMap<>(15);
reqeust.put("taskId", map.get("id"));
reqeust.put("registerCode", "3001");
reqeust.put("title", map.get("subject"));
reqeust.put("classify", "erp");
reqeust.put("contentType", "erp");
reqeust.put("thirdSenderId", "");
reqeust.put("senderName", map.get("sender"));
reqeust.put("thirdReceiverId", "");
reqeust.put("noneBindingReceiver", map.get("priorPerform"));
reqeust.put("noneBindingSender", map.get("sender"));
reqeust.put("creationDate", map.get("createdTime"));
reqeust.put("state", map.get("state"));
reqeust.put("subState", "0");
reqeust.put("content", "");
reqeust.put("url", "http://ericbing/K3Cloud7.5/html5/index.aspx");
reqeust.put("h5url", "");
reqeust.put("appParam", "");
tempList.add(reqeust);
}
String result = HttpClientUtil.sendPost(url + "/seeyon/rest/thirdpartyPending/receive?token=" + temp.get("id"), JsonUtil.toString(tempList));
System.out.println("---------------->" + result);
Map<String, Object> map = JsonUtil.toMap(result, String.class, Object.class);
if (CollectionUtils.isEmpty(map)) {
return RestResponse.fail("无返回值");
}
if ("false".equals(map.get("success"))) {
List<Object> errorList = JsonUtil.toList(JsonUtil.toString(map.get("errorMsgs")), Object.class);
String errorDetail = errorList.stream().map(m -> (String) JsonUtil.toMap(JsonUtil.toString(m), String.class, Object.class).get("errorDetail")).collect(Collectors.joining(", "));
return RestResponse.fail(errorDetail);
}
return RestResponse.success();
}
}
package com.shr.transfer.task;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* @author Inori
*/
@Data
public class ToDoTaskDetailListInVo {
/**
* 系统类型
*/
@NotBlank(message = "参数systemType缺失")
private String systemType;
}
package com.shr.transfer.task;
import lombok.Data;
import java.util.List;
/**
* @author Inori
*/
@Data
public class ToDoTaskDetailListOutVo {
/**
* 记录
*/
private List<Object> records;
}
package com.shr.transfer.task;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* @author Inori
*/
@Data
public class ToDoTaskListInVo {
/**
* 系统类型
*/
@NotBlank(message = "参数systemType缺失")
private String systemType;
}
package com.shr.transfer.task;
import lombok.Data;
import java.util.List;
/**
* @author Inori
*/
@Data
public class ToDoTaskListOutVo {
/**
* 总数
*/
private Integer total;
/**
* 总数记录
*/
private List<Object> totalRecords;
/**
* 明细记录
*/
private List<Object> detailRecords;
}
package com.shr.utils;
import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.List;
/**
* 发送请求工具类
*
* @author Lnori
*/
public class HttpClientUtil {
private static final Logger log = LoggerFactory.getLogger(HttpClientUtil.class);
public static void main(String[] args) throws UnsupportedEncodingException {
String s = sendGet("https://r.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?g_tk=&uins=865347524");
System.out.println(s.indexOf("{"));
System.out.println(s.indexOf("}"));
String substring1 = s.substring(s.indexOf("{") + 2, s.indexOf(":") - 1);
System.out.println(substring1);
String substring = s.substring(s.indexOf("["), s.indexOf("]") + 1);
List<String> list = JsonUtil.toList(substring, String.class);
for (String s1 : list) {
System.out.println(s1);
}
}
public static final String[] ENCODES = new String[]{"UTF-8", "GBK", "GB2312", "ISO-8859-1", "ISO-8859-2"};
/**
* 发送Get请求
*
* @param url url
* @return 结果
*/
public static String sendGet(String url) {
log.info("【Get请求】Url: {}", url);
/*
* 1.生成HttpClient对象并设置参数
*/
HttpClient httpClient = new HttpClient();
//设置Http连接超时为10秒
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(10000);
/*
* 2.生成GetMethod对象并设置参数
*/
GetMethod getMethod = new GetMethod(url);
//设置get请求超时为10秒
getMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 10000);
//设置请求重试处理,用的是默认的重试处理:请求三次
getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
String response;
/*
* 3.执行HTTP GET 请求
*/
try {
int statusCode = httpClient.executeMethod(getMethod);
/*
* 4.判断访问的状态码
*/
if (statusCode != HttpStatus.SC_OK) {
log.error("请求出错:{}", getMethod.getStatusLine());
}
/*
* 5.处理HTTP响应内容
*/
//读取为字节数组
byte[] responseBody = getMethod.getResponseBody();
response = new String(responseBody, "GBK");
log.info("【Get请求】返回值: {}", response);
return response;
} catch (HttpException e) {
log.error("请检查输入的URL!");
} catch (IOException e) {
log.error("发生网络异常!");
} finally {
/*
* 6.释放连接
*/
getMethod.releaseConnection();
httpClient.getHttpConnectionManager().closeIdleConnections(0L);
}
return "";
}
public static String sendPost(String url, String json) {
log.info("【Post请求】Url: {}", url);
/*
* 1.生成HttpClient对象并设置参数
*/
HttpClient httpClient = new HttpClient();
//设置Http连接超时为10秒
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(10000);
/*
* 2.生成PostMethod对象并设置参数
*/
PostMethod postMethod = new PostMethod(url);
//设置post请求超时为10秒
postMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 10000);
//设置请求重试处理,用的是默认的重试处理:请求三次
postMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
//设置请求头
postMethod.addRequestHeader("Content-Type", "application/json");
/*
* 3.执行HTTP GET 请求
*/
String response = "";
try {
//json格式的参数解析
RequestEntity entity = new StringRequestEntity(json, "application/json", "UTF-8");
postMethod.setRequestEntity(entity);
int statusCode = httpClient.executeMethod(postMethod);
/*
* 4.判断访问的状态码
*/
if (statusCode != HttpStatus.SC_OK) {
log.error("请求出错:{}", postMethod.getStatusLine());
}
/*
* 5.处理HTTP响应内容
*/
byte[] responseBody = postMethod.getResponseBody();
response = new String(responseBody, StandardCharsets.UTF_8);
log.info("【Post请求】返回值: {}", response);
return response;
} catch (HttpException e) {
log.error("请检查输入的URL!");
} catch (IOException e) {
log.error("发生网络异常!");
} finally {
/*
* 6.释放连接
*/
postMethod.releaseConnection();
httpClient.getHttpConnectionManager().closeIdleConnections(0L);
}
return "";
}
}
...@@ -19,16 +19,21 @@ spring: ...@@ -19,16 +19,21 @@ spring:
max-request-size: 100MB max-request-size: 100MB
max-file-size: 100MB max-file-size: 100MB
# datasource:
# url: jdbc:mysql://127.0.0.1:3306/shr_server?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=CTT&allowPublicKeyRetrieval=true
# username: root
# password: 123456
# driver-class-name: com.mysql.cj.jdbc.Driver
datasource: datasource:
url: jdbc:mysql://127.0.0.1:3306/shr_server?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=CTT&allowPublicKeyRetrieval=true url: jdbc:oracle:thin:@192.168.20.128:1521:orcl
username: root username: ssm
password: 123456 password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: oracle.jdbc.driver.OracleDriver
mybatis-plus: mybatis-plus:
mapper-locations: classpath*:/**/*Mapper.xml mapper-locations: classpath*:/**/*Mapper.xml
typeAliasesPackage: com.shr.model typeAliasesPackage: com.shr.model
configuration: configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
mapUnderscoreToCamelCase: true mapUnderscoreToCamelCase: true
cache-enabled: true \ No newline at end of file
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论