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