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.util.Iterator;
015: import java.util.logging.Level;
016: import java.util.logging.Logger;
017:
018: import java.net.URL;
019:
020: import javax.xml.rpc.Stub;
021: import javax.xml.rpc.Service;
022: import javax.xml.rpc.ServiceException;
023: import javax.xml.rpc.ServiceFactory;
024: import javax.xml.namespace.QName;
025:
026: import com.sun.portal.wsrp.common.stubs.WSRP_v1_Markup_PortType;
027: import com.sun.portal.wsrp.common.stubs.WSRP_v1_Registration_PortType;
028: import com.sun.portal.wsrp.common.stubs.WSRP_v1_ServiceDescription_PortType;
029: import com.sun.portal.wsrp.common.stubs.WSRP_v1_PortletManagement_PortType;
030: import com.sun.portal.wsrp.common.stubs.WSRPService_Impl;
031:
032: import com.sun.portal.wsrp.common.Timer;
033:
034: import com.sun.portal.wsrp.consumer.common.RemoteServiceStubManager;
035: import com.sun.portal.wsrp.consumer.common.WSRPConsumerException;
036: import com.sun.portal.log.common.PortalLogger;
037:
038: /**
039: * This is an implementation that uses JAX-RPC's Dynamic Proxy mechanism
040: * to retrieve endpoint. Currently, due to some unknown reason, this
041: * implementation has a major performance problem.
042: */
043: public class ProxyRemoteServiceStubManagerImpl implements
044: RemoteServiceStubManager {
045:
046: //
047: // TBD: this is a known bug. we should not be looking up port type
048: // by the port name. instead, the binding name should be the
049: // lookup criteria. see WSRP spec. chapter 14.
050: //
051: public final static String MARKUP_PORT_NAME = "WSRPBaseService";
052: public final static String SERVICE_DESCRIPTION_PORT_NAME = "WSRPServiceDescriptionService";
053: public final static String REGISTRATION_PORT_NAME = "WSRPRegistrationService";
054: public final static String PORTLET_MANAGEMENT_PORT_NAME = "WSRPPortletManagementService";
055: public final static String NAMESPACE_URI = "urn:oasis:names:tc:wsrp:v1:wsdl";
056:
057: //
058: // debug
059: //
060: private static Logger logger = PortalLogger
061: .getLogger(ProxyRemoteServiceStubManagerImpl.class);
062:
063: public WSRP_v1_Markup_PortType getMarkupPortType(String endpoint,
064: boolean isNew) throws WSRPConsumerException {
065:
066: WSRP_v1_Markup_PortType port = null;
067:
068: if (endpoint != null) {
069: port = (WSRP_v1_Markup_PortType) getPortType(
070: MARKUP_PORT_NAME, endpoint);
071: }
072:
073: if (port == null) {
074: throw new WSRPConsumerException(
075: "ProxyRSSM.getMarkupPortType(): Markup port type is not available. isNew="
076: + isNew);
077: }
078:
079: return port;
080: }
081:
082: public WSRP_v1_Registration_PortType getRegistrationPortType(
083: String endpoint) throws WSRPConsumerException {
084:
085: WSRP_v1_Registration_PortType port = null;
086:
087: if (endpoint != null) {
088: port = (WSRP_v1_Registration_PortType) getPortType(
089: REGISTRATION_PORT_NAME, endpoint);
090: }
091:
092: return port;
093: }
094:
095: public WSRP_v1_ServiceDescription_PortType getServiceDescriptionPortType(
096: String endpoint) throws WSRPConsumerException {
097:
098: WSRP_v1_ServiceDescription_PortType port = null;
099:
100: if (endpoint != null) {
101: port = (WSRP_v1_ServiceDescription_PortType) getPortType(
102: SERVICE_DESCRIPTION_PORT_NAME, endpoint);
103: }
104:
105: if (port == null) {
106: throw new WSRPConsumerException(
107: "ProxyRSSM.getServiceDescriptionPortType(): Service description port type is not available.");
108: }
109:
110: return port;
111: }
112:
113: public WSRP_v1_PortletManagement_PortType getPortletManagementPortType(
114: String endpoint) throws WSRPConsumerException {
115:
116: WSRP_v1_PortletManagement_PortType port = null;
117:
118: if (endpoint != null) {
119: port = (WSRP_v1_PortletManagement_PortType) getPortType(
120: PORTLET_MANAGEMENT_PORT_NAME, endpoint);
121: }
122:
123: if (port == null) {
124: throw new WSRPConsumerException(
125: "ProxyRSSM.getPortletManagementPortType(): portlet management port type is not available.");
126: }
127:
128: return port;
129: }
130:
131: public String getEndpoint(URL producerWsdl, String portName)
132: throws WSRPConsumerException {
133:
134: Timer t = new Timer();
135:
136: String endpoint = null;
137:
138: Service wsrpService = null;
139: try {
140:
141: ServiceFactory serviceFactory = ServiceFactory
142: .newInstance();
143:
144: QName wsrpServiceQname = new QName(NAMESPACE_URI,
145: WSRP_SERVICE_NAME);
146:
147: //
148: // TBD: this operation takes close to a minute. find out why...
149: //
150: wsrpService = serviceFactory.createService(producerWsdl,
151: wsrpServiceQname);
152:
153: } catch (ServiceException ex) {
154: throw new WSRPConsumerException(
155: "ProxyRSSM.getEndpoint(): failed to find WSRP service from the wsdl. producerWsdl="
156: + producerWsdl.toString(), ex);
157: }
158: if (logger.isLoggable(Level.FINEST)) {
159: Object[] param = { "producerWsdl", producerWsdl };
160: logger.log(Level.FINEST, "PSWS_CSPWCCI0001");
161: param[0] = "elaqpsed time";
162: param[1] = "" + t.getElapsed();
163: }
164:
165: t = new Timer();
166:
167: if (wsrpService == null) {
168: throw new WSRPConsumerException(
169: "ProxyRSSM.getEndpoint(): failed to find WSRP service from the wsdl. producerWsdl="
170: + producerWsdl.toString());
171: }
172:
173: Class portTypeClass = null;
174: if (portName.equals(MARKUP_PORT_NAME)) {
175: portTypeClass = WSRP_v1_Markup_PortType.class;
176: } else if (portName.equals(SERVICE_DESCRIPTION_PORT_NAME)) {
177: portTypeClass = WSRP_v1_ServiceDescription_PortType.class;
178: } else if (portName.equals(REGISTRATION_PORT_NAME)) {
179: portTypeClass = WSRP_v1_Registration_PortType.class;
180: }
181:
182: //
183: // TBD: this is a known bug. we should not be looking up port type
184: // by the port name. instead, the binding name should be the
185: // lookup criteria. see WSRP spec. chapter 14.
186: // JAXRPC currently does not allow such mechanism so we use the
187: // name.
188: //
189: try {
190: Stub port = (Stub) wsrpService.getPort(new QName(
191: NAMESPACE_URI, portName), portTypeClass);
192: if (port != null) {
193: endpoint = (String) port
194: ._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY);
195: }
196:
197: } catch (ServiceException ex) {
198: //
199: // producer can opt to not expose registration port type in
200: // case of out-of-band registration. handle it gracefully.
201: //
202: if (!portName.equals(REGISTRATION_PORT_NAME)) {
203: throw new WSRPConsumerException(
204: "ProxyRSSM.getEndpoint(): failed to find endpoint from the wsdl. producerWsdl="
205: + producerWsdl.toString()
206: + ", portName=" + portName, ex);
207: }
208: }
209:
210: if (logger.isLoggable(Level.FINEST)) {
211: String[] param = { "end point took", "" + t.getElapsed() };
212: logger.log(Level.FINEST, "PSWS_CSPWCCI0001", param);
213: }
214:
215: if (logger.isLoggable(Level.FINEST)) {
216: Object[] param = { "producerWsdl", producerWsdl };
217: logger.log(Level.FINEST, "PSWS_CSPWCCI0001", param);
218: param[0] = "endpoint";
219: param[1] = endpoint;
220: logger.log(Level.FINEST, "PSWS_CSPWCCI0001", param);
221: }
222:
223: return endpoint;
224: }
225:
226: protected Stub getPortType(String portBinding, String endpoint)
227: throws WSRPConsumerException {
228:
229: Stub getNonDynamicStub = null;
230:
231: if (endpoint != null) {
232: if (portBinding.equals(MARKUP_PORT_NAME)) {
233: getNonDynamicStub = (Stub) (new WSRPService_Impl()
234: .getWSRPBaseService());
235: } else if (portBinding
236: .equals(SERVICE_DESCRIPTION_PORT_NAME)) {
237: getNonDynamicStub = (Stub) (new WSRPService_Impl()
238: .getWSRPServiceDescriptionService());
239: } else if (portBinding.equals(REGISTRATION_PORT_NAME)) {
240: getNonDynamicStub = (Stub) (new WSRPService_Impl()
241: .getWSRPRegistrationService());
242: } else if (portBinding.equals(PORTLET_MANAGEMENT_PORT_NAME)) {
243: getNonDynamicStub = (Stub) (new WSRPService_Impl()
244: .getWSRPPortletManagementService());
245: }
246: getNonDynamicStub._setProperty(
247: Stub.ENDPOINT_ADDRESS_PROPERTY, endpoint);
248: }
249:
250: return getNonDynamicStub;
251: }
252: }
|