Skip to content

Commit ad90596

Browse files
authored
Update smalltalk.java
1 parent 8cce8b8 commit ad90596

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

src/tinystruct/examples/smalltalk.java

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public String command() {
163163

164164
return this.save(meetingCode, builder);
165165
}
166-
166+
response.setStatus(403);
167167
return "{ \"error\": \"expired\" }";
168168
}
169169

@@ -192,7 +192,9 @@ public String save() {
192192
}
193193
}
194194
}
195-
return "{}";
195+
196+
response.setStatus(403);
197+
return "{ \"error\": \"expired\" }";
196198
}
197199

198200
public String update() throws ApplicationException, IOException {
@@ -202,14 +204,27 @@ public String update() throws ApplicationException, IOException {
202204
if (meetingCode != null) {
203205
return this.update(meetingCode.toString(), sessionId);
204206
}
205-
return "";
207+
final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE");
208+
response.setContentType("application/json");
209+
response.setStatus(403);
210+
return "{ \"error\": \"expired\" }";
206211
}
207212

208213
public String update(String meetingCode, String sessionId) throws ApplicationException, IOException {
209-
if (this.meetings.containsKey(meetingCode) && sessions.get(meetingCode) != null && sessions.get(meetingCode).contains(sessionId)) {
210-
return this.update(sessionId);
214+
if (this.meetings.containsKey(meetingCode)) {
215+
if(sessions.get(meetingCode) != null && sessions.get(meetingCode).contains(sessionId)) {
216+
return this.update(sessionId);
217+
}
218+
final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE");
219+
response.setContentType("application/json");
220+
response.setStatus(403);
221+
return "{ \"error\": \"session-timeout\" }";
211222
}
212-
return "";
223+
224+
final HttpServletResponse response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE");
225+
response.setContentType("application/json");
226+
response.setStatus(403);
227+
return "{ \"error\": \"expired\" }";
213228
}
214229

215230
public String upload() throws ApplicationException {
@@ -308,16 +323,24 @@ public void sessionCreated(HttpSessionEvent arg0) {
308323
public void sessionDestroyed(HttpSessionEvent arg0) {
309324
Object meetingCode = arg0.getSession().getAttribute("meeting_code");
310325
if ( meetingCode != null ) {
326+
final SimpleDateFormat format = new SimpleDateFormat("yyyy-M-d h:m:s");
327+
final Builder builder = new Builder();
328+
builder.put("user", null);
329+
builder.put("time", format.format(new Date()));
330+
builder.put("cmd", "expired");
331+
this.save(meetingCode, builder);
332+
311333
Queue<Builder> messages;
312334
List<String> session_ids;
313-
synchronized (meetings) {
314-
if((session_ids = this.sessions.get(meetingCode)) != null)
315-
{
335+
synchronized (meetings) {
336+
if((session_ids = this.sessions.get(meetingCode)) != null) {
316337
session_ids.remove(arg0.getSession().getId());
317338
}
339+
318340
if ((messages = meetings.get(meetingCode)) != null) {
319341
messages.remove(meetingCode);
320342
}
343+
321344
meetings.notifyAll();
322345
}
323346

0 commit comments

Comments
 (0)