2626 */
2727public class Express extends ExpressMiddleware {
2828
29+ private final ConcurrentHashMap <String , HttpRequest > PARAMETER_LISTENER = new ConcurrentHashMap <>();
2930 private final ConcurrentHashMap <Object , Object > LOCALS = new ConcurrentHashMap <>();
3031
3132 private final ArrayList <ExpressFilterWorker > WORKER = new ArrayList <>();
@@ -55,6 +56,20 @@ public Express(String hostname) {
5556 public Express () {
5657 }
5758
59+ /**
60+ * Add an listener which will be called when an url with this parameter is called.
61+ *
62+ * @param param The parameter name.
63+ * @param request An request handler.
64+ */
65+ public void onParam (String param , HttpRequest request ) {
66+ PARAMETER_LISTENER .put (param , request );
67+ }
68+
69+ public ConcurrentHashMap <String , HttpRequest > getParameterListener () {
70+ return PARAMETER_LISTENER ;
71+ }
72+
5873 /**
5974 * Add an key-val pair to the express app, can be used
6075 * to store data. Uses ConcurrentHashMap so it's thread save.
@@ -127,7 +142,7 @@ private void addMiddleware(String requestMethod, String context, HttpRequest mid
127142 WORKER .add (new ExpressFilterWorker ((ExpressFilterTask ) middleware ));
128143 }
129144
130- MIDDLEWARE_CHAIN .add (new ExpressFilterImpl (requestMethod , context , middleware ));
145+ MIDDLEWARE_CHAIN .add (new ExpressFilterImpl (this , requestMethod , context , middleware ));
131146 }
132147
133148 /**
@@ -137,7 +152,7 @@ private void addMiddleware(String requestMethod, String context, HttpRequest mid
137152 * @param request An listener which will be fired if the context matches the requestpath.
138153 */
139154 public void all (String context , HttpRequest request ) {
140- FILTER_CHAIN .add (new ExpressFilterImpl ("*" , context , request ));
155+ FILTER_CHAIN .add (new ExpressFilterImpl (this , "*" , context , request ));
141156 }
142157
143158 /**
@@ -147,7 +162,7 @@ public void all(String context, HttpRequest request) {
147162 * @param request An listener which will be fired if the context matches the requestpath.
148163 */
149164 public void get (String context , HttpRequest request ) {
150- FILTER_CHAIN .add (new ExpressFilterImpl ("GET" , context , request ));
165+ FILTER_CHAIN .add (new ExpressFilterImpl (this , "GET" , context , request ));
151166 }
152167
153168 /**
@@ -157,7 +172,7 @@ public void get(String context, HttpRequest request) {
157172 * @param request An listener which will be fired if the context matches the requestpath.
158173 */
159174 public void post (String context , HttpRequest request ) {
160- FILTER_CHAIN .add (new ExpressFilterImpl ("POST" , context , request ));
175+ FILTER_CHAIN .add (new ExpressFilterImpl (this , "POST" , context , request ));
161176 }
162177
163178 /**
@@ -167,7 +182,7 @@ public void post(String context, HttpRequest request) {
167182 * @param request An listener which will be fired if the context matches the requestpath.
168183 */
169184 public void put (String context , HttpRequest request ) {
170- FILTER_CHAIN .add (new ExpressFilterImpl ("PUT" , context , request ));
185+ FILTER_CHAIN .add (new ExpressFilterImpl (this , "PUT" , context , request ));
171186 }
172187
173188 /**
@@ -177,7 +192,7 @@ public void put(String context, HttpRequest request) {
177192 * @param request An listener which will be fired if the context matches the requestpath.
178193 */
179194 public void delete (String context , HttpRequest request ) {
180- FILTER_CHAIN .add (new ExpressFilterImpl ("DELETE" , context , request ));
195+ FILTER_CHAIN .add (new ExpressFilterImpl (this , "DELETE" , context , request ));
181196 }
182197
183198 /**
@@ -187,7 +202,7 @@ public void delete(String context, HttpRequest request) {
187202 * @param request An listener which will be fired if the context matches the requestpath.
188203 */
189204 public void patch (String context , HttpRequest request ) {
190- FILTER_CHAIN .add (new ExpressFilterImpl ("PATCH" , context , request ));
205+ FILTER_CHAIN .add (new ExpressFilterImpl (this , "PATCH" , context , request ));
191206 }
192207
193208 /**
@@ -198,7 +213,7 @@ public void patch(String context, HttpRequest request) {
198213 * @param request An listener which will be fired if the context matches the requestpath.
199214 */
200215 public void on (String requestMethod , String context , HttpRequest request ) {
201- FILTER_CHAIN .add (new ExpressFilterImpl (requestMethod , context , request ));
216+ FILTER_CHAIN .add (new ExpressFilterImpl (this , requestMethod , context , request ));
202217 }
203218
204219 /**
@@ -211,7 +226,7 @@ public void on(String requestMethod, String context, HttpRequest request) {
211226 */
212227 public void on (String requestMethod , HttpRequest request , String ... contexts ) {
213228 for (String c : contexts )
214- FILTER_CHAIN .add (new ExpressFilterImpl (requestMethod , c , request ));
229+ FILTER_CHAIN .add (new ExpressFilterImpl (this , requestMethod , c , request ));
215230 }
216231
217232 /**
0 commit comments