Привет, я использую интеграцию Spring Spring с веб-сокетом Spring без использования Stomp.Я могу сохранить весеннюю сессию в базе данных mysql. Но я не могу получить сессию websocket из весенней сессии.Пожалуйста, помогите, я прикрепляю свой пользовательский обработчик.
public class WsoHandshakeInterceptor extends HttpSessionHandshakeInterceptor {
WsiService wsiService ;
private static Logger logger = LogManager.getLogger(WsoHandshakeInterceptor.class);
/**
* @return the wsiService
*/
public WsiService getWsiService() {
return wsiService;
}
/**
* @param wsiService the wsiService to set
*/
public void setWsiService(WsiService wsiService) {
this.wsiService = wsiService;
}
@Override
public boolean beforeHandshake(ServerHttpRequest servletRequest, ServerHttpResponse servletResponse, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
System.out.println("before handshake");
ParamDto paramDto= new ParamDto();
paramDto.setParamGrp("IPI");
paramDto.setParamKey("CONNECTIONS");
String allowedConnections=wsiService.getGparamValue(paramDto);
CbwsoReqStatDto reDto=new CbwsoReqStatDto();
if (servletRequest instanceof ServletServerHttpRequest) {
HttpServletRequest request=((ServletServerHttpRequest) servletRequest).getServletRequest();
HttpServletResponse response = ((ServletServerHttpResponse) servletResponse).getServletResponse();
String decryptedData="";
String eid = request.getParameter("eid");
String connReqParam=request.getParameter("entityDetails");
// String wsoRefNo= wsiService.getWsoRefNo();
EntityDetails entityDetail= new EntityDetails();
Timestamp requestTime = CbwsiCommonUtils.getCurrentDate();
reDto.setWsoRefNo("");
reDto.setRequester_Id(eid);
reDto.setReciever_Id("001");
reDto.setRequestData(connReqParam);
reDto.setRequesterRefNo("");
reDto.setRequestType("C");
reDto.setRequestUrl(request.getRequestURL().toString());
reDto.setRequsetTime(requestTime);
reDto.setRequester_IP(request.getRemoteAddr());
reDto.setDecryptedRequest("");
// wsiService.insertWsoRequest(reDto);
try{
String wsoRefNo= wsiService.insertNewWsoRequest(reDto);
int dupConReq=wsiService.getDupConnectionReq(reDto);
//if (dupConReq==0){
if(!CbwsiCommonUtils.isEmpty(eid) && !CbwsiCommonUtils.isEmpty(connReqParam)){
logger.info("**"+eid+"**"+" ****************New Connection Request*****************");
try {
decryptedData=wsiService.getWsoReqParamDecrypted(request);
} catch (JAXBException e) {
logger.info(" **eid** "+" ****************New Connection Request Exception*****************");
logger.info(" **eid** "+CbwsiCommonUtils.stackTraceToString(e));
// TODO Auto-generated catch block
reDto=new CbwsoReqStatDto();
reDto.setWsoRefNo(wsoRefNo);
reDto.setRequestStatus("N");
reDto.setRequestStatusMsg(e.getMessage());
wsiService.updateWsoRequest(reDto);
reDto=new CbwsoReqStatDto();
reDto.setWsoRefNo(wsoRefNo);
reDto.setRequester_IP(request.getRemoteAddr());
reDto.setRequestUrl(request.getRequestURL().toString());
reDto.setRequestData(connReqParam);
reDto.setRequsetTime(requestTime);
reDto.setRequestStatus("N");
reDto.setFailureReason(CbwsiCommonUtils.stackTraceToString(e));
wsiService.saveBadRequest(reDto);
return false;
} catch (Exception e) {
logger.info("**"+eid+"**"+" ****************New Connection Request Exception*****************");
logger.info("**"+eid+"**"+CbwsiCommonUtils.stackTraceToString(e));
// TODO Auto-generated catch block
reDto=new CbwsoReqStatDto();
reDto.setWsoRefNo(wsoRefNo);
reDto.setRequestStatus("N");
reDto.setRequestStatusMsg(e.getMessage());
wsiService.updateWsoRequest(reDto);
reDto=new CbwsoReqStatDto();
reDto.setWsoRefNo(wsoRefNo);
reDto.setRequester_IP(request.getRemoteAddr());
reDto.setRequestUrl(request.getRequestURL().toString());
reDto.setRequestData(connReqParam);
reDto.setRequsetTime(requestTime);
reDto.setRequestStatus("N");
reDto.setFailureReason(CbwsiCommonUtils.stackTraceToString(e));
wsiService.saveBadRequest(reDto);
return false;
}
if(decryptedData != null && decryptedData.trim().length() > 0){
try {
entityDetail=(EntityDetails)CbwsiCommonUtils.getDataFromRequest(decryptedData, "application/json", entityDetail);
} catch (JAXBException e) {
logger.info("**"+eid+"**"+" ****************New Connection Request Exception*****************");
logger.info("**"+eid+"**"+CbwsiCommonUtils.stackTraceToString(e));
// TODO Auto-generated catch block
reDto=new CbwsoReqStatDto();
reDto.setWsoRefNo(wsoRefNo);
reDto.setRequestStatus("N");
reDto.setRequestStatusMsg(e.getMessage());
wsiService.updateWsoRequest(reDto);
reDto=new CbwsoReqStatDto();
reDto.setWsoRefNo(wsoRefNo);
reDto.setRequester_IP(request.getRemoteAddr());
reDto.setRequestUrl(request.getRequestURL().toString());
reDto.setRequestData(connReqParam);
reDto.setRequsetTime(requestTime);
reDto.setRequestStatus("N");
reDto.setFailureReason(CbwsiCommonUtils.stackTraceToString(e));
wsiService.saveBadRequest(reDto);
return false;
} catch (Exception e) {
logger.info("**"+eid+"**"+" ****************New Connection Request Exception*****************");
logger.info("**"+eid+"**"+CbwsiCommonUtils.stackTraceToString(e));
// TODO Auto-generated catch block
reDto=new CbwsoReqStatDto();
reDto.setWsoRefNo(wsoRefNo);
reDto.setRequestStatus("N");
reDto.setRequestStatusMsg(e.getMessage());
wsiService.updateWsoRequest(reDto);
reDto=new CbwsoReqStatDto();
reDto.setWsoRefNo(wsoRefNo);
reDto.setRequester_IP(request.getRemoteAddr());
reDto.setRequestUrl(request.getRequestURL().toString());
reDto.setRequestData(connReqParam);
reDto.setRequsetTime(requestTime);
reDto.setRequestStatus("N");
reDto.setFailureReason(CbwsiCommonUtils.stackTraceToString(e));
wsiService.saveBadRequest(reDto);
return false;
}
}
if(entityDetail.getBankId().equalsIgnoreCase(eid)){
try {
String validateRequesterRefferenceNumber=wsiService.validateReqRefNo(entityDetail.getRequesterWsoRef(),entityDetail.getBankId());
if(validateRequesterRefferenceNumber.equalsIgnoreCase("valid")){
if(wsiService.authenticateRequest( entityDetail.getBankId(), entityDetail.getUserName(), entityDetail.getPassword())){
int activeConnections=wsiService.getActiveConnectionsCount( entityDetail.getBankId());
if (allowedConnections!=null && activeConnections <=Integer.parseInt(allowedConnections) ){
if (wsiService.verifyEntitySignature(entityDetail)){
String clientIp= request.getRemoteAddr();
attributes.put("IP_ADDRESS", clientIp);
attributes.put("EID", eid);
attributes.put("WSIREFNO", wsoRefNo);
attributes.put("REQUEST_URL", request.getRequestURL().toString());
attributes.put("HTTP_SESSION", request.getSession());
attributes.put("HTTP_REQUEST",request);
reDto=new CbwsoReqStatDto();
reDto.setWsoRefNo(wsoRefNo);
reDto.setRequestStatus("A");
reDto.setRequestStatusMsg("Connected");
reDto.setRequesterRefNo(entityDetail.getRequesterWsoRef());
reDto.setDecryptedRequest(decryptedData);
wsiService.updateWsoRequest(reDto);
return true;
}
else{
logger.info("**"+eid+"**"+" ****************New Connection Request Exception : Signature Invalid.*****************");
reDto=new CbwsoReqStatDto();
reDto.setWsoRefNo(wsoRefNo);
reDto.setRequestStatus("N");
reDto.setRequesterRefNo(entityDetail.getRequesterWsoRef());
reDto.setDecryptedRequest(decryptedData);
reDto.setRequestStatusMsg("Signature Invalid");
wsiService.updateWsoRequest(reDto);
return false;
}
}
else{
logger.info("**"+eid+"**"+" ****************New Connection Request Exception : Connection Exceeded Allowed Connections.*****************");
reDto=new CbwsoReqStatDto();
reDto.setWsoRefNo(wsoRefNo);
reDto.setRequestStatus("N");
reDto.setRequesterRefNo(entityDetail.getRequesterWsoRef());
reDto.setDecryptedRequest(decryptedData);
reDto.setRequestStatusMsg("Connection Exceeded Allowed Connections.");
wsiService.updateWsoRequest(reDto);
return false;
}
}
else{
logger.info("**"+eid+"**"+" ****************New Connection Request Exception : Authentication Failed*****************");
reDto=new CbwsoReqStatDto();
reDto.setWsoRefNo(wsoRefNo);
reDto.setRequestStatus("N");
reDto.setRequesterRefNo(entityDetail.getRequesterWsoRef());
reDto.setDecryptedRequest(decryptedData);
reDto.setRequestStatusMsg("Authentication Failed");
wsiService.updateWsoRequest(reDto);
return false;
}
}
else{
logger.info("**"+eid+"**"+" ****************New Connection Request Exception :"+ validateRequesterRefferenceNumber+"*****************");
reDto=new CbwsoReqStatDto();
reDto.setWsoRefNo(wsoRefNo);
reDto.setRequestStatus("N");
reDto.setRequesterRefNo(entityDetail.getRequesterWsoRef());
reDto.setDecryptedRequest(decryptedData);
reDto.setRequestStatusMsg(validateRequesterRefferenceNumber);
wsiService.updateWsoRequest(reDto);
return false;
}
} catch (Exception e) {
// TODO Auto-generated catch block
logger.info("**"+eid+"**"+" ****************New Connection Request Exception*****************");
logger.info("**"+eid+"**"+CbwsiCommonUtils.stackTraceToString(e));
reDto=new CbwsoReqStatDto();
reDto.setWsoRefNo(wsoRefNo);
reDto.setRequestStatus("N");
reDto.setRequesterRefNo(entityDetail.getRequesterWsoRef());
reDto.setDecryptedRequest(decryptedData);
reDto.setRequestStatusMsg(e.getMessage());
wsiService.updateWsoRequest(reDto);
reDto=new CbwsoReqStatDto();
reDto.setWsoRefNo(wsoRefNo);
reDto.setRequester_IP(request.getRemoteAddr());
reDto.setRequestUrl(request.getRequestURL().toString());
reDto.setRequestData(connReqParam);
reDto.setRequsetTime(requestTime);
reDto.setRequestStatus("N");
reDto.setFailureReason(CbwsiCommonUtils.stackTraceToString(e));
wsiService.saveBadRequest(reDto);
return false;
}
}
else{
logger.info("**"+eid+"**"+" ****************New Connection Request Exception : Invalid Requester*****************");
reDto=new CbwsoReqStatDto();
reDto.setWsoRefNo(wsoRefNo);
reDto.setRequestStatus("N");
reDto.setRequesterRefNo(entityDetail.getRequesterWsoRef());
reDto.setDecryptedRequest(decryptedData);
reDto.setRequestStatusMsg("Invalid Requester");
wsiService.updateWsoRequest(reDto);
return false;
}
/* }
else{
reDto=new CbwsoReqStatDto();
reDto.setWsoRefNo(wsoRefNo);
reDto.setRequestStatus("N");
reDto.setRequestStatusMsg("Duplicate Data Forwarded");
wsiService.updateWsoRequest(reDto);
return false;
}*/
}
else{
logger.info("**"+eid+"**"+" ****************New Connection Request Exception : Request parameters are empty*****************");
reDto=new CbwsoReqStatDto();
reDto.setWsoRefNo(wsoRefNo);
reDto.setRequestStatus("N");
reDto.setRequesterRefNo("");
reDto.setDecryptedRequest(decryptedData);
reDto.setRequestStatusMsg("Request parameters are empty");
wsiService.updateWsoRequest(reDto);
reDto=new CbwsoReqStatDto();
reDto.setWsoRefNo(wsoRefNo);
reDto.setRequester_IP(request.getRemoteAddr());
reDto.setRequestUrl(request.getRequestURL().toString());
reDto.setRequestData("");
reDto.setRequsetTime(requestTime);
reDto.setRequestStatus("N");
reDto.setFailureReason("Request parameters are empty");
wsiService.saveBadRequest(reDto);
return false;
}
}
catch (Exception e) {
logger.info("**"+eid+"** "+" ****************New Connection Request Exception*****************");
logger.info("**"+eid+"** "+CbwsiCommonUtils.stackTraceToString(e));
}
}
return false;
}
@Override
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception ex) {
System.out.println("after handshake");
}
}
Это пользовательское рукопожатие, которое я реализую.Но как передать весеннюю сессию моему обработчику веб-сокетов.
С уважением, Джасир