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;
06:
07: import java.net.MalformedURLException;
08:
09: import com.sun.portal.rewriter.util.Debug;
10: import com.sun.portal.rewriter.util.crypto.CryptoHelper;
11: import com.sun.portal.rewriter.util.uri.DecoratedURI;
12: import com.sun.portal.rproxy.connectionhandler.Request;
13: import com.sun.portal.rproxy.connectionhandler.Response;
14: import com.sun.portal.rproxy.rewriter.util.SRAPConfigManager;
15: import com.sun.portal.rproxy.rewriter.util.uri.SRAPGatewayURI;
16:
17: public final class SRAPTranslatorHelper {
18: /**
19: * Used by HTTPRequest uriDecode() method
20: */
21: public static String decodeOfuscatedURI(String aURI) {
22: String lResult = aURI;
23:
24: if (SRAPConfigManager.isObscureURIs()) {
25: lResult = CryptoHelper.decode(aURI);
26: }
27:
28: try {
29: // BugNo:4855482,4855960
30: lResult = new DecoratedURI(lResult).toExternalForm();
31: } catch (MalformedURLException e) {
32: }
33:
34: return lResult;
35: }// decodeOfuscatedURI()
36:
37: public static String prefixGateway(
38: final SRAPGatewayURI aGatewayURI,
39: final DecoratedURI aAbsoluteURI) {
40: SRAPGatewayURI lGatewayURI = aGatewayURI
41: .decideGatewayURI(aAbsoluteURI);
42:
43: // if the url is already rewritten with gateway URL..
44: if (lGatewayURI.isNetworkURIMatch(aAbsoluteURI)) {
45: return aAbsoluteURI.toExternalForm();
46: }
47:
48: String lGatewayURIString = lGatewayURI.toReverseProxyForm();
49: String lAbsoluteURIString = aAbsoluteURI.toExternalForm();
50: StringBuffer sb = new StringBuffer(lGatewayURIString.length()
51: + lAbsoluteURIString.length() + 1);
52: sb.append(lGatewayURIString).append("/");
53: sb.append(lAbsoluteURIString);
54: return sb.toString();
55: }// prefixGateway()
56:
57: public static String translateHeaderURL(final String aURI,
58: final Response aResp, final Request aReq,
59: final boolean aParseHeader, final boolean aIsAddScheme) {
60: String lURI = aURI;
61:
62: if (aParseHeader) {
63: int i = aURI.indexOf(':');
64: if (i != -1 && i < aURI.length()) {
65: lURI = aURI.substring(i + 1).trim();
66: }
67: }
68:
69: return addScheme(lURI, aReq);
70: }// translateHeaderURL()
71:
72: private static final String addScheme(final String aOrgURI,
73: final Request aRequest) {
74: try {
75: return SRAPTranslatorBuilder.create(aRequest, null)
76: .translate(aOrgURI);
77: } catch (Exception e) {
78: Debug.recordURIWarning(
79: "Invalid URI in SRAPTranslatorHelper:BaseURI:"
80: + aOrgURI + "GatewayURI:"
81: + aRequest.getGatewayURL(), e);
82: }
83:
84: return aOrgURI;
85: }// addScheme()
86:
87: }// class SRAPTranslatorHelper
|