001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.server.dispatch;
031:
032: import com.caucho.log.Log;
033: import com.caucho.server.webapp.WebApp;
034: import com.caucho.server.connection.AbstractHttpRequest;
035: import com.caucho.util.L10N;
036: import com.caucho.vfs.Dependency;
037:
038: import java.util.logging.Logger;
039:
040: /**
041: * A repository for request information gleaned from the uri.
042: */
043: public class Invocation extends ServletInvocation implements Dependency {
044: static final L10N L = new L10N(Invocation.class);
045: static final Logger log = Logger.getLogger(Invocation.class
046: .getName());
047:
048: private String _rawHost;
049:
050: // canonical host and port
051: private String _hostName;
052: private int _port;
053:
054: private String _rawURI;
055: private boolean _isSecure;
056:
057: private String _uri;
058: private String _sessionId;
059:
060: private WebApp _webApp;
061:
062: private Dependency _dependency;
063:
064: public Invocation() {
065: }
066:
067: /**
068: * Returns the secure flag
069: */
070: public final boolean isSecure() {
071: return _isSecure;
072: }
073:
074: /**
075: * Sets the secure flag
076: */
077: public final void setSecure(boolean isSecure) {
078: _isSecure = isSecure;
079: }
080:
081: /**
082: * Returns the raw host from the protocol. This may be different
083: * from the canonical host name.
084: */
085: public final String getHost() {
086: return _rawHost;
087: }
088:
089: /**
090: * Sets the protocol's host.
091: */
092: public final void setHost(String host) {
093: _rawHost = host;
094: }
095:
096: /**
097: * Returns canonical host name.
098: */
099: public final String getHostName() {
100: return _hostName;
101: }
102:
103: /**
104: * Sets the protocol's host.
105: */
106: public final void setHostName(String hostName) {
107: if (hostName != null && !hostName.equals(""))
108: _hostName = hostName;
109: }
110:
111: /**
112: * Returns canonical port
113: */
114: public final int getPort() {
115: return _port;
116: }
117:
118: /**
119: * Sets the canonical port
120: */
121: public final void setPort(int port) {
122: _port = port;
123: }
124:
125: /**
126: * Returns the raw URI from the protocol before any normalization.
127: * The raw URI includes the query string. (?)
128: */
129: public final String getRawURI() {
130: return _rawURI;
131: }
132:
133: /**
134: * Sets the raw URI from the protocol before any normalization.
135: * The raw URI includes the query string. (?)
136: */
137: public final void setRawURI(String uri) {
138: _rawURI = uri;
139: }
140:
141: /**
142: * Returns the raw URI length.
143: */
144: public int getURLLength() {
145: if (_rawURI != null)
146: return _rawURI.length();
147: else
148: return 0;
149: }
150:
151: /**
152: * Returns the URI after normalization, e.g. character escaping,
153: * URL session, and query string.
154: */
155: public final String getURI() {
156: return _uri;
157: }
158:
159: /**
160: * Sets the URI after normalization.
161: */
162: public final void setURI(String uri) {
163: _uri = uri;
164:
165: setContextURI(uri);
166: }
167:
168: /**
169: * Returns a URL-based session id.
170: */
171: public final String getSessionId() {
172: return _sessionId;
173: }
174:
175: /**
176: * Sets the URL-based session id.
177: */
178: public final void setSessionId(String sessionId) {
179: _sessionId = sessionId;
180: }
181:
182: /**
183: * Returns the mapped webApp.
184: */
185: public final WebApp getWebApp() {
186: return _webApp;
187: }
188:
189: /**
190: * Sets the mapped webApp.
191: */
192: public void setWebApp(WebApp app) {
193: _webApp = app;
194: }
195:
196: /**
197: * Sets the dependency.
198: */
199: public void setDependency(Dependency dependency) {
200: _dependency = dependency;
201: }
202:
203: /**
204: * Returns the dependency list.
205: */
206: public Dependency getDependency() {
207: return _dependency;
208: }
209:
210: /**
211: * Returns true if the invocation has been modified. Generally only
212: * true if the webApp has been modified.
213: */
214: public boolean isModified() {
215: Dependency depend = _dependency;
216:
217: if (depend != null && depend.isModified())
218: return true;
219:
220: WebApp app = _webApp;
221:
222: if (app != null) {
223: depend = app.getInvocationDependency();
224:
225: if (depend != null)
226: return depend.isModified();
227: }
228:
229: return true;
230: }
231:
232: /**
233: * Log the reason for modification.
234: */
235: public boolean logModified(Logger log) {
236: Dependency depend = _dependency;
237:
238: if (depend != null && depend.logModified(log))
239: return true;
240:
241: WebApp app = _webApp;
242:
243: if (app != null) {
244: depend = app.getInvocationDependency();
245:
246: if (depend != null)
247: return depend.logModified(log);
248: }
249:
250: return true;
251: }
252:
253: /**
254: * Returns the versioned invocation based on this request.
255: *
256: * @param request the servlet request
257: */
258: public Invocation getRequestInvocation(AbstractHttpRequest request) {
259: return this ;
260: }
261:
262: /**
263: * Copies from the invocation.
264: */
265: public void copyFrom(Invocation invocation) {
266: super .copyFrom(invocation);
267:
268: _rawHost = invocation._rawHost;
269: _rawURI = invocation._rawURI;
270:
271: _hostName = invocation._hostName;
272: _port = invocation._port;
273: _uri = invocation._uri;
274:
275: // server/1h25
276: _sessionId = invocation._sessionId;
277:
278: _webApp = invocation._webApp;
279: _dependency = invocation._dependency;
280: }
281:
282: /**
283: * Returns the invocation's hash code.
284: */
285: public int hashCode() {
286: int hash = _rawURI.hashCode();
287:
288: if (_rawHost != null)
289: hash = hash * 65521 + _rawHost.hashCode();
290:
291: hash = hash * 65521 + _port;
292:
293: return hash;
294: }
295:
296: /**
297: * Checks for equality
298: */
299: public boolean equals(Object o) {
300: if (this == o)
301: return true;
302: else if (o == null)
303: return false;
304:
305: if (getClass() != o.getClass())
306: return false;
307:
308: Invocation inv = (Invocation) o;
309:
310: if (_isSecure != inv._isSecure)
311: return false;
312:
313: if (_rawURI != inv._rawURI
314: && (_rawURI == null || !_rawURI.equals(inv._rawURI)))
315: return false;
316:
317: if (_rawHost != inv._rawHost
318: && (_rawHost == null || !_rawHost.equals(inv._rawHost)))
319: return false;
320:
321: if (_port != inv._port)
322: return false;
323:
324: String aQuery = getQueryString();
325: String bQuery = inv.getQueryString();
326:
327: if (aQuery != bQuery
328: && (aQuery == null || !aQuery.equals(bQuery)))
329: return false;
330:
331: return true;
332: }
333:
334: void close() {
335: _webApp = null;
336: }
337: }
|