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.List;
016: import java.util.Collection;
017: import java.util.logging.Level;
018: import java.util.logging.Logger;
019:
020: import java.io.IOException;
021: import java.io.FileOutputStream;
022: import java.io.FileNotFoundException;
023:
024: import java.net.URL;
025:
026: import org.xml.sax.InputSource;
027:
028: import javax.xml.rpc.Stub;
029: import javax.xml.rpc.ServiceException;
030:
031: import com.sun.portal.wsrp.common.Timer;
032:
033: import com.sun.portal.wsrp.common.stubs.WSRP_v1_Markup_PortType;
034: import com.sun.portal.wsrp.common.stubs.WSRP_v1_Registration_PortType;
035: import com.sun.portal.wsrp.common.stubs.WSRP_v1_ServiceDescription_PortType;
036: import com.sun.portal.wsrp.common.stubs.WSRP_v1_PortletManagement_PortType;
037:
038: import com.sun.portal.wsrp.common.stubs.WSRPService_Impl;
039:
040: import com.sun.portal.wsrp.consumer.common.RemoteServiceStubManager;
041: import com.sun.portal.wsrp.consumer.common.WSRPConsumerConfig;
042: import com.sun.portal.wsrp.consumer.common.WSRPConsumerException;
043: import com.sun.portal.log.common.PortalLogger;
044:
045: //
046: // TBD: these are internal (non-public) JAXRPC api.
047: // once WSDL parser becomes available, we should swap this out
048: //
049: import com.sun.xml.rpc.wsdl.framework.Extension;
050: import com.sun.xml.rpc.wsdl.parser.WSDLParser;
051: import com.sun.xml.rpc.wsdl.document.WSDLDocument;
052: import com.sun.xml.rpc.wsdl.document.Definitions;
053: import com.sun.xml.rpc.wsdl.document.Service;
054: import com.sun.xml.rpc.wsdl.document.Port;
055: import com.sun.xml.rpc.wsdl.document.soap.SOAPAddress;
056:
057: //
058: // interal JAXRPC api used for debugging
059: //
060: import com.sun.xml.rpc.client.http.HttpClientTransportFactory;
061:
062: /**
063: * This is an implementation that uses JAX-RPC's internal (non-public) API
064: * to parse WSDL and retrieve port endpoint.
065: */
066: public class StaticRemoteServiceStubManagerImpl implements
067: RemoteServiceStubManager {
068:
069: //
070: // debug
071: //
072: private static Logger logger = PortalLogger
073: .getLogger(StaticRemoteServiceStubManagerImpl.class);
074:
075: public WSRP_v1_Markup_PortType getMarkupPortType(String endpoint,
076: boolean isNew) throws WSRPConsumerException {
077:
078: WSRP_v1_Markup_PortType port = null;
079:
080: if (endpoint != null) {
081: port = (WSRP_v1_Markup_PortType) getPortType(
082: MARKUP_PORT_BINDING, endpoint);
083: }
084:
085: if (port == null) {
086: throw new WSRPConsumerException(
087: "StaticRSSM.getMarkupPortType(): Markup endpoint not available. isNew="
088: + isNew);
089: }
090:
091: return port;
092: }
093:
094: public WSRP_v1_Registration_PortType getRegistrationPortType(
095: String endpoint) throws WSRPConsumerException {
096:
097: WSRP_v1_Registration_PortType port = null;
098:
099: if (endpoint != null) {
100: port = (WSRP_v1_Registration_PortType) getPortType(
101: REGISTRATION_PORT_BINDING, endpoint);
102: }
103:
104: return port;
105: }
106:
107: public WSRP_v1_ServiceDescription_PortType getServiceDescriptionPortType(
108: String endpoint) throws WSRPConsumerException {
109:
110: WSRP_v1_ServiceDescription_PortType port = null;
111:
112: if (endpoint != null) {
113: port = (WSRP_v1_ServiceDescription_PortType) getPortType(
114: SERVICE_DESCRIPTION_PORT_BINDING, endpoint);
115: }
116:
117: if (port == null) {
118: throw new WSRPConsumerException(
119: "StaticRSSM.getServiceDescriptionPortType(): Service descrption port not available.");
120: }
121:
122: return port;
123: }
124:
125: public WSRP_v1_PortletManagement_PortType getPortletManagementPortType(
126: String endpoint) throws WSRPConsumerException {
127:
128: WSRP_v1_PortletManagement_PortType port = null;
129:
130: if (endpoint != null) {
131: port = (WSRP_v1_PortletManagement_PortType) getPortType(
132: PORTLET_MANAGEMENT_PORT_BINDING, endpoint);
133: }
134:
135: if (port == null) {
136: throw new WSRPConsumerException(
137: "StaticRSSM.getPortletManagementPortType(): Portlet management port not available.");
138: }
139:
140: return port;
141: }
142:
143: public String getEndpoint(URL producerWsdl, String portBinding)
144: throws WSRPConsumerException {
145:
146: Timer t = new Timer();
147:
148: String endpoint = null;
149:
150: //
151: // TBD: the following code uses internal (non-public) JAXRPC api.
152: // once WSDL parser becomes available, we should swap this out
153: //
154:
155: //
156: // initialize WSDL parser
157: //
158: WSDLParser wp = new WSDLParser();
159: WSDLDocument wd = wp.parse(new InputSource(producerWsdl
160: .toString()), true);
161:
162: if (logger.isLoggable(Level.FINEST)) {
163: Object[] param = { "producerWsdl", producerWsdl };
164: logger.log(Level.FINEST, "PSWS_CSPWCCI0001");
165: param[0] = "elaqpsed time";
166: param[1] = "" + t.getElapsed();
167: }
168:
169: t = new Timer();
170:
171: //
172: // find service
173: //
174: Definitions def = wd.getDefinitions();
175: Service service = null;
176: for (Iterator i = def.services(); i.hasNext();) {
177: Service svc = (Service) i.next();
178: if (svc.getName().equals(WSRP_SERVICE_NAME)) {
179: service = svc;
180: break;
181: }
182: }
183: if (service == null) {
184: throw new WSRPConsumerException(
185: "StaticRSSM.getEndpoint(): failed to find WSRP service from the wsdl. producerWsdl="
186: + producerWsdl.toString());
187: }
188:
189: //
190: // find port
191: //
192: // if no matching port is found, return null
193: //
194: Port port = null;
195: for (Iterator i = service.ports(); i.hasNext();) {
196: Port pt = (Port) i.next();
197: if (pt.getBinding().getLocalPart().equals(portBinding)) {
198: port = pt;
199: break;
200: }
201: }
202:
203: //
204: // retrieve endpoint
205: //
206: if (port != null) {
207: for (Iterator i = port.extensions(); i.hasNext();) {
208: Extension ext = (Extension) i.next();
209: if (ext instanceof SOAPAddress) {
210: SOAPAddress address = (SOAPAddress) ext;
211: endpoint = address.getLocation();
212: }
213: }
214: }
215:
216: if (logger.isLoggable(Level.FINEST)) {
217: String[] param = { "end point took", "" + t.getElapsed() };
218: logger.log(Level.FINEST, "PSWS_CSPWCCI0001", param);
219: }
220:
221: if (logger.isLoggable(Level.FINEST)) {
222: Object[] param = { "producerWsdl", producerWsdl };
223: logger.log(Level.FINEST, "PSWS_CSPWCCI0001", param);
224: param[0] = "endpoint";
225: param[1] = endpoint;
226: logger.log(Level.FINEST, "PSWS_CSPWCCI0001", param);
227: }
228:
229: return endpoint;
230: }
231:
232: protected Stub getPortType(String portBinding, String endpoint)
233: throws WSRPConsumerException {
234:
235: Stub getNonDynamicStub = null;
236:
237: if (endpoint != null) {
238: if (portBinding.equals(MARKUP_PORT_BINDING)) {
239: getNonDynamicStub = (Stub) (new WSRPService_Impl()
240: .getWSRPBaseService());
241:
242: } else if (portBinding
243: .equals(SERVICE_DESCRIPTION_PORT_BINDING)) {
244: getNonDynamicStub = (Stub) (new WSRPService_Impl()
245: .getWSRPServiceDescriptionService());
246: } else if (portBinding.equals(REGISTRATION_PORT_BINDING)) {
247: getNonDynamicStub = (Stub) (new WSRPService_Impl()
248: .getWSRPRegistrationService());
249: } else if (portBinding
250: .equals(PORTLET_MANAGEMENT_PORT_BINDING)) {
251: getNonDynamicStub = (Stub) (new WSRPService_Impl()
252: .getWSRPPortletManagementService());
253: }
254: getNonDynamicStub._setProperty(
255: Stub.ENDPOINT_ADDRESS_PROPERTY, endpoint);
256: }
257:
258: /**
259: * commented out due to jaxrpc bug #5006641
260: *
261: WSRPConsumerConfig config = WSRPConsumerConfig.getInstance();
262: if (config.getSOAPDebugMethod() == config.SOAP_DEBUG_DUMP) {
263: String filename = getSOAPDumpFilename();
264:
265: FileOutputStream fos = null;
266: try {
267: fos = new FileOutputStream(filename, true);
268: } catch (java.io.FileNotFoundException fnf) {
269: throw new WSRPConsumerException("StaticRSSMImpl.getEndpoint(): failed to find log file", fnf);
270: }
271:
272: HttpClientTransportFactory tf = new HttpClientTransportFactory(fos);
273:
274: ((com.sun.xml.rpc.client.StubBase)getNonDynamicStub)._setTransportFactory(tf);
275: }
276: */
277:
278: return getNonDynamicStub;
279: }
280:
281: }
|