0001: /**
0002: * $Id: SimpleWebServiceProviderAdapter.java,v 1.20 2005/09/21 10:41:56 dg154973 Exp $
0003: * Copyright 2002-2003 Sun Microsystems, Inc. All
0004: * rights reserved. Use of this product is subject
0005: * to license terms. Federal Acquisitions:
0006: * Commercial Software -- Government Users
0007: * Subject to Standard License Terms and
0008: * Conditions.
0009: *
0010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
0011: * are trademarks or registered trademarks of Sun Microsystems,
0012: * Inc. in the United States and other countries.
0013: */package com.sun.portal.providers.simplewebservice;
0014:
0015: import java.util.HashMap;
0016: import java.util.Map;
0017: import java.util.Iterator;
0018: import java.util.logging.Level;
0019: import java.util.logging.Logger;
0020: import java.util.logging.LogRecord;
0021: import java.net.URL;
0022:
0023: import javax.servlet.http.HttpServletRequest;
0024: import javax.servlet.http.HttpServletResponse;
0025:
0026: import com.sun.portal.providers.ProviderException;
0027: import com.sun.portal.providers.jsp.JSPProvider;
0028:
0029: import com.sun.portal.providers.simplewebservice.util.XList;
0030: import com.sun.portal.log.common.PortalLogger;
0031:
0032: /**
0033: * The Simple Web Service Provider is a specialized content Provider that
0034: * facilitates the mechanism to dynamically construct the front end UI for
0035: * interaction with relatively simple SOAP based web services targeted by
0036: * an end user.
0037: * <P>
0038: *
0039: * Minimally, given the WSDL URL and the name of the Method to be invoked
0040: * on the web service, the Simple Web Service Provider fetches and parses
0041: * the WSDL file, and then based on the content of the WSDL, dynamically
0042: * generates the input UI that will allow the user to supply values for
0043: * the input parameters required by the web service. Upon submission of
0044: * the input form, the Provider invokes the designated method on the web
0045: * service and subsequently renders the UI displaying the results received
0046: * back from the web service.
0047: * <P>
0048: *
0049: * Channels based on the Simple Web Service Provider are of the following
0050: * two types -
0051: * <UL>
0052: * <LI>
0053: * Pre configured Simple Web Service Provider channel - The pre configured
0054: * channel type is bound to a specific web service (e.g. a Stock Quote web
0055: * service) and associated method by the Administrator, and is available
0056: * for addition to the desktop by the end user. The values of the web service
0057: * WSDL URL and method name configuration parameters is meant to be pre configured
0058: * by the Administrator. The pre configured channel type provides the facility
0059: * for the user to store default values for the web service input parameters
0060: * via the "edit" menu selection on the channel UI.
0061: * <LI>
0062: * Configurable Simple Web Service Provider channel - The configurable channel
0063: * type allows the end user to switch the channel to point to other web
0064: * services (and their associated methods). This is achieved by allowing
0065: * the end user the capability to modify values for the WSDL URL and the web
0066: * service method name from the "edit" menu option on the channel UI. However,
0067: * unlike the pre configured channel type, the configurable type does not
0068: * allow the user to store any default values for the web service input
0069: * parameters.
0070: * </UL>
0071: * <P>
0072: *
0073: * Both the pre configured and configurable Simple Web Service Provider channel
0074: * types include a configuration property that will specify the "default view"
0075: * that is to be display when the desktop is initially rendered or refreshed.
0076: * The "default view" can either be set to the web service input form or the
0077: * view showing the web service output UI.
0078: * <P>
0079: *
0080: * The SimpleWebServiceProviderAdapter class is an abstract sub-class of
0081: * the JSPProvider that facilitates the basic framework required to invoke
0082: * a given method on a remote SOAP based web service.
0083: * <P>
0084: *
0085: * The SimpleWebServiceProviderAdapter class has one abstract method "invokeMethod".
0086: * Given the relevant information required to invoke a method on the Web Service, a
0087: * sub-class should implement this method using an appropriate SOAP implementation.
0088: * <P>
0089: *
0090: * By default, the Simple Web Service Provider makes use of the JAXRPC
0091: * runtime to make calls to remote web services.
0092: * <P>
0093: *
0094: * The SimpleWebServiceProviderAdapter provides built-in capabilities for
0095: * generic tasks such as -
0096: * <UL>
0097: * <LI> Managing Web Services related display profile properties such as the
0098: * WSDL URL, method name, etc.
0099: * <LI> Defining the input/output variables needed to invoke the designated
0100: * web service method.
0101: * <LI> Storing and retrieving the default input values in the profile database.
0102: * <LI> Storing and retrieving the state for the provider.
0103: * </UL>
0104: * <P>
0105: *
0106: * Some of the classes used by the SimpleWebServiceProviderAdapter are:
0107: * <BR>
0108: * SimpleWebServiceParameter - to encapsulate an input or output parameter
0109: * for a web service method defined in a WSDL.
0110: * <BR>
0111: * SimpleWebServiceState class to store the state of the Provider instance.
0112: * <BR>
0113: * SimpleWebServiceException and its subclasses to throw fine grained exceptions.
0114: * <P>
0115: *
0116: * The SimpleWebServiceProviderAdapter uses an instance variable of type
0117: * SimpleWebServiceState to store the state of the provider instance. The
0118: * logic in processRequest(request) method decides whether to use the
0119: * information from the request object, or the last state, or default parameters
0120: * obtained from the profile storage to provide results to the content jsp
0121: * (default is webserviceContent.jsp).
0122: * <P>
0123: *
0124: * For editing, an overridden processEdit method, checks for the request
0125: * parameter "editContent". If the value is EDIT_DEFAULT_WSDL_URL, the method
0126: * tries to save the new wsdl/methodname from the request object. If the
0127: * value is EDIT_DEFAULT_INPUT, it tries to save the default input parameter
0128: * values for the already configured WSDL and methodname. State is reset
0129: * everytime any of the display profile properties are changed through this
0130: * method.
0131: *
0132: *
0133: * <P><B>Proxy Configuration</B><BR>
0134: * A Simple Web Service Provider uses a proxy to make calls to the remote web service
0135: * if the proxy is set in the jvm12.conf file for web server
0136: * For Example the proxy can be set as
0137: * <CODE>http.proxyHost=<proxyHost></CODE><BR>
0138: * <CODE>http.proxyPort=<proxyPort></CODE>
0139: * <P>
0140: *
0141: * @see SimpleWebServiceParameter
0142: * @see SimpleWebServiceState
0143: * @see SimpleWebServiceException
0144: * @see SimpleWebServiceProcessException
0145: * @see XList
0146: */
0147: abstract public class SimpleWebServiceProviderAdapter extends
0148: JSPProvider {
0149:
0150: private static Logger logger = PortalLogger
0151: .getLogger(SimpleWebServiceProviderAdapter.class);
0152: /*
0153: * Display Profile Properties
0154: */
0155: public static final String DP_WSDL_URL = "wsdlURL";
0156: public static final String DP_METHOD_NAME = "methodName";
0157: public static final String DP_IS_DEFAULT_SHOW_OUTPUT = "isDefaultShowOutput";
0158: public static final String DP_IS_DEFAULT_AVAILABLE = "isDefaultAvailable";
0159: public static final String DP_DEFAULT_INPUT = "defaultInput";
0160: public static final String DP_CACHE_TIME_OUT = "descriptorCacheTimeOut";
0161:
0162: /*
0163: * Value of a request parameter "editContent",that the processEdit() method
0164: * looks for to find out what needs to be updated in the display profile.
0165: */
0166: public static final String EDIT_DEFAULT_INPUT = "edit_input";
0167: public static final String EDIT_DEFAULT_WSDL_URL = "edit_wsdlurl";
0168:
0169: /*
0170: * State saved that is used for refreshes.
0171: */
0172: private SimpleWebServiceState _lastSavedState = null;
0173: private boolean _needInputState = false;
0174:
0175: // ab jan24 -- set the cache timeout to a suitable value
0176: // 10 minutes
0177: private static final int CACHE_TIME_OUT = 600;
0178: public static final int NO_CACHE_TIME_OUT_SPECIFIED = -1;
0179:
0180: /**
0181: * Gets the URL for the configured WSDL from the profile store.
0182: * <P>
0183: *
0184: * @return the WSDL URL.
0185: *
0186: * @throws ProviderException if there were problems obtaining the WSDL URL.
0187: */
0188: public String getWSDL() throws ProviderException {
0189: return getStringProperty(DP_WSDL_URL);
0190: }
0191:
0192: /**
0193: * Gets the configured web service method name from the profile store.
0194: * <P>
0195: *
0196: * @return the web service method name.
0197: *
0198: * @throws ProviderException if there was a problem getting the method name.
0199: */
0200: public String getMethodName() throws ProviderException {
0201: return getStringProperty(DP_METHOD_NAME);
0202: }
0203:
0204: /**
0205: * Gets the time-out value for the WebServiceDescriptor cache from the profile store.
0206: * <P>
0207: *
0208: * @return the int value (secs) of WebServiceDescriptor cache time-out.
0209: *
0210: * @throws ProviderException if there was a problem getting the WebServiceDescriptor cache time-out.
0211: */
0212: public int getDescriptorCacheTimeOut() throws ProviderException {
0213: if (existsIntegerProperty(DP_CACHE_TIME_OUT)) {
0214: return getIntegerProperty(DP_CACHE_TIME_OUT);
0215: } else {
0216: return CACHE_TIME_OUT;
0217: }
0218: }
0219:
0220: /**
0221: * Gets the value of DP_IS_DEFAULT_SHOW_OUTPUT from the profile database. If
0222: * value is true, the Provider uses the default input values (if available)
0223: * from the profile database to invoke the web service method. If false, the
0224: * JSP shows the form prompting the user for input values.
0225: * <P>
0226: *
0227: * @return true if DP_IS_DEFAULT_SHOW_OUTPUT is true, false if not.
0228: *
0229: * @throws ProviderException if there was a problem getting the property.
0230: */
0231: public boolean isDefaultShowOutput() throws ProviderException {
0232: return getBooleanProperty(DP_IS_DEFAULT_SHOW_OUTPUT);
0233: }
0234:
0235: /**
0236: * Gets the boolean value from the profile database. Value of true indicates
0237: * that default input data is available from the profile database at this
0238: * time.
0239: * <P>
0240: *
0241: * @return true if DP_IS_DEFAULT_AVAILABLE is true, false if not.
0242: *
0243: * @throws ProviderException if there was a problem getting the property.
0244: */
0245: public boolean isDefaultAvailable() throws ProviderException {
0246: return getBooleanProperty(DP_IS_DEFAULT_AVAILABLE);
0247: }
0248:
0249: /**
0250: * This method returns an array of SimpleWebServiceParameters. There is 1-to-1
0251: * correspondence between the array elements and variables defined for the
0252: * web service method to be called.
0253: * <P>
0254: * This method is used by JSPs to render the proper UI for input values.
0255: * This method is also used by other methods in the provider to read
0256: * input from Request or Profile.
0257: * <P>
0258: *
0259: * @return an array of SimpleWebServiceParameters.
0260: *
0261: * @throws ProviderException if there was a generic Provider error.
0262: * @throws SimpleWebServiceException if there was an error associated
0263: * with the web service.
0264: */
0265: public SimpleWebServiceParameter[] defineInputForWebService(
0266: HttpServletRequest req) throws ProviderException,
0267: SimpleWebServiceException {
0268:
0269: //--------------------------------------------
0270: // Return meta-data with default values if available
0271: int childCount = 1;
0272: if (isDefaultAvailable()) {
0273: return readInputFromDefault();
0274: } else {
0275: ParameterDescriptor[] paramDescriptors = getWebServiceDescriptor()
0276: .getInputParams();
0277:
0278: SimpleWebServiceParameter[] inputParam = new SimpleWebServiceParameter[paramDescriptors.length];
0279:
0280: for (int i = 0; paramDescriptors != null
0281: && i < paramDescriptors.length; i++) {
0282:
0283: if (paramDescriptors[i].getType().equals(XList.class)) {
0284:
0285: String targetNameSpace = ((XList) paramDescriptors[i]
0286: .getValue()).getTargetNameSpace();
0287: String complexTypeName = ((XList) paramDescriptors[i]
0288: .getValue()).getComplexTypeName();
0289:
0290: XList xlist = new XList(complexTypeName,
0291: targetNameSpace);
0292:
0293: recursiveDefineInputForWebService(
0294: paramDescriptors[i], xlist, req);
0295:
0296: inputParam[i] = new SimpleWebServiceParameter(
0297: paramDescriptors[i], xlist);
0298: } else {
0299: inputParam[i] = new SimpleWebServiceParameter(
0300: paramDescriptors[i], (String) null);
0301: }
0302: }
0303:
0304: return inputParam;
0305: }
0306: }
0307:
0308: public SimpleWebServiceParameter[] defineInputForWebService()
0309: throws ProviderException, SimpleWebServiceException {
0310:
0311: //--------------------------------------------
0312: // Return meta-data with default values if available
0313: int childCount = 1;
0314: if (isDefaultAvailable()) {
0315: return readInputFromDefault();
0316: } else {
0317: ParameterDescriptor[] paramDescriptors = getWebServiceDescriptor()
0318: .getInputParams();
0319:
0320: SimpleWebServiceParameter[] inputParam = new SimpleWebServiceParameter[paramDescriptors.length];
0321:
0322: for (int i = 0; paramDescriptors != null
0323: && i < paramDescriptors.length; i++) {
0324:
0325: if (paramDescriptors[i].getType().equals(XList.class)) {
0326:
0327: String targetNameSpace = ((XList) paramDescriptors[i]
0328: .getValue()).getTargetNameSpace();
0329: String complexTypeName = ((XList) paramDescriptors[i]
0330: .getValue()).getComplexTypeName();
0331:
0332: XList xlist = new XList(complexTypeName,
0333: targetNameSpace);
0334:
0335: recursiveDefineInputForWebService(
0336: paramDescriptors[i], xlist);
0337:
0338: inputParam[i] = new SimpleWebServiceParameter(
0339: paramDescriptors[i], xlist);
0340: } else {
0341: inputParam[i] = new SimpleWebServiceParameter(
0342: paramDescriptors[i], (String) null);
0343: }
0344: }
0345:
0346: return inputParam;
0347: }
0348: }
0349:
0350: /**
0351: * This method returns an array of SimpleWebServiceParameters. There is 1-to-1
0352: * correspondence between the array elements and variables defined for the
0353: * web service method to be called.
0354: * <P>
0355: * This method is used by JSPs to render the proper UI for input values.
0356: * This method is also used by other methods in the provider to read
0357: * input from Request or Profile.
0358: * <P>
0359: *
0360: * @return an array of SimpleWebServiceParameters.
0361: *
0362: * @throws ProviderException if there was a generic Provider error.
0363: * @throws SimpleWebServiceException if there was an error associated
0364: * with the web service.
0365: */
0366:
0367: /**
0368: * This method reads the input values for a web service method from an servlet
0369: * request and stores them as default values in the profile database. It is
0370: * called by webserviceInputDoEdit.jsp
0371: * <P>
0372: *
0373: * @param req the HttpServletRequest
0374: * @throws ProviderException if there was a generic Provider error.
0375: * @throws SimpleWebServiceException if there was an error associated with the
0376: * web service.
0377: */
0378: public void saveInputAsDefault(HttpServletRequest req)
0379: throws ProviderException, SimpleWebServiceException {
0380:
0381: ParameterDescriptor[] paramDescriptors = getWebServiceDescriptor()
0382: .getInputParams();
0383:
0384: HashMap map = new HashMap();
0385:
0386: for (int i = 0; paramDescriptors != null
0387: && i < paramDescriptors.length; i++) {
0388: logger.log(Level.FINEST, "PSCR_CSPPS0001", new Object[] {
0389: i + "", paramDescriptors[i].getName() });
0390: recursiveSaveInputAsDefault(req, paramDescriptors[i], map);
0391: }
0392:
0393: setBooleanProperty(DP_IS_DEFAULT_AVAILABLE, true);
0394: setMapProperty(DP_DEFAULT_INPUT, map);
0395: }
0396:
0397: /**
0398: * This method reads the input values for a web service method and returns
0399: * them as an array of SimpleWebServiceParameter.
0400: *
0401: * @param req
0402: * @exception com.sun.portal.providers.ProviderException
0403: * @exception com.sun.portal.providers.simplewebservice.SimpleWebServiceException
0404: */
0405:
0406: protected SimpleWebServiceParameter[] readInputFromRequest(
0407: HttpServletRequest req) throws ProviderException,
0408: SimpleWebServiceException {
0409:
0410: //----------------------------------------------------------
0411: // Fill in the values for each parameter from the
0412: // request object if available.
0413:
0414: ParameterDescriptor[] paramDescriptors = getWebServiceDescriptor()
0415: .getInputParams();
0416:
0417: SimpleWebServiceParameter[] inputParam = new SimpleWebServiceParameter[paramDescriptors.length];
0418:
0419: for (int i = 0; paramDescriptors != null
0420: && i < paramDescriptors.length; i++) {
0421:
0422: if (paramDescriptors[i].getType().equals(XList.class)) {
0423:
0424: String targetNameSpace = ((XList) paramDescriptors[i]
0425: .getValue()).getTargetNameSpace();
0426: String complexTypeName = ((XList) paramDescriptors[i]
0427: .getValue()).getComplexTypeName();
0428:
0429: XList xlist = new XList(complexTypeName,
0430: targetNameSpace);
0431:
0432: recursiveReadInputFromRequest(req, paramDescriptors[i],
0433: xlist);
0434: inputParam[i] = new SimpleWebServiceParameter(
0435: paramDescriptors[i], xlist);
0436: } else {
0437: String valueString = req
0438: .getParameter(makeUniqueStr(paramDescriptors[i]
0439: .getName()));
0440:
0441: inputParam[i] = new SimpleWebServiceParameter(
0442: paramDescriptors[i], valueString);
0443:
0444: }
0445: }
0446:
0447: return inputParam;
0448: }
0449:
0450: /**
0451: * This method reads input values for a web service method from the profile database and returns them as
0452: * an array of SimpleWebServiceParameter.
0453: *
0454: * @exception com.sun.portal.providers.ProviderException
0455: * @exception com.sun.portal.providers.simplewebservice.SimpleWebServiceException
0456: */
0457: protected SimpleWebServiceParameter[] readInputFromDefault()
0458: throws ProviderException, SimpleWebServiceException {
0459:
0460: //----------------------------------------------------------
0461: // Fill in the values for each parameter from the
0462: // request object if available.
0463:
0464: Map map = getMapProperty(DP_DEFAULT_INPUT);
0465:
0466: //----------------------------------------------------------
0467: // Fill in the values for each parameter from the
0468: // map object if available.
0469:
0470: ParameterDescriptor[] paramDescriptors = getWebServiceDescriptor()
0471: .getInputParams();
0472: SimpleWebServiceParameter[] inputParam = new SimpleWebServiceParameter[paramDescriptors.length];
0473:
0474: for (int i = 0; paramDescriptors != null
0475: && i < paramDescriptors.length; i++) {
0476:
0477: if (paramDescriptors[i].getType().equals(XList.class)) {
0478:
0479: String targetNameSpace = ((XList) paramDescriptors[i]
0480: .getValue()).getTargetNameSpace();
0481: String complexTypeName = ((XList) paramDescriptors[i]
0482: .getValue()).getComplexTypeName();
0483:
0484: XList xlist = new XList(complexTypeName,
0485: targetNameSpace);
0486:
0487: recursiveReadInputFromDefault((Map) map
0488: .get(paramDescriptors[i].getName()),
0489: paramDescriptors[i], xlist);
0490: inputParam[i] = new SimpleWebServiceParameter(
0491: paramDescriptors[i], xlist);
0492: } else {
0493:
0494: // sy30/03/03 - Bug from previous code.
0495: // Should not be cast to String as data might be int or boolean or collection
0496: //
0497: //String valueString =
0498: // (String)map.get(paramDescriptors[i].getName());
0499: //inputParam[i] = new SimpleWebServiceParameter(
0500: // paramDescriptors[i],
0501: // valueString);
0502:
0503: Object objValue = map
0504: .get(paramDescriptors[i].getName());
0505: inputParam[i] = new SimpleWebServiceParameter(
0506: paramDescriptors[i], objValue.toString());
0507: }
0508: }
0509:
0510: return inputParam;
0511: }
0512:
0513: /**
0514: * This method is called by the webserviceContent.jsp to find out if it should
0515: * prompt the user for input by showing an input form or if it should show the results. This
0516: * method uses the stored state and request parameter "myProvider" & "invokeService" to
0517: * decide what needs to be rendered.
0518: * <P>
0519: *
0520: * @param request the HttpServletRequest
0521: * @throws ProviderException if there was a generic Provider error.
0522: */
0523: public boolean showInputForm(HttpServletRequest request)
0524: throws ProviderException {
0525:
0526: String invokeAction = request
0527: .getParameter(makeUniqueStr("invokeAction"));
0528:
0529: //--------------------------------------------
0530: // Decision is the combination of hidden parameter invokeAction,
0531: // last state parameters(_needInputState & _lastSavedState)
0532: // and availability of defaults.
0533: // The decision making is easy if the invokeAction parameter is true or false.
0534: //
0535: // The interesting case is when this parameter is not present. This parameter is absent in the cases of
0536: // refresh and the first time around when the desktop is displayed.
0537: // In that case, if there is a a lastSavedState avaialable to use, then it will be used to refresh.
0538: // If there is no last saved state, another state variable _needInputState is checked. This variable is set to the output
0539: // of this method. If this flag is found true ( because of previous run), input form is shown. By default it is set
0540: // to false. If it is found as false, the logic checks if there are defaults available to run the service.
0541: // If they are available, they are used to invoke the service, else form is shown.
0542:
0543: if (invokeAction == null) {
0544:
0545: if (_lastSavedState == null) {
0546: if (_needInputState == true) {
0547: //
0548: // redundant, but there for clarity(right :-)
0549:
0550: _needInputState = true;
0551: } else {
0552: if (isDefaultShowOutput() && isDefaultAvailable()) {
0553: _needInputState = false;
0554: } else {
0555: _needInputState = true;
0556: }
0557: }
0558: } else {
0559: _needInputState = false;
0560: }
0561: } else if (invokeAction.equals("false")) {
0562: _lastSavedState = null;
0563: _needInputState = true;
0564: } else if (invokeAction.equals("true")) {
0565: _needInputState = false;
0566: }
0567:
0568: return _needInputState;
0569:
0570: }
0571:
0572: /**
0573: * This method is called by webserviceContent.jsp to get the results to be
0574: * rendered on the page. This method uses logic to find out whether the results are to
0575: * be produced using 1) stored state 2) request parameter or 3) default input parameters.
0576: * In case of 2) and 3), this method calls the abstract method invokeWebService()
0577: * to actually invoke the web service.
0578: * <P>
0579: *
0580: * @param request the HttpServletRequest.
0581: * @return the state of the web service.
0582: * @throws ProviderException if there was a generic Provider error.
0583: * @throws SimpleWebServiceException if there was an error associated
0584: * with the web service.
0585: */
0586: public SimpleWebServiceState processRequest(
0587: HttpServletRequest request) throws ProviderException,
0588: SimpleWebServiceException {
0589:
0590: SimpleWebServiceParameter[] input = null;
0591: SimpleWebServiceParameter output = null;
0592: SimpleWebServiceState result = null;
0593: SimpleWebServiceProcessException runError = null;
0594:
0595: try {
0596:
0597: if ((request.getParameter("myProvider") != null)
0598: && request.getParameter("myProvider").equals(
0599: getName())) {
0600: logger.log(Level.FINEST, "PSCR_CSPPS0002",
0601: new Object[] { getName(), toString() });
0602: input = readInputFromRequest(request);
0603: output = invokeWebService(input);
0604: } else if (_lastSavedState != null) {
0605: logger.log(Level.FINEST, "PSCR_CSPPS0003",
0606: new Object[] { getName(), toString() });
0607: result = _lastSavedState;
0608: } else if (isDefaultShowOutput() && isDefaultAvailable()) {
0609: logger.log(Level.FINEST, "PSCR_CSPPS0004",
0610: new Object[] { getName(), toString() });
0611: input = readInputFromDefault();
0612: output = invokeWebService(input);
0613: }
0614: } catch (SimpleWebServiceProcessException ex) {
0615: runError = ex;
0616: }
0617:
0618: if (result == null) {
0619: result = new SimpleWebServiceState(input, output, runError);
0620: }
0621:
0622: _lastSavedState = result;
0623: return result;
0624:
0625: }
0626:
0627: /**
0628: * This method prepends a string with the name of the channel to make a unique name
0629: * that can be used in an input form rendered by webserviceContent.jsp.
0630: * <P>
0631: *
0632: * @param name the name of the channel.
0633: * @return the unique name to use for the channel.
0634: */
0635: public String makeUniqueStr(String name) {
0636: return getName() + "_" + name;
0637: }
0638:
0639: /**
0640: * This method fetches an instance of WebServiceDescriptor from
0641: * the WebServiceDescriptor factory. It throws an Provider Exception if the
0642: * web service uses features not (yet) supported by this web service.
0643: *
0644: * @exception com.sun.portal.providers.ProviderException
0645: * @exception com.sun.portal.providers.simplewebservice.SimpleWebServiceException
0646: */
0647: protected WebServiceDescriptor getWebServiceDescriptor()
0648: throws ProviderException, SimpleWebServiceException {
0649:
0650: WebServiceDescriptor descriptor = null;
0651: int cacheTimeOut = CACHE_TIME_OUT;
0652:
0653: try {
0654: cacheTimeOut = getDescriptorCacheTimeOut();
0655: } catch (Exception ex) {
0656: if (logger.isLoggable(Level.INFO)) {
0657: LogRecord record = new LogRecord(Level.INFO,
0658: "PSCR_CSPPS0005");
0659: record.setLoggerName(logger.getName());
0660: record.setParameters(new Object[] { getName() });
0661: record.setThrown(ex);
0662: logger.log(record);
0663: }
0664: cacheTimeOut = CACHE_TIME_OUT;
0665: }
0666:
0667: try {
0668: descriptor = WebServiceDescriptorFactory.getFactory()
0669: .getWebServiceDescriptor(getWSDL(),
0670: getMethodName(), cacheTimeOut);
0671: } catch (WebServiceDescriptorException ex) {
0672:
0673: String errorMsg = null;
0674:
0675: if (logger.isLoggable(Level.INFO)) {
0676: LogRecord record = new LogRecord(Level.INFO,
0677: "PSCR_CSPPS0005");
0678: record.setLoggerName(logger.getName());
0679: record.setParameters(new Object[] { getName() });
0680: record.setThrown(ex);
0681: logger.log(record);
0682: }
0683: if (ex.getFaultCode().equals(
0684: WebServiceDescriptorException.INVALID_URL)) {
0685:
0686: errorMsg = getResourceBundle().getString(
0687: "invalidUrlErr");
0688: } else if (ex.getFaultCode().equals(
0689: WebServiceDescriptorException.INVALID_WSDL)) {
0690:
0691: errorMsg = getResourceBundle().getString(
0692: "invalidWsdlErr");
0693: } else if (ex.getFaultCode().equals(
0694: WebServiceDescriptorException.UNSUPPORTED_WSDL)) {
0695:
0696: errorMsg = getResourceBundle().getString(
0697: "unSupportedWSDL");
0698: } else {
0699: errorMsg = getResourceBundle()
0700: .getString("wsdlOtherErr");
0701: }
0702: throw new SimpleWebServiceException(
0703: SimpleWebServiceException.WSDL_DESCRIPTOR_ERROR,
0704: errorMsg, ex);
0705: }
0706:
0707: validateFunctionalitySupport(descriptor);
0708:
0709: return descriptor;
0710: }
0711:
0712: /**
0713: * Throws an ProviderException if the WSDL (as represented by given instance of WebServiceDescriptor)
0714: * requires functonality not supported by his provider.
0715: *
0716: * @param descriptor the web service descriptor that contains all the meta information about the web service.
0717: * @throws ProviderException if there was a generic Provider error.
0718: * @throws SimpleWebServiceException if there was an error associated
0719: * with the web service.
0720: */
0721: public void validateFunctionalitySupport(
0722: WebServiceDescriptor descriptor)
0723: throws SimpleWebServiceException, ProviderException {
0724:
0725: StringBuffer notSupportedMessage = new StringBuffer();
0726:
0727: String soapBindingStyle = descriptor.getSOAPBindingStyle();
0728: String inputEncodingStyle = descriptor.getInputEncodingStyle();
0729: String outputEncodingStyle = descriptor
0730: .getOutputEncodingStyle();
0731:
0732: if (soapBindingStyle != null) {
0733: if (soapBindingStyle
0734: .equals(WebServiceDescriptor.DOCUMENT_SOAP_BINDING_STYLE)) {
0735: if (inputEncodingStyle != null
0736: && outputEncodingStyle != null) {
0737: if (!inputEncodingStyle
0738: .equals(WebServiceDescriptor.ENC_LITERAL)
0739: && !outputEncodingStyle
0740: .equals(WebServiceDescriptor.ENC_LITERAL)) {
0741: notSupportedMessage
0742: .append("\nOnly literal encoding supported for document soap binding style");
0743: }
0744: }
0745: } else if (soapBindingStyle
0746: .equals(WebServiceDescriptor.RPC_SOAP_BINDING_STYLE)) {
0747: if (inputEncodingStyle != null
0748: && outputEncodingStyle != null) {
0749: if (!inputEncodingStyle
0750: .equals(WebServiceDescriptor.ENC_ENCODED)
0751: && !outputEncodingStyle
0752: .equals(WebServiceDescriptor.ENC_ENCODED)) {
0753: notSupportedMessage
0754: .append("\nOnly encoded encoding supported for rpc soap binding style");
0755: }
0756: }
0757: } else {
0758: notSupportedMessage
0759: .append(
0760: "\nOnly soap binding with rpc or document style supported: ")
0761: .append(soapBindingStyle);
0762: }
0763: }
0764:
0765: if (notSupportedMessage.length() != 0) {
0766: logger.log(Level.FINE, "PSCR_CSPPS0006", new Object[] {
0767: getName(), notSupportedMessage.toString() });
0768:
0769: throw new SimpleWebServiceException(
0770: SimpleWebServiceException.FUNCTIONALITY_NOT_SUPPORTED,
0771: getResourceBundle().getString(
0772: "functionalityNotSupportedErr"));
0773: }
0774: }
0775:
0776: /**
0777: * Overridden processEdit method, checks for the request parameter
0778: * "editContent". Based on the value of this parameter. If the value is EDIT_DEFAULT_WSDL_URL,
0779: * the method tries to save the new wsdl/methodname from the request object,
0780: * If the value is EDIT_DEFAULT_INPUT, it tries to save the default input parameter values for
0781: * already configured wsdl and methodname. State is reset everytime,
0782: * any of the display profile properties are changed through this method.
0783: * <P>
0784: *
0785: * @param request the HttpServletRequest.
0786: * @param res the HttpServletResponse.
0787: * @throws ProviderException if there was a generic Provider error.
0788: */
0789: public URL processEdit(HttpServletRequest request,
0790: HttpServletResponse res) throws ProviderException {
0791:
0792: String editContent = request.getParameter("editContent");
0793: try {
0794: if (editContent.equals(EDIT_DEFAULT_INPUT)) {
0795: saveInputAsDefault(request);
0796: } else if (editContent.equals(EDIT_DEFAULT_WSDL_URL)) {
0797: String wsdl = request
0798: .getParameter("simpleWebService-wsdl");
0799: String methodName = request
0800: .getParameter("simpleWebService-methodName");
0801:
0802: if (wsdl != null) {
0803: wsdl = wsdl.trim();
0804: }
0805: if (methodName != null) {
0806: methodName = methodName.trim();
0807: }
0808:
0809: setStringProperty(DP_WSDL_URL, wsdl);
0810: setStringProperty(DP_METHOD_NAME, methodName);
0811: }
0812:
0813: // Reset the state, since defaults changed
0814: _lastSavedState = null;
0815: _needInputState = false;
0816: } catch (SimpleWebServiceException ex) {
0817: throw new ProviderException("Problem in parsing WSDL", ex);
0818: }
0819:
0820: return null;
0821: }
0822:
0823: /**
0824: * /***********************************************************************
0825: * START OF SOME RECURSIVE HELPER METHODS TO READ NESTED COMPLEX DATA
0826: * All the four recursive private methods are use to populate information in and out
0827: * of nested parameters. While storing the information in the SimpleWebServiceParameter,
0828: * nested information is stored in an instance of XList, where each element in the list
0829: * if a SimpleWebServiceParameter. While storing the information in defaults, the nested complex
0830: * structure is stored in the nested map and read accordingly.
0831: *
0832: * @param paramDescriptor
0833: * @param parentXList
0834: * @exception com.sun.portal.providers.ProviderException
0835: * @exception com.sun.portal.providers.simplewebservice.SimpleWebServiceException
0836: */
0837:
0838: private void recursiveDefineInputForWebService(
0839: ParameterDescriptor paramDescriptor, XList parentXList,
0840: HttpServletRequest req) throws ProviderException,
0841: SimpleWebServiceException {
0842:
0843: SimpleWebServiceParameter param = null;
0844:
0845: XList paramDescriptorList = (XList) paramDescriptor.getValue();
0846: Iterator paramDescriptorListIter = paramDescriptorList
0847: .iterator();
0848:
0849: int childCount = 1;
0850: if (paramDescriptor.isArrayType()) {
0851: childCount = getArraySize(req, paramDescriptor
0852: .getFullName());
0853: }
0854:
0855: while (paramDescriptorListIter.hasNext()) {
0856: ParameterDescriptor childDesc = (ParameterDescriptor) paramDescriptorListIter
0857: .next();
0858:
0859: if (childDesc.isRepeatable()) {
0860: childCount = getArraySize(req, childDesc.getFullName());
0861: }
0862: for (int i = 0; i < childCount; i++) {
0863: if (childDesc.getType().equals(XList.class)) {
0864: String targetNameSpace = ((XList) childDesc
0865: .getValue()).getTargetNameSpace();
0866:
0867: String complexTypeName = ((XList) childDesc
0868: .getValue()).getComplexTypeName();
0869:
0870: XList xlist = new XList(complexTypeName,
0871: targetNameSpace);
0872:
0873: recursiveDefineInputForWebService(childDesc, xlist,
0874: req);
0875:
0876: param = new SimpleWebServiceParameter(childDesc,
0877: xlist);
0878:
0879: } else {
0880: param = new SimpleWebServiceParameter(childDesc,
0881: (String) null);
0882: }
0883: parentXList.add(param);
0884: }
0885: }
0886:
0887: }
0888:
0889: private void recursiveDefineInputForWebService(
0890: ParameterDescriptor paramDescriptor, XList parentXList)
0891: throws ProviderException, SimpleWebServiceException {
0892:
0893: SimpleWebServiceParameter param = null;
0894:
0895: XList paramDescriptorList = (XList) paramDescriptor.getValue();
0896: Iterator paramDescriptorListIter = paramDescriptorList
0897: .iterator();
0898:
0899: while (paramDescriptorListIter.hasNext()) {
0900: ParameterDescriptor childDesc = (ParameterDescriptor) paramDescriptorListIter
0901: .next();
0902:
0903: if (childDesc.getType().equals(XList.class)) {
0904: String targetNameSpace = ((XList) childDesc.getValue())
0905: .getTargetNameSpace();
0906:
0907: String complexTypeName = ((XList) childDesc.getValue())
0908: .getComplexTypeName();
0909:
0910: XList xlist = new XList(complexTypeName,
0911: targetNameSpace);
0912:
0913: recursiveDefineInputForWebService(childDesc, xlist);
0914:
0915: param = new SimpleWebServiceParameter(childDesc, xlist);
0916:
0917: } else {
0918: param = new SimpleWebServiceParameter(childDesc,
0919: (String) null);
0920: }
0921: parentXList.add(param);
0922:
0923: }
0924:
0925: }
0926:
0927: private int getArraySize(HttpServletRequest req, String arrayName) {
0928: int ret = 1;
0929: try {
0930: ret = Integer.parseInt(req.getParameter(arrayName));
0931: } catch (Exception e) {
0932: ret = 1;
0933: }
0934:
0935: // System.out.println("Size of " + arrayName + " is " + ret);
0936: return ret;
0937: }
0938:
0939: private void recursiveReadInputFromRequest(HttpServletRequest req,
0940: ParameterDescriptor paramDescriptor, XList parentXList)
0941: throws ProviderException, SimpleWebServiceException {
0942:
0943: try {
0944: // if (paramDescriptor == null)
0945: // System.out.println("ParamDescriptor is Null");
0946:
0947: SimpleWebServiceParameter param = null;
0948: int childCount = 1;
0949: XList paramDescriptorList = (XList) paramDescriptor
0950: .getValue();
0951: // if (paramDescriptorList == null)
0952: // System.out.println("Problem with paramDescriptorList");
0953: Iterator paramDescriptorListIter = paramDescriptorList
0954: .iterator();
0955: if (paramDescriptor.isArrayType()) {
0956: childCount = getArraySize(req, paramDescriptor
0957: .getFullName());
0958: // System.out.println("Array Size of Array" + paramDescriptor.getFullName() + "is" + childCount);
0959: }
0960: while (paramDescriptorListIter.hasNext()) {
0961: ParameterDescriptor childDesc = (ParameterDescriptor) paramDescriptorListIter
0962: .next();
0963:
0964: // if (childDesc == null)
0965: // System.out.println("ChildDesc is Null");
0966: // if (childDesc.getValue() == null)
0967: // System.out.println("ChildDesc Value is Null");
0968: if (childDesc.isRepeatable()) {
0969: childCount = getArraySize(req, childDesc
0970: .getFullName());
0971: }
0972: for (int i = 0; i < childCount; i++) {
0973: if (childDesc.getType().equals(XList.class)) {
0974: String targetNameSpace = ((XList) childDesc
0975: .getValue()).getTargetNameSpace();
0976:
0977: String complexTypeName = ((XList) childDesc
0978: .getValue()).getComplexTypeName();
0979:
0980: XList xlist = new XList(complexTypeName,
0981: targetNameSpace);
0982:
0983: recursiveReadInputFromRequest(req, childDesc,
0984: xlist);
0985: param = new SimpleWebServiceParameter(
0986: childDesc, xlist);
0987:
0988: } else {
0989: /* String valueString =
0990: req.getParameter(makeUniqueStr(childDesc.getFullName()));*/
0991: String valueString = getIndexedParamter(req,
0992: makeUniqueStr(childDesc.getFullName()),
0993: i);
0994:
0995: param = new SimpleWebServiceParameter(
0996: childDesc, valueString);
0997: }
0998: parentXList.add(param);
0999: }
1000: }
1001: } catch (Exception e) {
1002: e.printStackTrace();
1003: }
1004: }
1005:
1006: private String getIndexedParamter(HttpServletRequest req,
1007: String paramName, int index) {
1008: String paramValue = "";
1009: String[] inParams = req.getParameterValues(paramName);
1010:
1011: if (inParams == null)
1012: return paramValue;
1013:
1014: int numberOfParams = req.getParameterValues(paramName).length;
1015:
1016: for (int i = 0; i < numberOfParams; i++) {
1017: if (!inParams[i].equals("__INVALID__")) {
1018: paramValue = inParams[i];
1019: inParams[i] = "__INVALID__";
1020: break;
1021: }
1022:
1023: }
1024:
1025: return paramValue;
1026: }
1027:
1028: private void recursiveSaveInputAsDefault(
1029: HttpServletRequest request,
1030: ParameterDescriptor paramDescriptor, Map parent) {
1031:
1032: Object value = null;
1033: if (paramDescriptor.getType().equals(XList.class)) {
1034:
1035: XList paramDescriptorList = (XList) paramDescriptor
1036: .getValue();
1037: Iterator paramDescriptorListIter = paramDescriptorList
1038: .iterator();
1039: HashMap childHashMap = new HashMap();
1040: value = childHashMap;
1041:
1042: while (paramDescriptorListIter.hasNext()) {
1043: ParameterDescriptor childDesc = (ParameterDescriptor) paramDescriptorListIter
1044: .next();
1045: recursiveSaveInputAsDefault(request, childDesc,
1046: childHashMap);
1047:
1048: }
1049: } else {
1050: value = request.getParameter(paramDescriptor.getFullName());
1051: }
1052: logger.log(Level.FINER, "PSCR_CSPPS0007", new Object[] {
1053: paramDescriptor.getFullName(), value });
1054: if (value != null) {
1055: parent.put(paramDescriptor.getName(), value);
1056: }
1057: }
1058:
1059: private void recursiveReadInputFromDefault(Map map,
1060: ParameterDescriptor paramDescriptor, XList parentXList)
1061: throws ProviderException, SimpleWebServiceException {
1062:
1063: if (map == null) {
1064: throw new ProviderException(
1065: "Default settings for web service are corrupted");
1066: }
1067:
1068: SimpleWebServiceParameter param = null;
1069:
1070: XList paramDescriptorList = (XList) paramDescriptor.getValue();
1071: Iterator paramDescriptorListIter = paramDescriptorList
1072: .iterator();
1073: while (paramDescriptorListIter.hasNext()) {
1074: ParameterDescriptor childDesc = (ParameterDescriptor) paramDescriptorListIter
1075: .next();
1076:
1077: if (childDesc.getType().equals(XList.class)) {
1078: String targetNameSpace = ((XList) childDesc.getValue())
1079: .getTargetNameSpace();
1080:
1081: String complexTypeName = ((XList) childDesc.getValue())
1082: .getComplexTypeName();
1083:
1084: XList xlist = new XList(complexTypeName,
1085: targetNameSpace);
1086: Map childMap = (Map) map.get(childDesc.getName());
1087:
1088: recursiveReadInputFromDefault(childMap, childDesc,
1089: xlist);
1090:
1091: param = new SimpleWebServiceParameter(childDesc, xlist);
1092: } else {
1093: String valueString = (String) map.get(childDesc
1094: .getName());
1095:
1096: param = new SimpleWebServiceParameter(childDesc,
1097: valueString);
1098: }
1099: parentXList.add(param);
1100: }
1101:
1102: }
1103:
1104: /***********************************************************************
1105: ** END OF RECURSIVE HELPER METHODS TO READ NESTED COMPLES DATA
1106: ***********************************************************************/
1107:
1108: /**
1109: * The abstract method that invokes the web service method using the input paramters
1110: * provided as a SimpleWebServiceParameter array.
1111: * <P>
1112: *
1113: * @param input array of web service input parameters.
1114: * @return the output result.
1115: * @throws ProviderException if there was a generic Provider error.
1116: * @throws SimpleWebServiceException if there was an error associated
1117: * with the web service.
1118: */
1119: abstract public SimpleWebServiceParameter invokeWebService(
1120: SimpleWebServiceParameter[] input)
1121: throws ProviderException, SimpleWebServiceException;
1122:
1123: }
|