001: /*
002: * (C) Copyright 2000 - 2005 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019: package com.nabhinc.portlet.wsadmin;
020:
021: import java.io.IOException;
022: import java.io.StringWriter;
023:
024: import javax.portlet.ActionRequest;
025: import javax.portlet.ActionResponse;
026: import javax.portlet.PortletException;
027: import javax.xml.parsers.DocumentBuilder;
028: import javax.xml.parsers.DocumentBuilderFactory;
029:
030: import org.w3c.dom.Document;
031: import org.w3c.dom.Element;
032: import org.xml.sax.InputSource;
033:
034: import com.nabhinc.portlet.mvcportlet.core.ActionConfig;
035: import com.nabhinc.portlet.mvcportlet.core.ActionProcessor;
036: import com.nabhinc.portlet.mvcportlet.core.BaseRequestProcessor;
037: import com.nabhinc.portlet.mvcportlet.core.Constants;
038: import com.nabhinc.util.DOM2Writer;
039: import com.nabhinc.ws.core.WebServiceException;
040: import com.nabhinc.ws.server.WebServiceInfo;
041: import com.nabhinc.ws.server.WebServiceManager;
042: import com.nabhinc.ws.server.WebServiceServlet;
043: import com.sun.xml.bind.StringInputStream;
044:
045: /**
046: *
047: *
048: * @author Padmanabh Dabke
049: * (c) 2005 Nabh Information Systems, Inc. All Rights Reserved.
050: */
051: public class WebServiceActionProcessor extends BaseRequestProcessor
052: implements ActionProcessor {
053:
054: /* (non-Javadoc)
055: * @see com.nabhinc.portlet.mvcportlet.core.ActionProcessor#process(javax.portlet.ActionRequest, javax.portlet.ActionResponse, com.nabhinc.portlet.mvcportlet.core.ActionConfig)
056: */
057: public String process(ActionRequest request,
058: ActionResponse response, ActionConfig actionConfig)
059: throws PortletException, IOException {
060: String wsName = request.getParameter("ws_name");
061: String action = request.getParameter("request_type");
062:
063: try {
064: if (action.equals("LoadWebService")) {
065: WebServiceManager.loadWebService(wsName);
066: } else if (action.equals("UnloadWebService")) {
067: WebServiceManager.unloadWebService(wsName);
068: } else if (action.equals("ReloadWebService")) {
069: WebServiceManager.reloadWebService(wsName);
070: } else if (action.equals("SuspendWebService")) {
071: WebServiceManager.stopWebService(wsName);
072: } else if (action.equals("ResumeWebService")) {
073: WebServiceManager.startWebService(wsName);
074: } else if (action.equals("DeleteWebService")) {
075: WebServiceManager.deleteWebService(wsName);
076: } else if (action.equals("AddWebService")) {
077: return addWebService(request, response);
078: } else if (action.equals("EditWebService")) {
079: setEditParameters(wsName, response);
080: } else if (action.equals("UpdateWebService")) {
081: return updateWebService(wsName, request, response);
082: }
083: } catch (WebServiceException ex) {
084: brpLog.error("Action " + action + " failed.", ex);
085: return "failure";
086: }
087: return "success";
088: }
089:
090: private String addWebService(ActionRequest request,
091: ActionResponse response) throws WebServiceException,
092: IOException {
093: WebServiceInfo wsInfo = new WebServiceInfo();
094: wsInfo.name = request.getParameter("ws_name");
095: wsInfo.displayName = request.getParameter("display_name");
096: wsInfo.webServiceClass = request.getParameter("ws_class");
097: wsInfo.webServiceInterfaceClass = request
098: .getParameter("service_interface_class");
099: wsInfo.description = request.getParameter("descr");
100: wsInfo.type = request.getParameter("ws_type");
101: wsInfo.manualLoad = request.getParameter("manual_load") != null;
102: wsInfo.isCritical = request.getParameter("is_critical") != null;
103: wsInfo.requiresSecureAccess = request
104: .getParameter("secure_access") != null;
105: wsInfo.owner = request.getParameter("owner");
106: wsInfo.wsdlFile = request.getParameter("wsdl_file");
107: wsInfo.propertiesInfo = WebServicePortletUtil
108: .constructPropertiesInfo(request);
109: String xmlConfigStr = request.getParameter("xml_config");
110: if (xmlConfigStr != null && (!xmlConfigStr.trim().equals(""))) {
111: try {
112: wsInfo.xmlConfig = parseXMLConfig(xmlConfigStr);
113: } catch (Exception ex) {
114: debug("Failed to parse XML configuration.", ex);
115: response.setRenderParameter(
116: Constants.ERROR_MESSAGE_PARAM
117: + request.getPortletMode().toString()
118: .toLowerCase(),
119: "Failed to parse deployment XML.");
120: return "failure";
121: }
122: }
123: WebServiceManager.addWebService(wsInfo);
124: return "success";
125: }
126:
127: private String updateWebService(String wsName,
128: ActionRequest request, ActionResponse response)
129: throws WebServiceException, IOException {
130: WebServiceInfo wsInfo = WebServiceManager
131: .getWebServiceInfo(wsName);
132: String xmlConfigStr = request.getParameter("xml_config");
133: if (xmlConfigStr != null && (!xmlConfigStr.trim().equals(""))) {
134: try {
135: wsInfo.xmlConfig = parseXMLConfig(xmlConfigStr);
136: } catch (Exception ex) {
137: debug("Failed to parse XML configuration.", ex);
138: response.setRenderParameter(
139: Constants.ERROR_MESSAGE_PARAM
140: + request.getPortletMode().toString()
141: .toLowerCase(),
142: "Failed to parse deployment XML.");
143: return "failure";
144: }
145: }
146: wsInfo.displayName = request.getParameter("display_name");
147: wsInfo.webServiceClass = request.getParameter("ws_class");
148: wsInfo.webServiceInterfaceClass = request
149: .getParameter("service_interface_class");
150: wsInfo.description = request.getParameter("descr");
151: wsInfo.type = request.getParameter("ws_type");
152: wsInfo.manualLoad = request.getParameter("manual_load") != null;
153: wsInfo.isCritical = request.getParameter("is_critical") != null;
154: wsInfo.requiresSecureAccess = request
155: .getParameter("secure_access") != null;
156: wsInfo.owner = request.getParameter("owner");
157: wsInfo.wsdlFile = request.getParameter("wsdl_file");
158: wsInfo.propertiesInfo = WebServicePortletUtil
159: .constructPropertiesInfo(request);
160: WebServiceServlet.getInstance().save();
161: return "success";
162: }
163:
164: private void setEditParameters(String wsName,
165: ActionResponse response) throws WebServiceException,
166: IOException {
167: WebServiceInfo wsInfo = WebServiceManager
168: .getWebServiceInfo(wsName);
169: response.setRenderParameter("ws_name", wsName);
170: response.setRenderParameter("display_name", wsInfo.displayName);
171: response.setRenderParameter("ws_class", wsInfo.webServiceClass);
172: response.setRenderParameter("service_interface_class",
173: wsInfo.webServiceInterfaceClass);
174: response.setRenderParameter("descr", wsInfo.description);
175: response.setRenderParameter("ws_type", wsInfo.type);
176: response.setRenderParameter("wsdl_file", wsInfo.wsdlFile);
177: if (wsInfo.manualLoad)
178: response.setRenderParameter("manual_load", "true");
179: if (wsInfo.isCritical)
180: response.setRenderParameter("is_critical", "true");
181: if (wsInfo.requiresSecureAccess)
182: response.setRenderParameter("secure_access", "true");
183: response.setRenderParameter("owner", wsInfo.owner);
184: if (wsInfo.xmlConfig != null) {
185: StringWriter w = new StringWriter();
186: DOM2Writer.serializeAsXML(wsInfo.xmlConfig, w, true, true,
187: "UTF-8", 0, 4);
188: w.flush();
189: response.setRenderParameter("xml_config", w.toString());
190: }
191: WebServicePortletUtil.setPropertyParams(response,
192: wsInfo.propertiesInfo);
193: }
194:
195: public Element parseXMLConfig(String xmlStr) throws Exception {
196:
197: DocumentBuilderFactory docFactory = DocumentBuilderFactory
198: .newInstance();
199: docFactory.setNamespaceAware(true);
200: DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
201: Document doc = docBuilder.parse(new InputSource(
202: new StringInputStream(xmlStr)));
203: return doc.getDocumentElement();
204:
205: }
206:
207: }
|