2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 package org.openecomp.portalsdk.analytics.controller;
23 import java.lang.reflect.*;
24 import javax.servlet.*;
25 import javax.servlet.http.*;
27 import org.openecomp.portalsdk.analytics.controller.*;
28 import org.openecomp.portalsdk.analytics.error.RaptorException;
29 import org.openecomp.portalsdk.analytics.error.RaptorRuntimeException;
30 import org.openecomp.portalsdk.analytics.model.runtime.ReportParamValues;
31 import org.openecomp.portalsdk.analytics.system.*;
32 import org.openecomp.portalsdk.analytics.util.*;
33 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
35 public class Controller extends org.openecomp.portalsdk.analytics.RaptorObject {
37 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(Controller.class);
41 public String processRequest(HttpServletRequest request) {
42 String actionKey = nvl(request.getParameter(AppConstants.RI_ACTION), "report.run");
44 return processRequest(actionKey, request);
47 public String processRequest(String actionKey, HttpServletRequest request) {
50 action = Globals.getRaptorActionMapping().getAction(actionKey);
52 throw new RaptorRuntimeException("Action not found");
53 } catch (RaptorException e) {
54 logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action [" + actionKey
55 + "]. RaptorException: " + e.getMessage()));
56 // if (actionKey.equals("system_upgrade")) // System override
57 // return att.raptor.util.upgrade.SystemUpgrade.upgradeDB(request);
59 return (new ErrorHandler()).processFatalError(request, new RaptorRuntimeException(
60 "[Controller.processRequest]Invalid raptor action [" + actionKey
61 + "]. Exception: " + e.getMessage()));
65 Class[] paramTypes = new Class[2];
66 paramTypes[0] = Class.forName("javax.servlet.http.HttpServletRequest");
67 paramTypes[1] = Class.forName("java.lang.String");
69 Class handlerClass = Class.forName(action.getControllerClass());
70 Object handler = handlerClass.newInstance();
71 Method handlerMethod = handlerClass.getMethod(action.getControllerMethod(),
74 Object[] paramValues = new Object[2];
75 paramValues[0] = request;
76 paramValues[1] = action.getJspName();
78 return (String) handlerMethod.invoke(handler, paramValues);
79 } catch (ClassNotFoundException e) {
80 logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action [" + actionKey
81 + "]. ClassNotFoundException: " + e.getMessage()));
82 return (new ErrorHandler()).processFatalError(request, new RaptorRuntimeException(
83 "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: "
85 } catch (IllegalAccessException e) {
86 logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action [" + actionKey
87 + "]. IllegalAccessException: " + e.getMessage()));
88 return (new ErrorHandler()).processFatalError(request, new RaptorRuntimeException(
89 "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: "
91 }catch (InstantiationException e) {
92 logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action [" + actionKey
93 + "]. InstantiationException: " + e.getMessage()));
94 return (new ErrorHandler()).processFatalError(request, new RaptorRuntimeException(
95 "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: "
97 }catch (NoSuchMethodException e) {
98 logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action [" + actionKey
99 + "]. NoSuchMethodException: " + e.getMessage()));
100 return (new ErrorHandler()).processFatalError(request, new RaptorRuntimeException(
101 "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: "
103 }catch (InvocationTargetException e) {
104 logger.debug(EELFLoggerDelegate.debugLogger, ("[Controller.processRequest]Invalid raptor action [" + actionKey
105 + "]. InvocationTargetException: " + e.getMessage()));
106 return (new ErrorHandler()).processFatalError(request, new RaptorRuntimeException(
107 "[Controller.processRequest] Unable to instantiate and invoke action handler. Exception: "
112 public void handleRequest(HttpServletRequest request, HttpServletResponse response,
113 ServletContext servletContext) throws Exception {
114 String actionKey = nvl(request.getParameter(AppConstants.RI_ACTION), request.getParameter("action"));
116 handleRequest(actionKey, request, response, servletContext);
119 public void handleRequest(String actionKey, HttpServletRequest request,
120 HttpServletResponse response, ServletContext servletContext) throws Exception {
121 servletContext.getRequestDispatcher("/" + processRequest(actionKey, request)).forward(