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.providers.simplewebservice.rpc;
013:
014: import java.net.URL;
015: import java.net.MalformedURLException;
016: import java.util.Iterator;
017: import java.util.ArrayList;
018:
019: import javax.xml.soap.*;
020: import javax.xml.rpc.*;
021: import javax.xml.rpc.soap.SOAPFaultException;
022: import javax.xml.namespace.QName;
023:
024: import com.sun.portal.providers.simplewebservice.SimpleWebServiceParameter;
025: import com.sun.portal.providers.simplewebservice.SimpleWebServiceException;
026: import com.sun.portal.providers.simplewebservice.SimpleWebServiceProcessException;
027: import com.sun.portal.providers.simplewebservice.WebServiceDescriptor;
028: import com.sun.portal.providers.simplewebservice.ParameterDescriptor;
029: import com.sun.portal.providers.simplewebservice.rpc.CallInvoker;
030: import com.sun.portal.providers.simplewebservice.util.XList;
031: import com.sun.portal.providers.simplewebservice.util.SimpleWebServiceUtil;
032: import com.sun.portal.providers.simplewebservice.util.SimpleWebServiceUtilImpl;
033: import com.sun.portal.providers.simplewebservice.util.SWSParameterUtil;
034: import com.sun.xml.rpc.util.StructMap;
035:
036: public class RPCCallInvoker implements CallInvoker {
037:
038: // Invoke Web Service using Document binding style
039: public SimpleWebServiceParameter invokeXBindingStyleWebService(
040: WebServiceDescriptor webServiceDescriptor,
041: SimpleWebServiceParameter[] inputValues, String proxyHost,
042: int proxyPortNumber)
043:
044: throws SimpleWebServiceException {
045:
046: Call call = null;
047:
048: Service service = null;
049: SWSCallFactory callFactory = null;
050:
051: //System.setProperty("http.proxyHost", proxyHost);
052: //System.setProperty("http.proxyPort", (new Integer(proxyPortNumber)).toString());
053:
054: // Create Service and Call. Also, set the Call properties
055: try {
056: ServiceFactory factory = ServiceFactory.newInstance();
057:
058: service = createService(factory, webServiceDescriptor);
059:
060: callFactory = RPCCallFactoryImpl.getInstance();
061:
062: call = callFactory.createCallObject(service,
063: webServiceDescriptor);
064:
065: } catch (ServiceException se) {
066:
067: throw new SimpleWebServiceProcessException(
068: SimpleWebServiceProcessException.ILLEGAL_PARAMETER_ERROR,
069: se.getMessage(), se);
070:
071: } catch (JAXRPCException rpce) {
072:
073: throw new SimpleWebServiceProcessException(
074: SimpleWebServiceProcessException.UNKNOWN_RUNTIME_ERROR,
075: rpce.getMessage(), rpce);
076: }
077:
078: SWSParameterUtil swsParamUtil = SWSParameterUtil.getInstace();
079: // Set the I/O parameters
080: try {
081: swsParamUtil.setIOParameters(call, webServiceDescriptor,
082: inputValues);
083: } catch (JAXRPCException rpce) {
084:
085: throw new SimpleWebServiceProcessException(
086: SimpleWebServiceProcessException.ILLEGAL_PARAMETER_ERROR,
087: rpce.getMessage(), rpce);
088: } catch (IllegalArgumentException ille) {
089:
090: throw new SimpleWebServiceProcessException(
091: SimpleWebServiceProcessException.ILLEGAL_PARAMETER_ERROR,
092: ille.getMessage(), ille);
093: }
094:
095: // Get value objects for input in Call invocation
096: Object objInputValues = null;
097: try {
098: objInputValues = swsParamUtil.getValues(inputValues,
099: webServiceDescriptor);
100: } catch (Exception ex) {
101: throw new SimpleWebServiceProcessException(
102: SimpleWebServiceProcessException.ILLEGAL_PARAMETER_ERROR,
103: ex.getMessage(), ex);
104: }
105:
106: // Invoke Call and get the output. Create SimpleWebServiceParameter
107: // from the obtained return value.
108: try {
109:
110: Object returnValue = null;
111: if (!webServiceDescriptor.isOneWayOperation()) {
112: returnValue = call.invoke((Object[]) objInputValues);
113: } else {
114: call.invokeOneWay((Object[]) objInputValues);
115:
116: }
117:
118: if (returnValue != null) {
119:
120: return swsParamUtil.getSWSPFromResponse(returnValue,
121: webServiceDescriptor);
122:
123: } else {
124: /*throw new SimpleWebServiceProcessException(
125: SimpleWebServiceProcessException.INVOKE_ERROR,
126: "Response could not be obtained. Please try again.");*/
127: if (webServiceDescriptor.getOutputParams().length > 0) {
128: return new SimpleWebServiceParameter(
129: webServiceDescriptor.getOutputParams()[0],
130: (String) null);
131: } else {
132:
133: return null;
134: }
135: }
136: }
137: /*catch(SOAPFaultException soapFaultExcep)
138: {
139: throw new SimpleWebServiceException("SOAP FAULT",
140: soapFaultExcep.getFaultString(),
141: soapFaultExcep.getCause());
142:
143: }*/catch (Exception ex) {
144:
145: throw new SimpleWebServiceProcessException(
146: SimpleWebServiceProcessException.ILLEGAL_PARAMETER_ERROR,
147: ex.getMessage(), ex);
148: }
149: }
150:
151: private Service createService(ServiceFactory factory,
152: WebServiceDescriptor webServiceDescriptor)
153: throws ServiceException {
154:
155: Service service = null;
156:
157: QName serviceQName = new QName(webServiceDescriptor
158: .getServiceName());
159:
160: service = factory.createService(serviceQName);
161:
162: return service;
163: }
164:
165: }
|