001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.geronimo.tomcat.cluster.wadi;
021:
022: import java.io.BufferedReader;
023: import java.io.IOException;
024: import java.io.UnsupportedEncodingException;
025: import java.security.Principal;
026: import java.util.Enumeration;
027: import java.util.Locale;
028: import java.util.Map;
029:
030: import javax.servlet.FilterChain;
031: import javax.servlet.RequestDispatcher;
032: import javax.servlet.ServletException;
033: import javax.servlet.ServletInputStream;
034: import javax.servlet.ServletRequest;
035: import javax.servlet.ServletResponse;
036: import javax.servlet.http.Cookie;
037: import javax.servlet.http.HttpServletRequest;
038: import javax.servlet.http.HttpSession;
039:
040: import org.apache.catalina.connector.Request;
041: import org.apache.catalina.connector.Response;
042: import org.apache.geronimo.clustering.ClusteredInvocation;
043: import org.apache.geronimo.clustering.ClusteredInvocationException;
044: import org.apache.geronimo.tomcat.cluster.AbstractClusteredValve;
045: import org.codehaus.wadi.core.contextualiser.InvocationException;
046: import org.codehaus.wadi.core.manager.Manager;
047: import org.codehaus.wadi.web.impl.WebInvocation;
048:
049: /**
050: *
051: * @version $Rev$ $Date$
052: */
053: public class WADIClusteredValve extends AbstractClusteredValve {
054: private final Manager wadiManager;
055:
056: public WADIClusteredValve(Manager wadiManager) {
057: this .wadiManager = wadiManager;
058: }
059:
060: protected ClusteredInvocation newClusteredInvocation(
061: Request request, Response response) {
062: return new WADIWebClusteredInvocation(request, response);
063: }
064:
065: protected class WADIWebClusteredInvocation extends
066: WebClusteredInvocation {
067:
068: public WADIWebClusteredInvocation(Request request,
069: Response response) {
070: super (request, response);
071: }
072:
073: public void invoke() throws ClusteredInvocationException {
074: WebInvocation invocation = new WebInvocation(5000);
075: FilterChain chainAdapter = new FilterChain() {
076: public void doFilter(ServletRequest request,
077: ServletResponse response) throws IOException,
078: ServletException {
079: try {
080: invokeLocally();
081: } catch (ClusteredInvocationException e) {
082: throw (IOException) new IOException()
083: .initCause(e);
084: }
085: }
086: };
087: invocation.init(
088: null == request ? NoOpHttpServletRequest.SINGLETON
089: : request, response, chainAdapter);
090: try {
091: wadiManager.contextualise(invocation);
092: } catch (InvocationException e) {
093: Throwable throwable = e.getCause();
094: if (throwable instanceof IOException) {
095: throw new ClusteredInvocationException(throwable);
096: } else if (throwable instanceof ServletException) {
097: throw new ClusteredInvocationException(throwable);
098: } else {
099: throw new ClusteredInvocationException(e);
100: }
101: }
102: }
103: }
104:
105: protected static class NoOpHttpServletRequest implements
106: HttpServletRequest {
107: public static final NoOpHttpServletRequest SINGLETON = new NoOpHttpServletRequest();
108:
109: public String getAuthType() {
110: throw new UnsupportedOperationException();
111: }
112:
113: public String getContextPath() {
114: throw new UnsupportedOperationException();
115: }
116:
117: public Cookie[] getCookies() {
118: throw new UnsupportedOperationException();
119: }
120:
121: public long getDateHeader(String arg0) {
122: throw new UnsupportedOperationException();
123: }
124:
125: public String getHeader(String arg0) {
126: throw new UnsupportedOperationException();
127: }
128:
129: public Enumeration getHeaderNames() {
130: throw new UnsupportedOperationException();
131: }
132:
133: public Enumeration getHeaders(String arg0) {
134: throw new UnsupportedOperationException();
135: }
136:
137: public int getIntHeader(String arg0) {
138: throw new UnsupportedOperationException();
139: }
140:
141: public String getMethod() {
142: throw new UnsupportedOperationException();
143: }
144:
145: public String getPathInfo() {
146: throw new UnsupportedOperationException();
147: }
148:
149: public String getPathTranslated() {
150: throw new UnsupportedOperationException();
151: }
152:
153: public String getQueryString() {
154: throw new UnsupportedOperationException();
155: }
156:
157: public String getRemoteUser() {
158: throw new UnsupportedOperationException();
159: }
160:
161: public String getRequestURI() {
162: throw new UnsupportedOperationException();
163: }
164:
165: public StringBuffer getRequestURL() {
166: throw new UnsupportedOperationException();
167: }
168:
169: public String getRequestedSessionId() {
170: return null;
171: }
172:
173: public String getServletPath() {
174: throw new UnsupportedOperationException();
175: }
176:
177: public HttpSession getSession() {
178: throw new UnsupportedOperationException();
179: }
180:
181: public HttpSession getSession(boolean arg0) {
182: throw new UnsupportedOperationException();
183: }
184:
185: public Principal getUserPrincipal() {
186: throw new UnsupportedOperationException();
187: }
188:
189: public boolean isRequestedSessionIdFromCookie() {
190: throw new UnsupportedOperationException();
191: }
192:
193: public boolean isRequestedSessionIdFromURL() {
194: throw new UnsupportedOperationException();
195: }
196:
197: public boolean isRequestedSessionIdFromUrl() {
198: throw new UnsupportedOperationException();
199: }
200:
201: public boolean isRequestedSessionIdValid() {
202: throw new UnsupportedOperationException();
203: }
204:
205: public boolean isUserInRole(String arg0) {
206: throw new UnsupportedOperationException();
207: }
208:
209: public Object getAttribute(String arg0) {
210: throw new UnsupportedOperationException();
211: }
212:
213: public Enumeration getAttributeNames() {
214: throw new UnsupportedOperationException();
215: }
216:
217: public String getCharacterEncoding() {
218: throw new UnsupportedOperationException();
219: }
220:
221: public int getContentLength() {
222: throw new UnsupportedOperationException();
223: }
224:
225: public String getContentType() {
226: throw new UnsupportedOperationException();
227: }
228:
229: public ServletInputStream getInputStream() throws IOException {
230: throw new UnsupportedOperationException();
231: }
232:
233: public String getLocalAddr() {
234: throw new UnsupportedOperationException();
235: }
236:
237: public String getLocalName() {
238: throw new UnsupportedOperationException();
239: }
240:
241: public int getLocalPort() {
242: throw new UnsupportedOperationException();
243: }
244:
245: public Locale getLocale() {
246: throw new UnsupportedOperationException();
247: }
248:
249: public Enumeration getLocales() {
250: throw new UnsupportedOperationException();
251: }
252:
253: public String getParameter(String arg0) {
254: throw new UnsupportedOperationException();
255: }
256:
257: public Map getParameterMap() {
258: throw new UnsupportedOperationException();
259: }
260:
261: public Enumeration getParameterNames() {
262: throw new UnsupportedOperationException();
263: }
264:
265: public String[] getParameterValues(String arg0) {
266: throw new UnsupportedOperationException();
267: }
268:
269: public String getProtocol() {
270: throw new UnsupportedOperationException();
271: }
272:
273: public BufferedReader getReader() throws IOException {
274: throw new UnsupportedOperationException();
275: }
276:
277: public String getRealPath(String arg0) {
278: throw new UnsupportedOperationException();
279: }
280:
281: public String getRemoteAddr() {
282: throw new UnsupportedOperationException();
283: }
284:
285: public String getRemoteHost() {
286: throw new UnsupportedOperationException();
287: }
288:
289: public int getRemotePort() {
290: throw new UnsupportedOperationException();
291: }
292:
293: public RequestDispatcher getRequestDispatcher(String arg0) {
294: throw new UnsupportedOperationException();
295: }
296:
297: public String getScheme() {
298: throw new UnsupportedOperationException();
299: }
300:
301: public String getServerName() {
302: throw new UnsupportedOperationException();
303: }
304:
305: public int getServerPort() {
306: throw new UnsupportedOperationException();
307: }
308:
309: public boolean isSecure() {
310: throw new UnsupportedOperationException();
311: }
312:
313: public void removeAttribute(String arg0) {
314: throw new UnsupportedOperationException();
315: }
316:
317: public void setAttribute(String arg0, Object arg1) {
318: throw new UnsupportedOperationException();
319: }
320:
321: public void setCharacterEncoding(String arg0)
322: throws UnsupportedEncodingException {
323: throw new UnsupportedOperationException();
324: }
325:
326: }
327:
328: }
|