1
0
mirror of https://github.com/chatopera/cosin.git synced 2025-06-25 02:47:10 +08:00

#589 optimize wss port

This commit is contained in:
Yu 2022-01-28 16:07:40 +08:00
parent 9234b670d4
commit 8d23de5881
2 changed files with 104 additions and 90 deletions

View File

@ -513,4 +513,13 @@ public class Handler {
return fileid;
}
public String getSchema(HttpServletRequest request) {
String schema = request.getScheme();
String headerProto = request.getHeader("X-Forwarded-Proto");
if (StringUtils.isNotBlank(headerProto)) {
schema = headerProto;
}
return schema;
}
}

View File

@ -170,11 +170,7 @@ public class IMController extends Handler {
view.addObject("port", request.getServerPort());
}
} else {
view.addObject("schema", request.getScheme());
String header = request.getHeader("X-Forwarded-Proto");
if (header != null) {
view.addObject("schema", header);
}
view.addObject("schema", super.getSchema(request));
view.addObject("port", request.getServerPort());
}
@ -230,11 +226,7 @@ public class IMController extends Handler {
view.addObject("port", request.getServerPort());
}
} else {
view.addObject("schema", request.getScheme());
String header = request.getHeader("X-Forwarded-Proto");
if (header != null) {
view.addObject("schema", header);
}
view.addObject("schema", super.getSchema(request));
view.addObject("port", request.getServerPort());
}
@ -329,31 +321,29 @@ public class IMController extends Handler {
/**
* 广告信息
*/
List<AdType> ads = MainUtils.getPointAdvs(MainContext.AdPosEnum.POINT.toString(), invite.getConsult_skill_fixed_id(), Constants.SYSTEM_ORGI);
List<AdType> ads = MainUtils.getPointAdvs(MainContext.AdPosEnum.POINT.toString(),
invite.getConsult_skill_fixed_id(), Constants.SYSTEM_ORGI);
if (ads.size() > 0) {
view.addObject(
"pointAds",
ads
);
ads);
view.addObject(
"pointAd",
MainUtils.weitht(ads)
);
MainUtils.weitht(ads));
} else {
view.addObject(
"pointAds",
null
);
null);
view.addObject(
"pointAd",
null
);
null);
}
view.addObject(
"inviteAd",
MainUtils.getPointAdv(MainContext.AdPosEnum.INVITE.toString(), invite.getConsult_skill_fixed_id(), Constants.SYSTEM_ORGI));
MainUtils.getPointAdv(MainContext.AdPosEnum.INVITE.toString(),
invite.getConsult_skill_fixed_id(), Constants.SYSTEM_ORGI));
} else {
logger.info("[point] invite id {}, orgi {} not found", id, Constants.SYSTEM_ORGI);
}
@ -449,10 +439,10 @@ public class IMController extends Handler {
return "ok";
}
@RequestMapping("/{id}/userlist")
@Menu(type = "im", subtype = "inlist", access = true)
public void inlist(HttpServletRequest request, HttpServletResponse response, @PathVariable String id, @Valid String userid) throws IOException {
public void inlist(HttpServletRequest request, HttpServletResponse response, @PathVariable String id,
@Valid String userid) throws IOException {
response.setHeader("Content-Type", "text/html;charset=utf-8");
if (StringUtils.isNotBlank(userid)) {
BlackEntity black = cache.findOneSystemByIdAndOrgi(userid, Constants.SYSTEM_ORGI);
@ -488,7 +478,8 @@ public class IMController extends Handler {
final @Valid String title,
final @Valid String traceid) throws InterruptedException {
// logger.info(
// "[online] user {}, orgi {}, traceid {}, appid {}, session {}", userid, orgi, traceid, appid, sessionid);
// "[online] user {}, orgi {}, traceid {}, appid {}, session {}", userid, orgi,
// traceid, appid, sessionid);
Optional<BlackEntity> blackOpt = cache.findOneBlackEntityByUserIdAndOrgi(userid, orgi);
if (blackOpt.isPresent() && (blackOpt.get().getEndtime() == null || blackOpt.get().getEndtime().after(
new Date()))) {
@ -527,12 +518,14 @@ public class IMController extends Handler {
// TODO 该contacts的识别并不准确因为不能关联
// if (invite != null && invite.isTraceuser()) {
// contacts = OnlineUserProxy.OnlineUserProxy.processContacts(orgi, contacts, appid, userid);
// contacts = OnlineUserProxy.OnlineUserProxy.processContacts(orgi, contacts,
// appid, userid);
// }
//
// if (StringUtils.isNotBlank(sign)) {
// OnlineUserProxy.online(
// super.getIMUser(request, sign, contacts != null ? contacts.getName() : null, sessionid),
// super.getIMUser(request, sign, contacts != null ? contacts.getName() : null,
// sessionid),
// orgi,
// sessionid,
// MainContext.OnlineUserType.WEBIM.toString(),
@ -647,7 +640,9 @@ public class IMController extends Handler {
Optional<BlackEntity> blackOpt = cache.findOneBlackEntityByUserIdAndOrgi(userid, Constants.SYSTEM_ORGI);
CousultInvite invite = OnlineUserProxy.consult(appid, orgi);
if (StringUtils.isNotBlank(
appid) && ((!blackOpt.isPresent()) || (blackOpt.get().getEndtime() != null && blackOpt.get().getEndtime().before(
appid)
&& ((!blackOpt.isPresent())
|| (blackOpt.get().getEndtime() != null && blackOpt.get().getEndtime().before(
new Date())))) {
String randomUserId; // 随机生成OnlineUser的用户名使用了浏览器指纹做唯一性KEY
@ -680,7 +675,11 @@ public class IMController extends Handler {
map.addAttribute("sessionConfig", sessionConfig);
map.addAttribute("hostname", request.getServerName());
if (sslPort != null) {
String schema = super.getSchema(request);
if (StringUtils.equals(schema, "https")) {
map.addAttribute("port", 443);
} else if (sslPort != null) {
map.addAttribute("port", sslPort);
} else {
map.addAttribute("port", port);
@ -688,11 +687,10 @@ public class IMController extends Handler {
map.addAttribute("appid", appid);
map.addAttribute("userid", userid);
map.addAttribute("schema", request.getScheme());
map.addAttribute("schema", schema);
map.addAttribute("sessionid", sessionid);
map.addAttribute("isInvite", isInvite);
view.addObject("product", product);
view.addObject("description", description);
view.addObject("imgurl", imgurl);
@ -754,7 +752,8 @@ public class IMController extends Handler {
} else if (invite.isConsult_info()) { // 启用了信息收集从Request获取 或从 Cookies 里去
// 验证 OnlineUser 信息
if (contacts != null && StringUtils.isNotBlank(
contacts.getName())) { //contacts用于传递信息并不和 联系人表发生 关联contacts信息传递给 Socket.IO然后赋值给 AgentUser最终赋值给 AgentService永久存储
contacts.getName())) { // contacts用于传递信息并不和 联系人表发生 关联contacts信息传递给 Socket.IO然后赋值给
// AgentUser最终赋值给 AgentService永久存储
consult = true;
// 存入 Cookies
if (invite.isConsult_info_cookies()) {
@ -783,7 +782,6 @@ public class IMController extends Handler {
response.addCookie(skypeid);
}
if (StringUtils.isNotBlank(contacts.getMemo())) {
Cookie memo = new Cookie(
"memo", MainUtils.encryption(URLEncoder.encode(contacts.getName(), "UTF-8")));
@ -837,7 +835,8 @@ public class IMController extends Handler {
}
} else {
// TODO 该contacts的识别并不准确因为不能关联
// contacts = OnlineUserProxy.processContacts(invite.getOrgi(), contacts, appid, userid);
// contacts = OnlineUserProxy.processContacts(invite.getOrgi(), contacts, appid,
// userid);
String uid = (String) request.getSession().getAttribute("Sessionuid");
String sid = (String) request.getSession().getAttribute("Sessionsid");
String cid = (String) request.getSession().getAttribute("Sessioncid");
@ -856,7 +855,8 @@ public class IMController extends Handler {
// 关联AgentUserContact的联系人
// NOTE: 如果该userid已经有了关联的Contact则忽略继续使用之前的
Optional<AgentUserContacts> agentUserContactsOpt = agentUserContactsRes.findOneByUseridAndOrgi(
Optional<AgentUserContacts> agentUserContactsOpt = agentUserContactsRes
.findOneByUseridAndOrgi(
userid, orgi);
if (!agentUserContactsOpt.isPresent()) {
AgentUserContacts agentUserContacts = new AgentUserContacts();
@ -935,7 +935,6 @@ public class IMController extends Handler {
chatbotConfig.put("botfirst", Boolean.toString(invite.isAifirst()));
chatbotConfig.put("isai", Boolean.toString(invite.isAi()));
if (chatbotConfig != null) {
map.addAttribute("chatbotConfig", chatbotConfig);
}
@ -961,8 +960,10 @@ public class IMController extends Handler {
}
view.addObject("commentList", Dict.getInstance().getDic(Constants.CSKEFU_SYSTEM_COMMENT_DIC));
view.addObject("commentItemList", Dict.getInstance().getDic(Constants.CSKEFU_SYSTEM_COMMENT_ITEM_DIC));
view.addObject("welcomeAd", MainUtils.getPointAdv(MainContext.AdPosEnum.WELCOME.toString(), skill, orgi));
view.addObject("figureAds", MainUtils.getPointAdvs(MainContext.AdPosEnum.IMAGE.toString(), skill, orgi));
view.addObject("welcomeAd",
MainUtils.getPointAdv(MainContext.AdPosEnum.WELCOME.toString(), skill, orgi));
view.addObject("figureAds",
MainUtils.getPointAdvs(MainContext.AdPosEnum.IMAGE.toString(), skill, orgi));
// 确定"接受邀请"被处理后通知浏览器关闭弹出窗口
OnlineUserProxy.sendWebIMClients(userid, "accept");
@ -1028,7 +1029,7 @@ public class IMController extends Handler {
view.addObject("hostname", request.getServerName());
view.addObject("port", request.getServerPort());
view.addObject("schema", request.getScheme());
view.addObject("schema", super.getSchema(request));
view.addObject("appid", appid);
view.addObject("channelVisitorSeparate", channelWebIMVisitorSeparate);
view.addObject("ip", MainUtils.md5(request.getRemoteAddr()));
@ -1127,7 +1128,7 @@ public class IMController extends Handler {
params.put("hostname", request.getServerName());
params.put("port", request.getServerPort());
params.put("schema", request.getScheme());
params.put("schema", super.getSchema(request));
params.put("appid", appid);
params.put("channelVisitorSeparate", channelWebIMVisitorSeparate);
params.put("ip", MainUtils.md5(request.getRemoteAddr()));
@ -1200,7 +1201,8 @@ public class IMController extends Handler {
snsAccountRepository.findBySnsid(appid).ifPresent(p -> {
CousultInvite invite = inviteRepository.findBySnsaccountidAndOrgi(appid, Constants.SYSTEM_ORGI);
// TODO 增加策略防止恶意刷消息
// List<LeaveMsg> msgList = leaveMsgRes.findByOrgiAndUserid(invite.getOrgi(), msg.getUserid());
// List<LeaveMsg> msgList = leaveMsgRes.findByOrgiAndUserid(invite.getOrgi(),
// msg.getUserid());
// if(msg!=null && msgList.size() == 0){
if (msg != null) {
msg.setOrgi(invite.getOrgi());
@ -1216,7 +1218,8 @@ public class IMController extends Handler {
@RequestMapping("/refuse")
@Menu(type = "im", subtype = "refuse", access = true)
public void refuse(HttpServletRequest request, HttpServletResponse response, @Valid String orgi, @Valid String appid, @Valid String userid, @Valid String sessionid, @Valid String client) throws Exception {
public void refuse(HttpServletRequest request, HttpServletResponse response, @Valid String orgi,
@Valid String appid, @Valid String userid, @Valid String sessionid, @Valid String client) throws Exception {
OnlineUserProxy.refuseInvite(userid, orgi);
final Date threshold = new Date(System.currentTimeMillis() - Constants.WEBIM_AGENT_INVITE_TIMEOUT);
Page<InviteRecord> inviteRecords = inviteRecordRes.findByUseridAndOrgiAndResultAndCreatetimeGreaterThan(
@ -1241,7 +1244,8 @@ public class IMController extends Handler {
@RequestMapping("/satis")
@Menu(type = "im", subtype = "satis", access = true)
public void satis(HttpServletRequest request, HttpServletResponse response, @Valid AgentServiceSatis satis) throws Exception {
public void satis(HttpServletRequest request, HttpServletResponse response, @Valid AgentServiceSatis satis)
throws Exception {
if (satis != null && StringUtils.isNotBlank(satis.getId())) {
int count = agentServiceSatisRes.countById(satis.getId());
if (count == 1) {
@ -1274,15 +1278,18 @@ public class IMController extends Handler {
HttpHeaders headers = RestUtils.header();
// String multipartLast = null;
// if ( multipart != null && multipart.getOriginalFilename() != null ){
// Number multipartLenght = multipart.getOriginalFilename().split("\\.").length - 1;
// multipartLast = multipart.getOriginalFilename().split("\\.")[ multipartLenght.intValue()];
// Number multipartLenght = multipart.getOriginalFilename().split("\\.").length
// - 1;
// multipartLast = multipart.getOriginalFilename().split("\\.")[
// multipartLenght.intValue()];
// }
// if (multipart != null &&
// multipartLast != null
// && multipart.getOriginalFilename().lastIndexOf(".") > 0
// && StringUtils.isNotBlank(userid)) {
// if( multipartLast.equals("jpeg") || multipartLast.equals("jpg") || multipartLast.equals("bmp")
// if( multipartLast.equals("jpeg") || multipartLast.equals("jpg") ||
// multipartLast.equals("bmp")
// || multipartLast.equals("png") ){
if (multipart != null
&& multipart.getOriginalFilename().lastIndexOf(".") > 0
@ -1292,7 +1299,6 @@ public class IMController extends Handler {
uploadDir.mkdirs();
}
String fileid = MainUtils.getUUID();
StreamingFile sf = new StreamingFile();
sf.setId(fileid);
@ -1375,7 +1381,6 @@ public class IMController extends Handler {
return new ResponseEntity<>(result.toString(), headers, HttpStatus.OK);
}
private String processAttachmentFile(
final MultipartFile file,
final String fileid,