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:
023: import javax.portlet.ActionRequest;
024: import javax.portlet.ActionResponse;
025: import javax.portlet.PortletException;
026:
027: import com.nabhinc.portlet.mvcportlet.core.ActionConfig;
028: import com.nabhinc.portlet.mvcportlet.core.ActionProcessor;
029: import com.nabhinc.portlet.mvcportlet.core.BaseRequestProcessor;
030:
031: import com.nabhinc.ws.core.WebServiceException;
032: import com.nabhinc.ws.server.InterceptorInfo;
033: import com.nabhinc.ws.server.InterceptorManager;
034: import com.nabhinc.ws.server.WebServiceServlet;
035:
036: /**
037: * Interceptor action processor.
038: *
039: * @author Padmanabh Dabke
040: * (c) 2005 Nabh Information Systems, Inc. All Rights Reserved.
041: */
042: public class InterceptorActionProcessor extends BaseRequestProcessor
043: implements ActionProcessor {
044:
045: public String process(ActionRequest request,
046: ActionResponse response, ActionConfig actionConfig)
047: throws PortletException, IOException {
048: String wsName = request.getParameter("int_name");
049: String action = request.getParameter("request_type");
050:
051: try {
052: if (action.equals("LoadInterceptor")) {
053: InterceptorManager.loadInterceptor(wsName);
054: } else if (action.equals("UnloadInterceptor")) {
055: InterceptorManager.unloadInterceptor(wsName);
056: } else if (action.equals("ReloadInterceptor")) {
057: InterceptorManager.reloadInterceptor(wsName);
058: } else if (action.equals("DeleteInterceptor")) {
059: InterceptorManager.deleteInterceptor(wsName);
060: } else if (action.equals("AddInterceptor")) {
061: return addInterceptor(request, response);
062: } else if (action.equals("EditInterceptor")) {
063: setEditParameters(wsName, response);
064: } else if (action.equals("UpdateInterceptor")) {
065: return updateInterceptor(wsName, request, response);
066: }
067: } catch (WebServiceException ex) {
068: brpLog.error("Action " + action + " failed.", ex);
069: return "failure";
070: }
071: return "success";
072: }
073:
074: private String addInterceptor(ActionRequest request,
075: ActionResponse response) throws WebServiceException,
076: IOException {
077: InterceptorInfo wsInfo = new InterceptorInfo();
078: wsInfo.name = request.getParameter("int_name");
079: wsInfo.displayName = request.getParameter("display_name");
080: wsInfo.interceptorClass = request.getParameter("int_class");
081: wsInfo.description = request.getParameter("descr");
082: wsInfo.manualLoad = request.getParameter("manual_load") != null;
083: wsInfo.isCritical = request.getParameter("is_critical") != null;
084: wsInfo.owner = request.getParameter("owner");
085: wsInfo.propertiesInfo = WebServicePortletUtil
086: .constructPropertiesInfo(request);
087: InterceptorManager.addInterceptor(wsInfo);
088: return "success";
089: }
090:
091: private String updateInterceptor(String wsName,
092: ActionRequest request, ActionResponse response)
093: throws WebServiceException, IOException {
094: InterceptorInfo wsInfo = InterceptorManager
095: .getInterceptorInfo(wsName);
096: wsInfo.displayName = request.getParameter("display_name");
097: wsInfo.interceptorClass = request.getParameter("int_class");
098: wsInfo.description = request.getParameter("descr");
099: wsInfo.manualLoad = request.getParameter("manual_load") != null;
100: wsInfo.isCritical = request.getParameter("is_critical") != null;
101: wsInfo.owner = request.getParameter("owner");
102: wsInfo.propertiesInfo = WebServicePortletUtil
103: .constructPropertiesInfo(request);
104: WebServiceServlet.getInstance().save();
105: return "success";
106: }
107:
108: private void setEditParameters(String wsName,
109: ActionResponse response) throws WebServiceException,
110: IOException {
111: InterceptorInfo wsInfo = InterceptorManager
112: .getInterceptorInfo(wsName);
113: response.setRenderParameter("int_name", wsName);
114: response.setRenderParameter("display_name", wsInfo.displayName);
115: response.setRenderParameter("int_class",
116: wsInfo.interceptorClass);
117: response.setRenderParameter("descr", wsInfo.description);
118: if (wsInfo.manualLoad)
119: response.setRenderParameter("manual_load", "true");
120: if (wsInfo.isCritical)
121: response.setRenderParameter("is_critical", "true");
122: response.setRenderParameter("owner", wsInfo.owner);
123: WebServicePortletUtil.setPropertyParams(response,
124: wsInfo.propertiesInfo);
125: }
126:
127: }
|