您好我目前正在使用restcomm-sip-servlets-4.0.75-apache-tomcat-8.0.26。我有问题从http请求线程取消正在进行的请求。我注意到,当我使用auth标头创建一个新请求时,似乎只会发生此问题:
AuthInfo authInfo = sipFactory.createAuthInfo();
authInfo.addAuthInfo(
response.getStatus(),
realm,myauth,password);
SipServletRequest challengeRequest = response.getSession().createRequest(
response.getRequest().getMethod());
(String)session.getAttribute("FirstPartyContent");
if(session.getAttribute("FirstPartyContent") !=null){
challengeRequest.setContent(session.getAttribute("FirstPartyContent"),(String) session.getAttribute("FirstPartyContentType"));
}
challengeRequest.addAuthHeader(response, authInfo);
challengeRequest.getFrom().setDisplayName(auth.getDisplayName());
session.removeAttribute("original");
session.setAttribute("original", challengeRequest);
challengeRequest.send();
当请求通过http接口进入时,我会像这样查找SipApplicationSession:
SipSessionsUtil sipSessionsUtil =
(SipSessionsUtil) session.getServletContext().
getAttribute("javax.servlet.sip.SipSessionsUtil");
logger.info("found servlet contxt for sipsession util");
SipApplicationSession tobecancelledsess = sipSessionsUtil.getApplicationSessionById(sessionapplicationID);
然后我从会话请求中创建一个取消请求,如下所示:
SipServletRequest req =(SipServletRequest)tobecancelledsess.getAttribute(“original”); drequest = req.createCancel();
虽然远程服务器使用to-tag响应临时,但我得到:
2017-04-28 16:26:04,470 DEBUG [SipServletMessageImpl](http-bio-8443-exec-1)事务null transactionId = null transactionType false 2017-04-28 16:26:04,470 DEBUG [SipServletMessageImpl](http-bio-8443-exec-1)事务null transactionId = null transactionType false java.lang.IllegalStateException:找不到客户端事务!空值 在org.mobicents.servlet.sip.message.SipServletRequestImpl.createCancel(SipServletRequestImpl.java:258) 在org.example.servlet.sip.CallContainer.CancelSession(CallContainer.java:319) 在org.example.servlet.sip.CallContainer.CheckCancel(CallContainer.java:274) at org.example.servlet.sip.SimpleWebServlet.doPut(SimpleWebServlet.java:360) at org.example.servlet.sip.SimpleWebServlet.service(SimpleWebServlet.java:149) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:729) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 在org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) 在org.mobicents.servlet.sip.startup.SipStandardContextValve.invoke(SipStandardContextValve.java:262) 在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) 在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) 在org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) 在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) 在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) 在org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:673) at org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:279) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61) 在java.lang.Thread.run(Thread.java:745)
我注意到当我从servlet类中取消请求时,我没有这个问题。
答案 0 :(得分:1)
我发现在这样的响应中设置上下文属性可以解决我的问题:
if (resp.getStatus() == SipServletResponse.SC_RINGING){
SipSession session = resp.getSession();
resp.getSession().getServletContext().setAttribute("ringing",true);
}
然后我抓住像这样的会话上下文
SipServletRequest req = (SipServletRequest)tobecancelledsess.getAttribute("original");
Boolean ringed = (Boolean ) tobecancelledsess.getServletContext().getAttribute("ringing");
if(ringed == Boolean.True)
drequest = req.createCancel();
最终您需要使用send();
发送取消请求