diff --git a/src/tinystruct/examples/smalltalk.java b/src/tinystruct/examples/smalltalk.java index 65b81b0..daaa3a6 100644 --- a/src/tinystruct/examples/smalltalk.java +++ b/src/tinystruct/examples/smalltalk.java @@ -211,20 +211,18 @@ public String update() throws ApplicationException, IOException { } public String update(String meetingCode, String sessionId) throws ApplicationException, IOException { + String error = "{ \"error\": \"expired\" }"; if (this.meetings.containsKey(meetingCode)) { if(sessions.get(meetingCode) != null && sessions.get(meetingCode).contains(sessionId)) { return this.update(sessionId); } - final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE"); - response.setContentType("application/json"); - response.setStatus(403); - return "{ \"error\": \"session-timeout\" }"; + error = "{ \"error\": \"session-timeout\" }"; } - + final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE"); response.setContentType("application/json"); response.setStatus(403); - return "{ \"error\": \"expired\" }"; + return error; } public String upload() throws ApplicationException { @@ -329,19 +327,19 @@ public void sessionDestroyed(HttpSessionEvent arg0) { builder.put("time", format.format(new Date())); builder.put("cmd", "expired"); this.save(meetingCode, builder); - + Queue messages; List session_ids; - synchronized (meetings) { + synchronized (this.meetings) { if((session_ids = this.sessions.get(meetingCode)) != null) { session_ids.remove(arg0.getSession().getId()); } - - if ((messages = meetings.get(meetingCode)) != null) { + + if ((messages = this.meetings.get(meetingCode)) != null) { messages.remove(meetingCode); } - - meetings.notifyAll(); + + this.meetings.notifyAll(); } synchronized (this.list) { diff --git a/src/tinystruct/examples/talk.java b/src/tinystruct/examples/talk.java index 61b607e..6897252 100644 --- a/src/tinystruct/examples/talk.java +++ b/src/tinystruct/examples/talk.java @@ -125,11 +125,11 @@ public void run() { * @throws IOException */ public final String update(final String sessionId) throws ApplicationException, IOException { - Builder message; + Builder message = null; Queue messages; synchronized (this.list) { messages = this.list.get(sessionId); - while((message = messages.poll()) == null) { + while(messages != null && (message = messages.poll()) == null) { try { this.list.wait(TIMEOUT); } catch (InterruptedException e) { @@ -137,7 +137,7 @@ public final String update(final String sessionId) throws ApplicationException, } } - return message.toString(); + return message != null ? message.toString() : ""; } }