01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05: package com.sun.portal.rproxy.rewriter.util.uri;
06:
07: import com.sun.portal.rewriter.util.uri.DecoratedURI;
08: import com.sun.portal.log.common.PortalLogger;
09: import com.sun.portal.rproxy.rewriter.util.SRAPConfigManager;
10:
11: import java.net.MalformedURLException;
12:
13: public class SRAPGatewayURI extends DecoratedURI {
14: private static final String HTTP_PROTOCOL = "http";
15: private static final String HTTPS_PROTOCOL = "https";
16:
17: private String reverseProxyForm = null;
18:
19: public SRAPGatewayURI(String aURIString)
20: throws MalformedURLException {
21: super (aURIString);
22: }//constructor
23:
24: //assingining these vars late as these values may not be used unleess
25: //useprototocol consistancy is enabled
26: private SRAPGatewayURI httpURI;
27: private SRAPGatewayURI httpsURI;
28:
29: public SRAPGatewayURI makeProtocolConsistantURI(DecoratedURI aURI) {
30: try {
31: if (httpsURI == null /*||httpURI == null*/) {
32: assignObjectVars();
33: }//if
34:
35: if (httpsURI != null) {
36: if (httpsURI.getProtocol().equalsIgnoreCase(
37: aURI.getProtocol())) {
38: return httpsURI;
39: } else if (httpURI.getProtocol().equalsIgnoreCase(
40: aURI.getProtocol())) {
41: return httpURI;
42: }
43: }
44: } catch (MalformedURLException e) {
45: }
46:
47: //if the protocol is neither http or https use as is
48: //or when the exception is thrown
49: return this ;
50: }//makeProtocolConsistantURI()
51:
52: public SRAPGatewayURI decideGatewayURI(DecoratedURI aURI) {
53: if (SRAPConfigManager.isUseConsistantProtocol4Gateway()) {
54: return makeProtocolConsistantURI(aURI);
55: }
56:
57: return this ;
58: }//decideGatewayURI()
59:
60: public final String toReverseProxyForm() {
61: if (reverseProxyForm == null) {
62: reverseProxyForm = getFullFileURI();
63:
64: if (reverseProxyForm.endsWith("/")) {
65: reverseProxyForm = reverseProxyForm.substring(0,
66: reverseProxyForm.length() - 1);
67: }
68: }
69:
70: return reverseProxyForm;
71: }//toReverseProxyForm()
72:
73: private void assignObjectVars() throws MalformedURLException {
74: if (getProtocol().equalsIgnoreCase(HTTP_PROTOCOL)) {
75: httpURI = this ;
76: httpsURI = new SRAPGatewayURI(HTTPS_PROTOCOL + "://"
77: + getUserInfo() + getHost()
78: + SRAPConfigManager.getHTTPSPort() + getPath()
79: + getQuery() + getReference());
80: } else if (getProtocol().equalsIgnoreCase(HTTPS_PROTOCOL)) {
81: httpsURI = this ;
82: httpURI = new SRAPGatewayURI(HTTP_PROTOCOL + "://"
83: + getUserInfo() + getHost()
84: + SRAPConfigManager.getHTTPPort() + getPath()
85: + getQuery() + getReference());
86: }
87: }//assignObjectVars()
88: }//class SRAPGatewayURI
|