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: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.vfs;
030:
031: import com.caucho.util.L10N;
032:
033: import java.io.IOException;
034: import java.util.Map;
035:
036: /**
037: * The HTTP scheme. Currently it supports GET and POST.
038: *
039: * <p>TODO: support WEBDAV, enabling the full Path API.
040: */
041: public class HttpsPath extends HttpPath {
042: protected static L10N L = new L10N(HttpsPath.class);
043:
044: /**
045: * Creates a new HTTP root path with a host and a port.
046: *
047: * @param host the target host
048: * @param port the target port, if zero, uses port 80.
049: */
050: public HttpsPath(String host, int port) {
051: super (host, port);
052: }
053:
054: /**
055: * Creates a new HTTP sub path.
056: *
057: * @param root the HTTP filesystem root
058: * @param userPath the argument to the calling lookup()
059: * @param newAttributes any attributes passed to http
060: * @param path the full normalized path
061: * @param query any query string
062: */
063: public HttpsPath(FilesystemPath root, String userPath,
064: Map<String, Object> newAttributes, String path, String query) {
065: super (root, userPath, newAttributes, path, query);
066: }
067:
068: protected HttpPath create(String host, int port) {
069: return new HttpsPath(host, port);
070: }
071:
072: protected HttpPath create(FilesystemPath root, String userPath,
073: Map<String, Object> newAttributes, String path, String query) {
074: return new HttpsPath(root, userPath, newAttributes, path, query);
075: }
076:
077: /**
078: * Returns the scheme, http.
079: */
080: public String getScheme() {
081: return "https";
082: }
083:
084: /**
085: * Returns a read stream for a GET request.
086: */
087: public StreamImpl openReadImpl() throws IOException {
088: HttpStreamWrapper stream = HttpStream.openRead(this );
089:
090: stream.setSSL(true);
091:
092: return stream;
093: }
094:
095: /**
096: * Returns a read/write pair for a POST request.
097: */
098: public StreamImpl openReadWriteImpl() throws IOException {
099: HttpStreamWrapper stream = HttpStream.openReadWrite(this );
100:
101: stream.setSSL(true);
102:
103: return stream;
104: }
105:
106: /**
107: * Returns a hashCode for the path.
108: */
109: public int hashCode() {
110: return 17 + 65537 * super .hashCode() + 37 * _host.hashCode()
111: + _port;
112: }
113:
114: /**
115: * Overrides equals to test for equality with an HTTP path.
116: */
117: public boolean equals(Object o) {
118: if (!(o instanceof HttpsPath))
119: return false;
120:
121: HttpsPath test = (HttpsPath) o;
122:
123: if (!_host.equals(test._host))
124: return false;
125: else if (_port != test._port)
126: return false;
127: else if (_query != null && !_query.equals(test._query))
128: return false;
129: else if (_query == null && test._query != null)
130: return false;
131: else
132: return true;
133: }
134: }
|