사용자를 위해 AsyncContexts를 설정하고이를 사용하여 알림을 푸는 데 문제가 있습니다. 오페라 잠자리 (디버깅에 따라, 그러나Servlet 3.0 : 비동기 응답을 보낼 수 없습니까?
HttpSession userSession = request.getSession();
String userIDString = userSession.getAttribute("id").toString();
String paramAction = request.getParameter("action");
if(paramAction.equals("registerAsynchronousContext"))
{
AsyncContext userAsyncContext = request.startAsync();
HashMap<String, AsyncContext> userAsynchronousContextHashMap = (HashMap<String, AsyncContext>)getServletContext().getAttribute("userAsynchronousContextHashMap");
userAsynchronousContextHashMap.put(userIDString, userAsyncContext);
getServletContext().setAttribute("userAsynchronousContextHashMap", userAsynchronousContextHashMap);
System.out.println("Put asynchronous request in global map");
}
//userAsynchronousContextHashMap is created by a ContextListener on the start of the web-app
:
$.post("TestServlet",{
action: "registerAsynchronousContext"
},function(data, textStatus, jqXHR){
alert("Server received async request"); //Placed here for debugging
}, "json");
그리고 "TestServlet"에
나는 이것을 doPost 메소드의 코드를 가지고 : 페이지로드에 나는 요청을 보낼 수있는 몇 가지 jQuery 코드를 Firebug와 같은 도구), 요청이 전송 된 후 서버가 약 30000ms의 HTTP 500 응답을 보내는 것처럼 보입니다.userAsyncContext.getResponse(). getWriter(). print (SOME_JSON)로 생성되고 HTTP 500 응답 이전에 전송 된 응답은 브라우저에서 수신되지 않으며 이유를 알지 못합니다. AsyncContext를 처리하는 "if"문에있는 모든 코드가없는 경우에만 일반 응답 객체를 사용하여 응답 (response.print (SOME_JSON))을 브라우저에 수신합니다.
누군가 나를 도울 수 있습니까? 이 비동기 API 작동 방식에 대한 오해로 인한 느낌이 들었습니다. 나는이 AsyncContext를 글로벌 맵에 저장 한 다음 검색하여 클라이언트에 응답 객체를 사용하여 클라이언트에 푸시 할 수 있다고 생각했습니다. 그러나 AsyncContext가 클라이언트에 다시 쓸 수있는 것처럼 보이지는 않습니다.
도움이 필요합니다.