|
1 | 1 | package hello.services;
|
2 | 2 |
|
3 |
| -import java.io.IOException; |
4 |
| - |
5 |
| -import org.apache.tapestry5.*; |
| 3 | +import org.apache.tapestry5.SymbolConstants; |
6 | 4 | import org.apache.tapestry5.ioc.MappedConfiguration;
|
7 |
| -import org.apache.tapestry5.ioc.OrderedConfiguration; |
8 | 5 | import org.apache.tapestry5.ioc.ServiceBinder;
|
9 |
| -import org.apache.tapestry5.ioc.annotations.Local; |
10 |
| -import org.apache.tapestry5.services.Request; |
11 |
| -import org.apache.tapestry5.services.RequestFilter; |
12 |
| -import org.apache.tapestry5.services.RequestHandler; |
13 |
| -import org.apache.tapestry5.services.Response; |
14 |
| -import org.slf4j.Logger; |
15 | 6 |
|
16 | 7 | /**
|
17 | 8 | * This module is automatically included as part of the Tapestry IoC Registry, it's a good place to
|
@@ -51,67 +42,4 @@ public static void contributeApplicationDefaults(
|
51 | 42 | // the first locale name is the default when there's no reasonable match).
|
52 | 43 | configuration.add(SymbolConstants.SUPPORTED_LOCALES, "en");
|
53 | 44 | }
|
54 |
| - |
55 |
| - |
56 |
| - /** |
57 |
| - * This is a service definition, the service will be named "TimingFilter". The interface, |
58 |
| - * RequestFilter, is used within the RequestHandler service pipeline, which is built from the |
59 |
| - * RequestHandler service configuration. Tapestry IoC is responsible for passing in an |
60 |
| - * appropriate Logger instance. Requests for static resources are handled at a higher level, so |
61 |
| - * this filter will only be invoked for Tapestry related requests. |
62 |
| - * <p/> |
63 |
| - * <p/> |
64 |
| - * Service builder methods are useful when the implementation is inline as an inner class |
65 |
| - * (as here) or require some other kind of special initialization. In most cases, |
66 |
| - * use the static bind() method instead. |
67 |
| - * <p/> |
68 |
| - * <p/> |
69 |
| - * If this method was named "build", then the service id would be taken from the |
70 |
| - * service interface and would be "RequestFilter". Since Tapestry already defines |
71 |
| - * a service named "RequestFilter" we use an explicit service id that we can reference |
72 |
| - * inside the contribution method. |
73 |
| - */ |
74 |
| - public RequestFilter buildTimingFilter(final Logger log) |
75 |
| - { |
76 |
| - return new RequestFilter() |
77 |
| - { |
78 |
| - public boolean service(Request request, Response response, RequestHandler handler) |
79 |
| - throws IOException |
80 |
| - { |
81 |
| - long startTime = System.currentTimeMillis(); |
82 |
| - |
83 |
| - try |
84 |
| - { |
85 |
| - // The responsibility of a filter is to invoke the corresponding method |
86 |
| - // in the handler. When you chain multiple filters together, each filter |
87 |
| - // received a handler that is a bridge to the next filter. |
88 |
| - |
89 |
| - return handler.service(request, response); |
90 |
| - } finally |
91 |
| - { |
92 |
| - long elapsed = System.currentTimeMillis() - startTime; |
93 |
| - |
94 |
| - log.info(String.format("Request time: %d ms", elapsed)); |
95 |
| - } |
96 |
| - } |
97 |
| - }; |
98 |
| - } |
99 |
| - |
100 |
| - /** |
101 |
| - * This is a contribution to the RequestHandler service configuration. This is how we extend |
102 |
| - * Tapestry using the timing filter. A common use for this kind of filter is transaction |
103 |
| - * management or security. The @Local annotation selects the desired service by type, but only |
104 |
| - * from the same module. Without @Local, there would be an error due to the other service(s) |
105 |
| - * that implement RequestFilter (defined in other modules). |
106 |
| - */ |
107 |
| - public void contributeRequestHandler(OrderedConfiguration<RequestFilter> configuration, |
108 |
| - @Local |
109 |
| - RequestFilter filter) |
110 |
| - { |
111 |
| - // Each contribution to an ordered configuration has a name, When necessary, you may |
112 |
| - // set constraints to precisely control the invocation order of the contributed filter |
113 |
| - // within the pipeline. |
114 |
| - |
115 |
| - configuration.add("Timing", filter); |
116 |
| - } |
117 | 45 | }
|
0 commit comments