#EC-HJ-17# 去掉日志输出

feature-LeeD-20221025
shilei 3 years ago
parent 3c03a68f26
commit f61db4f586

@ -34,16 +34,17 @@ public class HttpReqUtils extends BaseBean{
.build(); .build();
try { try {
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
int code = response.code();
bb.writeLog("response.code():"+response.code()); String bodyMsg = msgData = response.body().string();
bb.writeLog("response.body():"+response.body().string()); bb.writeLog("response.code():"+code);
bb.writeLog("response.body():"+bodyMsg);
if(response!=null && response.code() == 200){ if(code == 200){
msgData = response.body().string(); msgData = bodyMsg;
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
bb.writeLog("msgData:"+msgData);
return msgData; return msgData;
} }

@ -36,15 +36,17 @@ public class HttpRequestUtil extends BaseBean{
try { try {
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
bb.writeLog("response.code():"+response.code()); int code = response.code();
bb.writeLog("response.body():"+response.body().string()); String bodyMsg = msgData = response.body().string();
bb.writeLog("response.code():"+code);
if(response!=null && response.code() == 200){ bb.writeLog("response.body():"+bodyMsg);
msgData = response.body().string(); if(code == 200){
msgData = bodyMsg;
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
bb.writeLog("msgData:"+msgData);
return msgData; return msgData;
} }

@ -2,6 +2,7 @@ package com.customization.sendtodo;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang.StringUtils;
import weaver.conn.RecordSet; import weaver.conn.RecordSet;
import weaver.general.BaseBean; import weaver.general.BaseBean;
import weaver.general.Util; import weaver.general.Util;
@ -12,8 +13,8 @@ import java.util.regex.Pattern;
public class SendPortalTodoUtil { public class SendPortalTodoUtil {
public static String EMAIL_REGEX_DEFAULT = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"; //public static String EMAIL_REGEX_DEFAULT = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
public static String EMAIL_REGEX_DEFAULT = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
/*** /***
* *
* @param requestId * @param requestId
@ -117,32 +118,34 @@ public class SendPortalTodoUtil {
requestObject.put("taskObjectList",taskObjectList); requestObject.put("taskObjectList",taskObjectList);
String email = Util.null2String(rs.getString("email")) ; String email = Util.null2String(rs.getString("email")) ;
bb.writeLog("email1:"+email);
Matcher matcher = regex.matcher(email); Matcher matcher = regex.matcher(email);
if(matcher.matches()){ if(matcher.matches()){
emailArray.add(email); emailArray.add(email);
} }
} }
bb.writeLog("dataJsonnew:"+requestObject.toJSONString()); //bb.writeLog("dataJsonnew:"+requestObject.toJSONString());
// String username = "admin"; // String username = "admin";
// String passwd = "Uportal_123"; // String passwd = "Uportal_123";
// String todourl = "http://172.16.25.133/portal-web/centerTodo/sync" ; // String todourl = "http://172.16.25.133/portal-web/centerTodo/sync" ;
String auth = username + ":" + passwd; String auth = username + ":" + passwd;
String msgdata = httpRequestUtil.doPostByAuth(portal_todourl,requestObject.toJSONString(),auth); String msgdata = httpRequestUtil.doPostByAuth(portal_todourl,requestObject.toJSONString(),auth);
bb.writeLog("msgdata:"+msgdata); bb.writeLog("msgdata:"+msgdata);
if(!"".equals(msgdata)){ if(StringUtils.isNotEmpty(msgdata)){
JSONObject msgObject = JSONObject.parseObject(msgdata); JSONObject msgObject = JSONObject.parseObject(msgdata);
//{"resultCode":"1","resultMsg":"No Result"} //{"resultCode":"1","resultMsg":"No Result"}
if(msgObject.containsKey("resultCode")){ if(msgObject.containsKey("resultCode")){
String resultCode = msgObject.getString("resultCode"); String resultCode = msgObject.getString("resultCode");
if("0".equals(resultCode)){ if("0".equals(resultCode)){
System.out.println(emailArray.toJSONString()); bb.writeLog("emailArray:"+emailArray.toJSONString());
if(emailArray.size() > 0)
String notificationSubject = "You have a new to-do list:"+requestname+",Please handle it in time"; {
String notificationContent = "You have a new to-do list:"+requestname+",Please handle it in time"; String notificationSubject = "You have a new to-do list:"+requestname+",Please handle it in time";
String notificationContent = "You have a new to-do list:"+requestname+",Please handle it in time";
sendMailUtil.sendMail(requestId,emailArray.toJSONString(),notificationSubject,notificationContent); sendMailUtil.sendMail(requestId,emailArray.toJSONString(),notificationSubject,notificationContent);
}
}else{ }else{
sendPortalErrorUtil.doCreateSendPortalTodoErrorInfo(); sendPortalErrorUtil.doCreateSendPortalTodoErrorInfo();
@ -265,6 +268,7 @@ public class SendPortalTodoUtil {
taskObjectList.add(taskObject); taskObjectList.add(taskObject);
String email = Util.null2String(rs.getString("email")) ; String email = Util.null2String(rs.getString("email")) ;
bb.writeLog("email2:"+email);
Matcher matcher = regex.matcher(email); Matcher matcher = regex.matcher(email);
if(matcher.matches()){ if(matcher.matches()){
emailArray.add(email); emailArray.add(email);
@ -274,7 +278,7 @@ public class SendPortalTodoUtil {
requestObject.put("taskObjectList",taskObjectList); requestObject.put("taskObjectList",taskObjectList);
String auth = username + ":" + passwd; String auth = username + ":" + passwd;
bb.writeLog("requestObject:"+requestObject.toJSONString()); //bb.writeLog("requestObject:"+requestObject.toJSONString());
String msgdata = httpRequestUtil.doPostByAuth(portal_todourl,requestObject.toJSONString(),auth); String msgdata = httpRequestUtil.doPostByAuth(portal_todourl,requestObject.toJSONString(),auth);
bb.writeLog("msgdata:"+msgdata); bb.writeLog("msgdata:"+msgdata);
if(!"".equals(msgdata)){ if(!"".equals(msgdata)){
@ -284,12 +288,13 @@ public class SendPortalTodoUtil {
String resultCode = msgObject.getString("resultCode"); String resultCode = msgObject.getString("resultCode");
if("0".equals(resultCode)){ if("0".equals(resultCode)){
System.out.println(emailArray.toJSONString()); bb.writeLog("emailArray:"+emailArray.toJSONString());
if(emailArray.size() > 0)
String notificationSubject = "You have a new to-do list:"+requestname+",Please handle it in time"; {
String notificationContent = "You have a new to-do list:"+requestname+",Please handle it in time"; String notificationSubject = "You have a new to-do list:"+requestname+",Please handle it in time";
String notificationContent = "You have a new to-do list:"+requestname+",Please handle it in time";
sendMailUtil.sendMail(requestid,emailArray.toJSONString(),notificationSubject,notificationContent); sendMailUtil.sendMail(requestid,emailArray.toJSONString(),notificationSubject,notificationContent);
}
}else{ }else{
sendPortalErrorUtil.doCreateSendPortalTodoErrorInfo(); sendPortalErrorUtil.doCreateSendPortalTodoErrorInfo();
} }
@ -483,6 +488,7 @@ public class SendPortalTodoUtil {
taskObjectList.add(taskObject); taskObjectList.add(taskObject);
String email = Util.null2String(rs.getString("email")) ; String email = Util.null2String(rs.getString("email")) ;
bb.writeLog("email3:"+email);
Matcher matcher = regex.matcher(email); Matcher matcher = regex.matcher(email);
if(matcher.matches()){ if(matcher.matches()){
emailArray.add(email); emailArray.add(email);
@ -492,7 +498,7 @@ public class SendPortalTodoUtil {
} }
String auth = username + ":" + passwd; String auth = username + ":" + passwd;
bb.writeLog("requestObject:"+requestObject.toJSONString()); //bb.writeLog("requestObject:"+requestObject.toJSONString());
String msgdata = httpRequestUtil.doPostByAuth(portal_todourl,requestObject.toJSONString(),auth); String msgdata = httpRequestUtil.doPostByAuth(portal_todourl,requestObject.toJSONString(),auth);
bb.writeLog("msgdata:"+msgdata); bb.writeLog("msgdata:"+msgdata);
if(!"".equals(msgdata)){ if(!"".equals(msgdata)){
@ -502,10 +508,14 @@ public class SendPortalTodoUtil {
String resultCode = msgObject.getString("resultCode"); String resultCode = msgObject.getString("resultCode");
if("0".equals(resultCode)){ if("0".equals(resultCode)){
System.out.println(emailArray.toJSONString()); bb.writeLog("emailArray:"+emailArray.toJSONString());
String notificationSubject = "You have a new to-do list:"+requestname+",Please handle it in time"; if(emailArray.size() > 0)
String notificationContent = "You have a new to-do list:"+requestname+",Please handle it in time"; {
sendMailUtil.sendMail(requestid,emailArray.toJSONString(),notificationSubject,notificationContent); String notificationSubject = "You have a new to-do list:"+requestname+",Please handle it in time";
String notificationContent = "You have a new to-do list:"+requestname+",Please handle it in time";
sendMailUtil.sendMail(requestid,emailArray.toJSONString(),notificationSubject,notificationContent);
}
}else{ }else{
sendPortalErrorUtil.doCreateSendPortalTodoErrorInfo(); sendPortalErrorUtil.doCreateSendPortalTodoErrorInfo();
@ -615,7 +625,6 @@ public class SendPortalTodoUtil {
JSONObject taskObject = new JSONObject(); JSONObject taskObject = new JSONObject();
String objectCode = usercode ; String objectCode = usercode ;
String operatorCode = usercode ; String operatorCode = usercode ;
taskObject.put("objectAction",objectAction); taskObject.put("objectAction",objectAction);
@ -626,6 +635,7 @@ public class SendPortalTodoUtil {
taskObjectList.add(taskObject); taskObjectList.add(taskObject);
String email = Util.null2String(rs.getString("email")) ; String email = Util.null2String(rs.getString("email")) ;
bb.writeLog("email4:"+email);
Matcher matcher = regex.matcher(email); Matcher matcher = regex.matcher(email);
if(matcher.matches()){ if(matcher.matches()){
emailArray.add(email); emailArray.add(email);
@ -636,7 +646,7 @@ public class SendPortalTodoUtil {
requestObject.put("taskObjectList",taskObjectList); requestObject.put("taskObjectList",taskObjectList);
String auth = username + ":" + passwd; String auth = username + ":" + passwd;
bb.writeLog("requestObject:"+requestObject.toJSONString()); //bb.writeLog("requestObject:"+requestObject.toJSONString());
String msgdata = httpRequestUtil.doPostByAuth(portal_todourl,requestObject.toJSONString(),auth); String msgdata = httpRequestUtil.doPostByAuth(portal_todourl,requestObject.toJSONString(),auth);
bb.writeLog("msgdata:"+msgdata); bb.writeLog("msgdata:"+msgdata);
if(!"".equals(msgdata)){ if(!"".equals(msgdata)){
@ -646,13 +656,13 @@ public class SendPortalTodoUtil {
String resultCode = msgObject.getString("resultCode"); String resultCode = msgObject.getString("resultCode");
if("0".equals(resultCode)){ if("0".equals(resultCode)){
System.out.println(emailArray.toJSONString()); bb.writeLog("emailArray:"+emailArray.toJSONString());
if(emailArray.size() > 0)
String notificationSubject = "You have a new to-do list:"+requestname+",Please handle it in time"; {
String notificationContent = "You have a new to-do list:"+requestname+",Please handle it in time"; String notificationSubject = "You have a new to-do list:"+requestname+",Please handle it in time";
String notificationContent = "You have a new to-do list:"+requestname+",Please handle it in time";
sendMailUtil.sendMail(requestid,emailArray.toJSONString(),notificationSubject,notificationContent); sendMailUtil.sendMail(requestid,emailArray.toJSONString(),notificationSubject,notificationContent);
}
}else{ }else{
sendPortalErrorUtil.doCreateSendPortalTodoErrorInfo(); sendPortalErrorUtil.doCreateSendPortalTodoErrorInfo();
} }

@ -33,52 +33,52 @@ public class HttpRequestUtil extends BaseBean{
* @throws ParseException * @throws ParseException
* @throws IOException * @throws IOException
*/ */
public String sendPost(String url, Map<String,String> headers,String encoding){ // public String sendPost(String url, Map<String,String> headers,String encoding){
String body = ""; // String body = "";
//
BaseBean bb = new BaseBean(); // BaseBean bb = new BaseBean();
bb.writeLog("url ==" + url); // bb.writeLog("url ==" + url);
//
//创建httpclient对象 // //创建httpclient对象
CloseableHttpClient client = HttpClients.createDefault(); // CloseableHttpClient client = HttpClients.createDefault();
//创建post方式请求对象 // //创建post方式请求对象
HttpPost httpPost = new HttpPost(url); // HttpPost httpPost = new HttpPost(url);
//
//设置参数到请求对象中 // //设置参数到请求对象中
if (headers != null && headers.size() > 0) { // if (headers != null && headers.size() > 0) {
for (Map.Entry<String, String> entry : headers.entrySet()) { // for (Map.Entry<String, String> entry : headers.entrySet()) {
bb.writeLog("key:"+entry.getKey()); // bb.writeLog("key:"+entry.getKey());
bb.writeLog("val:"+entry.getValue()); // bb.writeLog("val:"+entry.getValue());
httpPost.addHeader(entry.getKey(),entry.getValue()); // httpPost.addHeader(entry.getKey(),entry.getValue());
} // }
} // }
//
//设置header信息 // //设置header信息
//指定报文头【Content-type】、【User-Agent】 // //指定报文头【Content-type】、【User-Agent】
// httpPost.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); //// httpPost.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
//
//执行请求操作,并拿到结果(同步阻塞) // //执行请求操作,并拿到结果(同步阻塞)
CloseableHttpResponse response = null; // CloseableHttpResponse response = null;
try { // try {
//
response = client.execute(httpPost); // response = client.execute(httpPost);
bb.writeLog(response.getStatusLine().getStatusCode()); // bb.writeLog(response.getStatusLine().getStatusCode());
//获取结果实体 // //获取结果实体
HttpEntity entity = response.getEntity(); // HttpEntity entity = response.getEntity();
if (entity != null) { // if (entity != null) {
//按指定编码转换结果实体为String类型 // //按指定编码转换结果实体为String类型
body = EntityUtils.toString(entity, encoding); // body = EntityUtils.toString(entity, encoding);
} // }
EntityUtils.consume(entity); // EntityUtils.consume(entity);
//释放链接 // //释放链接
response.close(); // response.close();
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
bb.writeLog("e:"+e); // bb.writeLog("e:"+e);
} // }
//
return body; // return body;
} // }
/** /**
@ -89,69 +89,69 @@ public class HttpRequestUtil extends BaseBean{
* name1=value1&name2=value2 * name1=value1&name2=value2
* @return result * @return result
*/ */
public String sendGet(String url, Map<String,String> headers,String uid) { // public String sendGet(String url, Map<String,String> headers,String uid) {
String result = ""; // String result = "";
BufferedReader in = null; // BufferedReader in = null;
//
BaseBean bb = new BaseBean(); // BaseBean bb = new BaseBean();
bb.writeLog("url ==" + url); // bb.writeLog("url ==" + url);
bb.writeLog("uid ==" + uid); // bb.writeLog("uid ==" + uid);
try { // try {
String urlNameString = url ; // String urlNameString = url ;
URL realUrl = new URL(urlNameString); // 打开和URL之间的连接 // URL realUrl = new URL(urlNameString); // 打开和URL之间的连接
HttpURLConnection connection= (HttpURLConnection) realUrl.openConnection(); // HttpURLConnection connection= (HttpURLConnection) realUrl.openConnection();
connection.setRequestProperty("accept", "*/*"); // connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive"); // connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); // connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
//
connection.setDoOutput(true); // connection.setDoOutput(true);
connection.setDoInput(true); // connection.setDoInput(true);
connection.setUseCaches(false); // connection.setUseCaches(false);
connection.setRequestMethod("GET"); // connection.setRequestMethod("GET");
//
//connection.addRequestProperty("Cookie", "SESSION="+uid); // //connection.addRequestProperty("Cookie", "SESSION="+uid);
//
if (headers != null && headers.size() > 0) // if (headers != null && headers.size() > 0)
{ // {
for (Map.Entry<String, String> entry : headers.entrySet()) { // for (Map.Entry<String, String> entry : headers.entrySet()) {
bb.writeLog("key:"+entry.getKey()); // bb.writeLog("key:"+entry.getKey());
bb.writeLog("val:"+entry.getValue()); // bb.writeLog("val:"+entry.getValue());
connection.addRequestProperty(entry.getKey(), entry.getValue()); // connection.addRequestProperty(entry.getKey(), entry.getValue());
} // }
} // }
//
// 建立实际的连接 // // 建立实际的连接
connection.connect(); // connection.connect();
// 获取所有响应头字段 // // 获取所有响应头字段
//Map<String, List<String>> map = connection.getHeaderFields(); // //Map<String, List<String>> map = connection.getHeaderFields();
// 遍历所有的响应头字段 // // 遍历所有的响应头字段
//for (String key : map.keySet()) { // //for (String key : map.keySet()) {
// System.out.println(key + "--->" + map.get(key)); // // System.out.println(key + "--->" + map.get(key));
//} // //}
// 定义 BufferedReader输入流来读取URL的响应 // // 定义 BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader( // in = new BufferedReader(new InputStreamReader(
connection.getInputStream(),"UTF-8")); // connection.getInputStream(),"UTF-8"));
String line; // String line;
while ((line = in.readLine()) != null) { // while ((line = in.readLine()) != null) {
result += line; // result += line;
} // }
} catch (Exception e) { // } catch (Exception e) {
bb.writeLog("发送GET请求出现异常" + e); // bb.writeLog("发送GET请求出现异常" + e);
e.printStackTrace(); // e.printStackTrace();
} // }
// 使用finally块来关闭输入流 // // 使用finally块来关闭输入流
finally { // finally {
try { // try {
if (in != null) { // if (in != null) {
in.close(); // in.close();
} // }
} catch (Exception e2) { // } catch (Exception e2) {
e2.printStackTrace(); // e2.printStackTrace();
} // }
} // }
//
return result; // return result;
} // }
/*** /***
@ -164,7 +164,7 @@ public class HttpRequestUtil extends BaseBean{
public String httpGet1(String url, Map<String,String> headers, String encode){ public String httpGet1(String url, Map<String,String> headers, String encode){
BaseBean bb = new BaseBean(); BaseBean bb = new BaseBean();
bb.writeLog("url",url); //bb.writeLog("url",url);
if(encode == null){ if(encode == null){
encode = "UTF-8"; encode = "UTF-8";
} }
@ -187,7 +187,7 @@ public class HttpRequestUtil extends BaseBean{
httpResponse = closeableHttpClient.execute(httpGet); httpResponse = closeableHttpClient.execute(httpGet);
if(httpResponse.getStatusLine().getStatusCode() == 200){ if(httpResponse.getStatusLine().getStatusCode() == 200){
bb.writeLog(httpResponse.getStatusLine().getStatusCode()); //bb.writeLog(httpResponse.getStatusLine().getStatusCode());
HttpEntity entity = httpResponse.getEntity(); HttpEntity entity = httpResponse.getEntity();
content = EntityUtils.toString(entity, encode); content = EntityUtils.toString(entity, encode);
} }
@ -217,58 +217,58 @@ public class HttpRequestUtil extends BaseBean{
* @param encode * @param encode
* @return * @return
*/ */
public String httpGet2(String url,Map<String,String> headers,String encode) // public String httpGet2(String url,Map<String,String> headers,String encode)
{ // {
//
BaseBean bb = new BaseBean(); // BaseBean bb = new BaseBean();
bb.writeLog("url",url); // bb.writeLog("url",url);
if(encode == null){ // if(encode == null){
encode = "UTF-8"; // encode = "UTF-8";
} // }
CloseableHttpResponse httpResponse = null; // CloseableHttpResponse httpResponse = null;
CloseableHttpClient closeableHttpClient = null; // CloseableHttpClient closeableHttpClient = null;
String content = null; // String content = null;
//since 4.3 不再使用 DefaultHttpClient // //since 4.3 不再使用 DefaultHttpClient
try { // try {
closeableHttpClient = HttpClientBuilder.create().build(); // closeableHttpClient = HttpClientBuilder.create().build();
HttpGet httpGet = new HttpGet(url); // HttpGet httpGet = new HttpGet(url);
//设置header // //设置header
if (headers != null && headers.size() > 0) { // if (headers != null && headers.size() > 0) {
for (Map.Entry<String, String> entry : headers.entrySet()) { // for (Map.Entry<String, String> entry : headers.entrySet()) {
//
bb.writeLog("key:"+entry.getKey()); // bb.writeLog("key:"+entry.getKey());
bb.writeLog("val:"+entry.getValue()); // bb.writeLog("val:"+entry.getValue());
//
httpGet.addHeader(entry.getKey(),entry.getValue()); // httpGet.addHeader(entry.getKey(),entry.getValue());
} // }
} // }
//
httpGet.setHeader("Accept", "*"); // httpGet.setHeader("Accept", "*");
//
httpResponse = closeableHttpClient.execute(httpGet); // httpResponse = closeableHttpClient.execute(httpGet);
if(httpResponse.getStatusLine().getStatusCode() == 200) // if(httpResponse.getStatusLine().getStatusCode() == 200)
{ // {
bb.writeLog(httpResponse.getStatusLine().getStatusCode()); // bb.writeLog(httpResponse.getStatusLine().getStatusCode());
HttpEntity entity = httpResponse.getEntity(); // HttpEntity entity = httpResponse.getEntity();
content = EntityUtils.toString(entity, encode); // content = EntityUtils.toString(entity, encode);
} // }
} catch (Exception e) { // } catch (Exception e) {
e.printStackTrace(); // e.printStackTrace();
bb.writeLog("er333:"+e); // bb.writeLog("er333:"+e);
}finally{ // }finally{
try { // try {
httpResponse.close(); // httpResponse.close();
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
} // }
try { //关闭连接、释放资源 // try { //关闭连接、释放资源
closeableHttpClient.close(); // closeableHttpClient.close();
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
return content; // return content;
} // }
/*** /***
* *
@ -276,37 +276,37 @@ public class HttpRequestUtil extends BaseBean{
* @param jsonstr * @param jsonstr
* @return * @return
*/ */
public static String doPostByAuth(String url,String jsonstr,String auth){ // public static String doPostByAuth(String url,String jsonstr,String auth){
CloseableHttpClient httpClient = null; // CloseableHttpClient httpClient = null;
HttpPost httpPost = null; // HttpPost httpPost = null;
String result = null; // String result = null;
try{ // try{
String authStr = new String(Base64.encode(auth)); // String authStr = new String(Base64.encode(auth));
httpClient = HttpClients.createDefault(); // httpClient = HttpClients.createDefault();
httpPost = new HttpPost(url); // httpPost = new HttpPost(url);
// String head_param_encode = urlEncode(head_param); //// String head_param_encode = urlEncode(head_param);
System.out.println("authStr:"+authStr); // System.out.println("authStr:"+authStr);
httpPost.addHeader("Connection", "Keep-Alive"); // httpPost.addHeader("Connection", "Keep-Alive");
httpPost.addHeader("Cache-Control", "No-Cache"); // httpPost.addHeader("Cache-Control", "No-Cache");
httpPost.addHeader("Accept", "*/*"); // httpPost.addHeader("Accept", "*/*");
httpPost.addHeader("Content-Type", "application/json;charset=utf-8"); // httpPost.addHeader("Content-Type", "application/json;charset=utf-8");
httpPost.addHeader("Authorization", "Basic " + authStr); // httpPost.addHeader("Authorization", "Basic " + authStr);
httpPost.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"); // httpPost.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36");
StringEntity se = new StringEntity(jsonstr); // StringEntity se = new StringEntity(jsonstr);
se.setContentType("application/json;charset=utf-8"); // se.setContentType("application/json;charset=utf-8");
httpPost.setEntity(se); // httpPost.setEntity(se);
HttpResponse response = httpClient.execute(httpPost); // HttpResponse response = httpClient.execute(httpPost);
if(response != null){ // if(response != null){
HttpEntity resEntity = response.getEntity(); // HttpEntity resEntity = response.getEntity();
if(resEntity != null){ // if(resEntity != null){
result = EntityUtils.toString(resEntity,"utf-8"); // result = EntityUtils.toString(resEntity,"utf-8");
} // }
} // }
}catch(Exception ex){ // }catch(Exception ex){
ex.printStackTrace(); // ex.printStackTrace();
} // }
return result; // return result;
} // }
// public static String urlEncode(String url) throws UnsupportedEncodingException { // public static String urlEncode(String url) throws UnsupportedEncodingException {
@ -327,29 +327,29 @@ public class HttpRequestUtil extends BaseBean{
// } // }
public String doPostByAuth2(String dataJson){ // public String doPostByAuth2(String dataJson){
BaseBean bb = new BaseBean(); // BaseBean bb = new BaseBean();
String msgData = "" ; // String msgData = "" ;
OkHttpClient client = new OkHttpClient().newBuilder() // OkHttpClient client = new OkHttpClient().newBuilder()
.build(); // .build();
MediaType mediaType = MediaType.parse("application/json"); // MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, dataJson); // RequestBody body = RequestBody.create(mediaType, dataJson);
Request request = new Request.Builder() // Request request = new Request.Builder()
.url("http://172.16.25.133/portal-web/centerTodo/sync") // .url("http://172.16.25.133/portal-web/centerTodo/sync")
.method("POST", body) // .method("POST", body)
.addHeader("Authorization", "Basic YWRtaW46VXBvcnRhbF8xMjM=") // .addHeader("Authorization", "Basic YWRtaW46VXBvcnRhbF8xMjM=")
.addHeader("Content-Type", "application/json") // .addHeader("Content-Type", "application/json")
.build(); // .build();
try { // try {
Response response = client.newCall(request).execute(); // Response response = client.newCall(request).execute();
bb.writeLog("response.code():"+response.code()); // bb.writeLog("response.code():"+response.code());
bb.writeLog("response.body():"+response.body().string()); // bb.writeLog("response.body():"+response.body().string());
//
msgData = response.body().string(); // msgData = response.body().string();
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
return msgData; // return msgData;
} // }
} }

@ -41,10 +41,10 @@ public class PortalLoginBeforeFilter implements Filter {
boolean isExcludedPage = false; boolean isExcludedPage = false;
String requestURL = request.getRequestURL().toString(); String requestURL = request.getRequestURL().toString();
bb.writeLog("bpmHostList:" + bpmHostList.size()); //bb.writeLog("bpmHostList:" + bpmHostList.size());
if (!bpmHostList.isEmpty()) { if (!bpmHostList.isEmpty()) {
for (String bpm_host_val : bpmHostList) { for (String bpm_host_val : bpmHostList) {
bb.writeLog("bpm_host_val:" + bpm_host_val); //bb.writeLog("bpm_host_val:" + bpm_host_val);
if (requestURL.contains(bpm_host_val)) { if (requestURL.contains(bpm_host_val)) {
isExcludedPage = true; isExcludedPage = true;
} }
@ -61,7 +61,7 @@ public class PortalLoginBeforeFilter implements Filter {
} }
} }
bb.writeLog("getRequestURI:" + getRequestURI + " isExcludedPage:" + isExcludedPage); //bb.writeLog("getRequestURI:" + getRequestURI + " isExcludedPage:" + isExcludedPage);
if (!isExcludedPage) { if (!isExcludedPage) {
User loginuser = (User) request.getSession(true).getAttribute("weaver_user@bean"); User loginuser = (User) request.getSession(true).getAttribute("weaver_user@bean");
@ -91,7 +91,7 @@ public class PortalLoginBeforeFilter implements Filter {
if (StringUtils.isNotEmpty(uid)) { if (StringUtils.isNotEmpty(uid)) {
String url = bb.getPropValue("PORTAL_INFO", "portal_user_auth"); String url = bb.getPropValue("PORTAL_INFO", "portal_user_auth");
//String url = "http://172.16.25.133/portal-web/user/current" ; //String url = "http://172.16.25.133/portal-web/user/current" ;
bb.writeLog("url:" + url); //bb.writeLog("url:" + url);
HttpRequestUtil HttpRequestUtil = new HttpRequestUtil(); HttpRequestUtil HttpRequestUtil = new HttpRequestUtil();
Map<String, String> headMap = new HashMap<String, String>(); Map<String, String> headMap = new HashMap<String, String>();
@ -111,7 +111,7 @@ public class PortalLoginBeforeFilter implements Filter {
} else { } else {
sql = " select * from HrmResource where loginid =? "; sql = " select * from HrmResource where loginid =? ";
} }
bb.writeLog("sql:" + sql); //bb.writeLog("sql:" + sql);
rs.executeQuery(sql, new Object[]{staffCode}); rs.executeQuery(sql, new Object[]{staffCode});
if (rs.next()) { if (rs.next()) {
user_new = new User(); user_new = new User();
@ -184,7 +184,7 @@ public class PortalLoginBeforeFilter implements Filter {
if (StringUtils.isNotEmpty(uid)) { if (StringUtils.isNotEmpty(uid)) {
String url = bb.getPropValue("PORTAL_INFO", "portal_user_auth"); String url = bb.getPropValue("PORTAL_INFO", "portal_user_auth");
//String url = "http://172.16.25.133/portal-web/user/current" ; //String url = "http://172.16.25.133/portal-web/user/current" ;
bb.writeLog("url:" + url); //bb.writeLog("url:" + url);
HttpRequestUtil HttpRequestUtil = new HttpRequestUtil(); HttpRequestUtil HttpRequestUtil = new HttpRequestUtil();
Map<String, String> headMap = new HashMap<String, String>(); Map<String, String> headMap = new HashMap<String, String>();

@ -133,11 +133,11 @@ public class PortalLoginFilter implements Filter
if(!isExcludedPage) if(!isExcludedPage)
{ {
bb.writeLog("getRequestURI:"+getRequestURI+" isExcludedPage:"+isExcludedPage); //bb.writeLog("getRequestURI:"+getRequestURI+" isExcludedPage:"+isExcludedPage);
User loginuser = (User) request.getSession(true).getAttribute("weaver_user@bean"); User loginuser = (User) request.getSession(true).getAttribute("weaver_user@bean");
if (loginuser == null) if (loginuser == null)
{ {
bb.writeLog("loginuser is null"); //bb.writeLog("loginuser is null");
String uid = "" ; String uid = "" ;
String cookies = request.getHeader("cookie"); String cookies = request.getHeader("cookie");
if(!"".equals(cookies)) if(!"".equals(cookies))
@ -165,7 +165,7 @@ public class PortalLoginFilter implements Filter
if(StringUtils.isNotEmpty(uid)) if(StringUtils.isNotEmpty(uid))
{ {
bb.writeLog("portal_user_auth:"+portal_user_auth); //bb.writeLog("portal_user_auth:"+portal_user_auth);
//String url = "http://172.16.25.133/portal-web/user/current" ; //String url = "http://172.16.25.133/portal-web/user/current" ;
HttpRequestUtil HttpRequestUtil = new HttpRequestUtil(); HttpRequestUtil HttpRequestUtil = new HttpRequestUtil();
Map<String,String> headMap = new HashMap<String,String>(); Map<String,String> headMap = new HashMap<String,String>();
@ -188,7 +188,7 @@ public class PortalLoginFilter implements Filter
}else{ }else{
sql = " select * from HrmResource where loginid =? "; sql = " select * from HrmResource where loginid =? ";
} }
bb.writeLog("sql:"+sql); //bb.writeLog("sql:"+sql);
rs.executeQuery(sql,new Object[]{staffCode}); rs.executeQuery(sql,new Object[]{staffCode});
if(rs.next()){ if(rs.next()){
user_new = new User(); user_new = new User();
@ -271,7 +271,7 @@ public class PortalLoginFilter implements Filter
} }
}else{ }else{
bb.writeLog("uid-- is null"); //bb.writeLog("uid-- is null");
response.setHeader("Access-Control-Allow-Origin", "*"); //解决跨域访问报错 response.setHeader("Access-Control-Allow-Origin", "*"); //解决跨域访问报错
response.setHeader("Access-Control-Allow-Methods", "POST, PUT, GET, OPTIONS, DELETE"); response.setHeader("Access-Control-Allow-Methods", "POST, PUT, GET, OPTIONS, DELETE");
response.setHeader("Access-Control-Max-Age", "3600"); //设置过期时间 response.setHeader("Access-Control-Max-Age", "3600"); //设置过期时间

@ -16,7 +16,7 @@ public class SendMailUtil{
String emailenable = baseBean.getPropValue("PORTAL_INFO","emailenable"); String emailenable = baseBean.getPropValue("PORTAL_INFO","emailenable");
public void sendMail(String requestid,String emails,String notificationSubject,String notificationContent){ public void sendMail(String requestid,String emails,String notificationSubject,String notificationContent){
baseBean.writeLog("emailenable:"+emailenable);
if(!"1".equals(emailenable)){ if(!"1".equals(emailenable)){
return; return;
} }
@ -40,6 +40,7 @@ public class SendMailUtil{
try{ try{
String responseData = doGetAccessToken(); String responseData = doGetAccessToken();
baseBean.writeLog("responseData:"+responseData);
String accessToken = "" ; String accessToken = "" ;
if(StringUtils.isNotEmpty(responseData)){ if(StringUtils.isNotEmpty(responseData)){
JSONObject responseObject = JSONObject.parseObject(responseData); JSONObject responseObject = JSONObject.parseObject(responseData);
@ -63,7 +64,7 @@ public class SendMailUtil{
jsonObject.put("content",requestJson); jsonObject.put("content",requestJson);
// "{\r\n \"access_token\": \"\",\r\n \"method\": \"sendNotification\",\r\n \"version\": \"1.0\",\r\n \"content\": {\"eventCode\":\"\", \r\n \"transId\":\"\", \r\n \"triggerTime\":\"20221020094013\",\r\n \"notificationType\":\"EMAIL\",\r\n \"email\":\"798989044@qq.com\", \r\n \"channel\":\"OA\", \r\n \"notificationSubject\":\"新待办到达\",\r\n \"notificationContent\":\"新待办到达,清及时处理\" }\r\n}" // "{\r\n \"access_token\": \"\",\r\n \"method\": \"sendNotification\",\r\n \"version\": \"1.0\",\r\n \"content\": {\"eventCode\":\"\", \r\n \"transId\":\"\", \r\n \"triggerTime\":\"20221020094013\",\r\n \"notificationType\":\"EMAIL\",\r\n \"email\":\"798989044@qq.com\", \r\n \"channel\":\"OA\", \r\n \"notificationSubject\":\"新待办到达\",\r\n \"notificationContent\":\"新待办到达,清及时处理\" }\r\n}"
System.out.println(jsonObject.toJSONString()); baseBean.writeLog("jsonObject:"+jsonObject.toJSONString());
OkHttpClient client = new OkHttpClient().newBuilder().build(); OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/json"); MediaType mediaType = MediaType.parse("application/json");
@ -111,14 +112,14 @@ public class SendMailUtil{
try { try {
// 生成签名 // 生成签名
String sign = RSAUtils.generateSign("", emainAppCode, emailAppSecret, timestamp, emailPrivateKey); String sign = RSAUtils.generateSign("", emainAppCode, emailAppSecret, timestamp, emailPrivateKey);
// System.out.println("sign == " + sign); baseBean.writeLog("sign == " + sign);
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("appCode",emainAppCode); jsonObject.put("appCode",emainAppCode);
jsonObject.put("appSecret",emailAppSecret); jsonObject.put("appSecret",emailAppSecret);
jsonObject.put("responseType",emailResponseType); jsonObject.put("responseType",emailResponseType);
jsonObject.put("timestamp",timestamp); jsonObject.put("timestamp",timestamp);
jsonObject.put("sign",sign); jsonObject.put("sign",sign);
System.out.println(jsonObject.toJSONString()); baseBean.writeLog("jsonObject:"+jsonObject.toJSONString());
OkHttpClient client = new OkHttpClient().newBuilder().build(); OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/json"); MediaType mediaType = MediaType.parse("application/json");

Loading…
Cancel
Save