2
* $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpsURL.java,v 1.6.2.4 2004/09/30 17:26:27 oglueck Exp $
4
* $Date: 2004/09/30 17:26:27 $
6
* ====================================================================
8
* Copyright 2002-2004 The Apache Software Foundation
10
* Licensed under the Apache License, Version 2.0 (the "License");
11
* you may not use this file except in compliance with the License.
12
* You may obtain a copy of the License at
14
* http://www.apache.org/licenses/LICENSE-2.0
16
* Unless required by applicable law or agreed to in writing, software
17
* distributed under the License is distributed on an "AS IS" BASIS,
18
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
* See the License for the specific language governing permissions and
20
* limitations under the License.
21
* ====================================================================
23
* This software consists of voluntary contributions made by many
24
* individuals on behalf of the Apache Software Foundation. For more
25
* information on the Apache Software Foundation, please see
26
* <http://www.apache.org/>.
28
* [Additional notices, if required by prior licensing conditions]
32
package org.apache.commons.httpclient;
34
import org.apache.commons.httpclient.util.URIUtil;
39
* @author <a href="mailto:jericho at apache.org">Sung-Gu</a>
40
* @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
42
public class HttpsURL extends HttpURL {
44
// ----------------------------------------------------------- Constructors
47
* Create an instance as an internal use.
49
protected HttpsURL() {
54
* Construct a HTTPS URL as an escaped form of a character array with the
55
* given charset to do escape encoding.
57
* @param escaped the HTTPS URL character sequence
58
* @param charset the charset to do escape encoding
59
* @throws URIException If {@link #checkValid()} fails
60
* @throws NullPointerException if <code>escaped</code> is <code>null</code>
61
* @see #getProtocolCharset
63
public HttpsURL(char[] escaped, String charset)
64
throws URIException, NullPointerException {
65
protocolCharset = charset;
66
parseUriReference(new String(escaped), true);
72
* Construct a HTTPS URL as an escaped form of a character array.
74
* @param escaped the HTTPS URL character sequence
75
* @throws URIException If {@link #checkValid()} fails
76
* @throws NullPointerException if <code>escaped</code> is <code>null</code>
77
* @see #getDefaultProtocolCharset
79
public HttpsURL(char[] escaped) throws URIException, NullPointerException {
80
parseUriReference(new String(escaped), true);
86
* Construct a HTTPS URL from a given string with the given charset to do
89
* @param original the HTTPS URL string
90
* @param charset the charset to do escape encoding
91
* @throws URIException If {@link #checkValid()} fails
92
* @see #getProtocolCharset
94
public HttpsURL(String original, String charset) throws URIException {
95
protocolCharset = charset;
96
parseUriReference(original, false);
102
* Construct a HTTPS URL from a given string.
104
* @param original the HTTPS URL string
105
* @throws URIException If {@link #checkValid()} fails
106
* @see #getDefaultProtocolCharset
108
public HttpsURL(String original) throws URIException {
109
parseUriReference(original, false);
115
* Construct a HTTPS URL from given components.
117
* @param host the host string
118
* @param port the port number
119
* @param path the path string
120
* @throws URIException If {@link #checkValid()} fails
121
* @see #getDefaultProtocolCharset
123
public HttpsURL(String host, int port, String path) throws URIException {
124
this(null, host, port, path, null, null);
129
* Construct a HTTPS URL from given components.
131
* @param host the host string
132
* @param port the port number
133
* @param path the path string
134
* @param query the query string
135
* @throws URIException If {@link #checkValid()} fails
136
* @see #getDefaultProtocolCharset
138
public HttpsURL(String host, int port, String path, String query)
139
throws URIException {
141
this(null, host, port, path, query, null);
146
* Construct a HTTPS URL from given components.
148
* @param user the user name
149
* @param password his or her password
150
* @param host the host string
151
* @throws URIException If {@link #checkValid()} fails
152
* @see #getDefaultProtocolCharset
154
public HttpsURL(String user, String password, String host)
155
throws URIException {
157
this(user, password, host, -1, null, null, null);
162
* Construct a HTTPS URL from given components.
164
* @param user the user name
165
* @param password his or her password
166
* @param host the host string
167
* @param port the port number
168
* @throws URIException If {@link #checkValid()} fails
169
* @see #getDefaultProtocolCharset
171
public HttpsURL(String user, String password, String host, int port)
172
throws URIException {
174
this(user, password, host, port, null, null, null);
179
* Construct a HTTPS URL from given components.
181
* @param user the user name
182
* @param password his or her password
183
* @param host the host string
184
* @param port the port number
185
* @param path the path string
186
* @throws URIException If {@link #checkValid()} fails
187
* @see #getDefaultProtocolCharset
189
public HttpsURL(String user, String password, String host, int port,
190
String path) throws URIException {
192
this(user, password, host, port, path, null, null);
197
* Construct a HTTPS URL from given components.
199
* @param user the user name
200
* @param password his or her password
201
* @param host the host string
202
* @param port the port number
203
* @param path the path string
204
* @param query The query string.
205
* @throws URIException If {@link #checkValid()} fails
206
* @see #getDefaultProtocolCharset
208
public HttpsURL(String user, String password, String host, int port,
209
String path, String query) throws URIException {
211
this(user, password, host, port, path, query, null);
216
* Construct a HTTPS URL from given components.
218
* @param host the host string
219
* @param path the path string
220
* @param query the query string
221
* @param fragment the fragment string
222
* @throws URIException If {@link #checkValid()} fails
223
* @see #getDefaultProtocolCharset
225
public HttpsURL(String host, String path, String query, String fragment)
226
throws URIException {
228
this(null, host, -1, path, query, fragment);
233
* Construct a HTTPS URL from given components.
235
* Note: The <code>userinfo</code> format is normally
236
* <code><username>:<password></code> where
237
* username and password must both be URL escaped.
239
* @param userinfo the userinfo string whose parts are URL escaped
240
* @param host the host string
241
* @param path the path string
242
* @param query the query string
243
* @param fragment the fragment string
244
* @throws URIException If {@link #checkValid()} fails
245
* @see #getDefaultProtocolCharset
247
public HttpsURL(String userinfo, String host, String path, String query,
248
String fragment) throws URIException {
250
this(userinfo, host, -1, path, query, fragment);
255
* Construct a HTTPS URL from given components.
257
* Note: The <code>userinfo</code> format is normally
258
* <code><username>:<password></code> where
259
* username and password must both be URL escaped.
261
* @param userinfo the userinfo string whose parts are URL escaped
262
* @param host the host string
263
* @param port the port number
264
* @param path the path string
265
* @throws URIException If {@link #checkValid()} fails
266
* @see #getDefaultProtocolCharset
268
public HttpsURL(String userinfo, String host, int port, String path)
269
throws URIException {
271
this(userinfo, host, port, path, null, null);
276
* Construct a HTTPS URL from given components.
278
* Note: The <code>userinfo</code> format is normally
279
* <code><username>:<password></code> where
280
* username and password must both be URL escaped.
282
* @param userinfo the userinfo string whose parts are URL escaped
283
* @param host the host string
284
* @param port the port number
285
* @param path the path string
286
* @param query the query string
287
* @throws URIException If {@link #checkValid()} fails
288
* @see #getDefaultProtocolCharset
290
public HttpsURL(String userinfo, String host, int port, String path,
291
String query) throws URIException {
293
this(userinfo, host, port, path, query, null);
298
* Construct a HTTPS URL from given components.
300
* Note: The <code>userinfo</code> format is normally
301
* <code><username>:<password></code> where
302
* username and password must both be URL escaped.
304
* @param userinfo the userinfo string whose parts are URL escaped
305
* @param host the host string
306
* @param port the port number
307
* @param path the path string
308
* @param query the query string
309
* @param fragment the fragment string
310
* @throws URIException If {@link #checkValid()} fails
311
* @see #getDefaultProtocolCharset
313
public HttpsURL(String userinfo, String host, int port, String path,
314
String query, String fragment) throws URIException {
316
// validate and contruct the URI character sequence
317
StringBuffer buff = new StringBuffer();
318
if (userinfo != null || host != null || port != -1) {
319
_scheme = DEFAULT_SCHEME; // in order to verify the own protocol
320
buff.append(_default_scheme);
322
if (userinfo != null) {
323
buff.append(userinfo);
327
buff.append(URIUtil.encode(host, URI.allowed_host));
328
if (port != -1 || port != DEFAULT_PORT) {
334
if (path != null) { // accept empty path
335
if (scheme != null && !path.startsWith("/")) {
336
throw new URIException(URIException.PARSING,
337
"abs_path requested");
339
buff.append(URIUtil.encode(path, URI.allowed_abs_path));
343
buff.append(URIUtil.encode(query, URI.allowed_query));
345
if (fragment != null) {
347
buff.append(URIUtil.encode(fragment, URI.allowed_fragment));
349
parseUriReference(buff.toString(), true);
354
* Construct a HTTP URL from given components.
356
* @param user the user name
357
* @param password his or her password
358
* @param host the host string
359
* @param port the port number
360
* @param path the path string
361
* @param query the query string
362
* @param fragment the fragment string
363
* @throws URIException If {@link #checkValid()} fails
364
* @see #getDefaultProtocolCharset
366
public HttpsURL(String user, String password, String host, int port,
367
String path, String query, String fragment) throws URIException {
368
this(HttpURL.toUserinfo(user, password), host, port, path, query, fragment);
372
* Construct a HTTPS URL with a given relative HTTPS URL string.
374
* @param base the base HttpsURL
375
* @param relative the relative HTTPS URL string
376
* @throws URIException If {@link #checkValid()} fails
378
public HttpsURL(HttpsURL base, String relative) throws URIException {
379
this(base, new HttpsURL(relative));
384
* Construct a HTTPS URL with a given relative URL.
386
* @param base the base HttpsURL
387
* @param relative the relative HttpsURL
388
* @throws URIException If {@link #checkValid()} fails
390
public HttpsURL(HttpsURL base, HttpsURL relative) throws URIException {
391
super(base, relative);
395
// -------------------------------------------------------------- Constants
398
* Default scheme for HTTPS URL.
400
public static final char[] DEFAULT_SCHEME = { 'h', 't', 't', 'p', 's' };
403
* Default scheme for HTTPS URL.
404
* @deprecated Use {@link #DEFAULT_SCHEME} instead. This one doesn't
405
* conform to the project naming conventions.
407
public static final char[] _default_scheme = DEFAULT_SCHEME;
411
* Default port for HTTPS URL.
413
public static final int DEFAULT_PORT = 443;
416
* Default port for HTTPS URL.
417
* @deprecated Use {@link #DEFAULT_PORT} instead. This one doesn't conform
418
* to the project naming conventions.
420
public static final int _default_port = DEFAULT_PORT;
424
* The serialVersionUID.
426
static final long serialVersionUID = 887844277028676648L;
428
// ------------------------------------------------------------- The scheme
431
* Get the scheme. You can get the scheme explicitly.
435
public char[] getRawScheme() {
436
return (_scheme == null) ? null : HttpsURL.DEFAULT_SCHEME;
441
* Get the scheme. You can get the scheme explicitly.
443
* @return the scheme null if empty or undefined
445
public String getScheme() {
446
return (_scheme == null) ? null : new String(HttpsURL.DEFAULT_SCHEME);
449
// --------------------------------------------------------------- The port
452
* Get the port number.
453
* @return the port number
455
public int getPort() {
456
return (_port == -1) ? HttpsURL.DEFAULT_PORT : _port;
459
// ---------------------------------------------------------------- Utility
462
* Verify the valid class use for construction.
464
* @throws URIException the wrong scheme use
466
protected void checkValid() throws URIException {
467
// could be explicit protocol or undefined.
468
if (!(equals(_scheme, DEFAULT_SCHEME) || _scheme == null)) {
469
throw new URIException(URIException.PARSING, "wrong class use");