1
14
15 package com.liferay.portal.servlet.filters.doubleclick;
16
17 import com.liferay.portal.kernel.servlet.StringServletResponse;
18 import com.liferay.util.servlet.filters.CacheResponseData;
19 import com.liferay.util.servlet.filters.CacheResponseUtil;
20
21 import java.io.IOException;
22 import java.io.Serializable;
23
24 import javax.servlet.FilterChain;
25 import javax.servlet.ServletException;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28
29
35 public class DoubleClickController implements Serializable {
36
37 public void control(
38 HttpServletRequest request, HttpServletResponse response,
39 FilterChain filterChain)
40 throws IOException, ServletException {
41
42 boolean firstRequest = false;
43
44 StringServletResponse stringResponse = null;
45
46 synchronized (this) {
47 if (_stringResponse == null) {
48 firstRequest = true;
49
50 _stringResponse = new StringServletResponse(response);
51 _throwable = null;
52 }
53
54 stringResponse = _stringResponse;
55 }
56
57 if (firstRequest) {
58 try {
59 filterChain.doFilter(request, _stringResponse);
60 }
61 catch (Throwable t) {
62 _throwable = t;
63 }
64 finally {
65 synchronized (this) {
66 _stringResponse = null;
67
68 notifyAll();
69 }
70 }
71 }
72 else {
73 synchronized (this) {
74 while (_stringResponse != null) {
75 try {
76 wait();
77 }
78 catch (InterruptedException ie) {
79 Thread currentThread = Thread.currentThread();
80
81 currentThread.interrupt();
82 }
83 }
84 }
85 }
86
87 if (_throwable != null) {
88 try {
89 throw _throwable;
90 }
91 catch (IOException ioe) {
92 throw ioe;
93 }
94 catch (ServletException se) {
95 throw se;
96 }
97 catch (RuntimeException re) {
98 throw re;
99 }
100 catch (Error e) {
101 throw e;
102 }
103 catch (Throwable t) {
104 throw new RuntimeException(t);
105 }
106 }
107
108 CacheResponseData cacheResponseData = new CacheResponseData(
109 stringResponse);
110
111 CacheResponseUtil.write(response, cacheResponseData);
112 }
113
114 private StringServletResponse _stringResponse;
115 private Throwable _throwable;
116
117 }