001: /**
002: * Copyright 2003 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.wsrp.consumer.common.impl;
013:
014: import java.lang.NumberFormatException;
015:
016: import java.util.Properties;
017: import java.util.Enumeration;
018: import java.util.Map;
019: import java.util.HashMap;
020: import java.util.logging.Level;
021: import java.util.logging.Logger;
022:
023: import java.io.FileInputStream;
024: import java.io.IOException;
025:
026: import java.net.URL;
027:
028: import java.net.MalformedURLException;
029:
030: import com.sun.portal.wsrp.common.stubs.WSRP_v1_Markup_PortType;
031: import com.sun.portal.wsrp.common.stubs.WSRP_v1_Registration_PortType;
032: import com.sun.portal.wsrp.common.stubs.WSRP_v1_ServiceDescription_PortType;
033:
034: import com.sun.portal.wsrp.consumer.common.WSRPConsumerException;
035: import com.sun.portal.wsrp.consumer.common.WSRPConsumerConfig;
036: import com.sun.portal.log.common.PortalLogger;
037:
038: /**
039: * This implementation of RSSM is based on StaticRSSMImpl.java. The only difference is that
040: * the endpoint of each port type is controlled by the config parameters set in the
041: * wsrpconsumerconfig.properties. When used in conjunction with TCPTunnel, this implementation
042: * allows developers to snoop into each individual SOAP envelope sent in and out of the WSRP
043: * consumer.
044: * When there is no mapping found in the config, it defaults to StaticRSSMImpl.
045: *
046: * The format of parameters set in the wsrpconsumerconfig.properties is as follows:
047: * tunnel_<target_host>:<target_port>=<listening_host>:<listening_port>
048: *
049: * Sample (please make a note of the character escaping):
050: * .....
051: * soapDebugMethod=tunnel
052: * tunnel_localhost\:80=localhost\:4000
053: * tunnel_portalstandards.oracle.com\:80=localhost\:4001
054: * tunnel_wsrp.dyndns.org\:9081=localhost\:4002
055: * tunnel_wsrp.dyndns.org\:8080=localhost\:4003
056: * tunnel_wsrp.avitek.com\:7001=localhost\:4004
057: * tunnel_andrek.dyndns.org\:80=localhost\:4005
058: * .....
059: */
060:
061: public class TunnelRemoteServiceStubManagerImpl extends
062: StaticRemoteServiceStubManagerImpl {
063:
064: private static Logger logger = PortalLogger
065: .getLogger(TunnelRemoteServiceStubManagerImpl.class);
066:
067: public TunnelRemoteServiceStubManagerImpl() {
068: }
069:
070: public WSRP_v1_Markup_PortType getMarkupPortType(String endpoint,
071: boolean isNew) throws WSRPConsumerException {
072:
073: endpoint = tunnelEndpoint(endpoint);
074: return super .getMarkupPortType(endpoint, isNew);
075: }
076:
077: public WSRP_v1_Registration_PortType getRegistrationPortType(
078: String endpoint) throws WSRPConsumerException {
079:
080: endpoint = tunnelEndpoint(endpoint);
081: return super .getRegistrationPortType(endpoint);
082: }
083:
084: public WSRP_v1_ServiceDescription_PortType getServiceDescriptionPortType(
085: String endpoint) throws WSRPConsumerException {
086:
087: endpoint = tunnelEndpoint(endpoint);
088: return super .getServiceDescriptionPortType(endpoint);
089: }
090:
091: public String getEndpoint(URL producerWsdl, String portBinding)
092: throws WSRPConsumerException {
093:
094: String endpoint = super .getEndpoint(producerWsdl, portBinding);
095: return tunnelEndpoint(endpoint);
096: }
097:
098: public String tunnelEndpoint(String endpoint)
099: throws WSRPConsumerException {
100:
101: if (endpoint == null) {
102: return null;
103: }
104:
105: URL url = null;
106: try {
107: url = new URL(endpoint);
108: } catch (MalformedURLException mue) {
109: throw new WSRPConsumerException(
110: "TunnelRemoteServiceStubManagerImple.tunnelEndpoint(): failed to parse endpoint. ",
111: mue);
112: }
113:
114: URL tURL = null;
115: String key = url.getHost() + ":"
116: + (url.getPort() < 0 ? 80 : url.getPort());
117: String tEndpoint = null;
118:
119: Map tunnelMap = WSRPConsumerConfig.getInstance().getTunnelMap();
120:
121: if (tunnelMap.containsKey(key)) {
122: String hostPort = (String) tunnelMap.get(key);
123: if (!hostPort.startsWith("http://")) {
124: hostPort = "http://" + hostPort;
125: }
126:
127: try {
128: tURL = new URL(hostPort);
129: //
130: // attach filepath
131: //
132: tURL = new URL(url.getProtocol(), tURL.getHost(), tURL
133: .getPort(), url.getFile());
134: } catch (MalformedURLException mue) {
135: throw new WSRPConsumerException(
136: "TunnelRSSMImpl.tunnelEndpoint(): failed to construct url. ",
137: mue);
138: }
139:
140: if (logger.isLoggable(Level.FINEST)) {
141: String[] param = { "tunneling through", tURL.toString() };
142: logger.log(Level.FINEST, "PSWS_CSPWCCI0001");
143: }
144:
145: tEndpoint = tURL.toString();
146:
147: } else {
148:
149: if (logger.isLoggable(Level.SEVERE))
150: logger.log(Level.SEVERE, "PSWS_CSPWCCI0002", key);
151:
152: tEndpoint = endpoint;
153: }
154:
155: return tEndpoint;
156: }
157: }
|