You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by as...@apache.org on 2018/04/20 18:32:42 UTC

portals-pluto git commit: PLUTO-703 Extract PortletV3Demo TagLibPortlet.ActEvtProxyServlet inner-class into a separate ActEvtProxyServlet.java source file

Repository: portals-pluto
Updated Branches:
  refs/heads/master d6ac7fcd2 -> 2a8facde4


PLUTO-703 Extract PortletV3Demo TagLibPortlet.ActEvtProxyServlet inner-class into a separate ActEvtProxyServlet.java source file


Project: http://git-wip-us.apache.org/repos/asf/portals-pluto/repo
Commit: http://git-wip-us.apache.org/repos/asf/portals-pluto/commit/2a8facde
Tree: http://git-wip-us.apache.org/repos/asf/portals-pluto/tree/2a8facde
Diff: http://git-wip-us.apache.org/repos/asf/portals-pluto/diff/2a8facde

Branch: refs/heads/master
Commit: 2a8facde44b1e43c2165fe5b2755930249a7330f
Parents: d6ac7fc
Author: Neil Griffin <ne...@gmail.com>
Authored: Fri Apr 20 14:32:24 2018 -0400
Committer: Neil Griffin <ne...@gmail.com>
Committed: Fri Apr 20 14:32:24 2018 -0400

----------------------------------------------------------------------
 .../java/basic/portlet/ActEvtProxyServlet.java  | 84 ++++++++++++++++++++
 .../src/main/java/basic/portlet/ParamUtil.java  | 39 +++++++++
 .../main/java/basic/portlet/TagLibPortlet.java  | 74 ++---------------
 .../main/webapp/WEB-INF/jsp/tagLibDialog.jsp    |  1 +
 4 files changed, 129 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/2a8facde/PortletV3Demo/src/main/java/basic/portlet/ActEvtProxyServlet.java
----------------------------------------------------------------------
diff --git a/PortletV3Demo/src/main/java/basic/portlet/ActEvtProxyServlet.java b/PortletV3Demo/src/main/java/basic/portlet/ActEvtProxyServlet.java
new file mode 100644
index 0000000..c9f7a99
--- /dev/null
+++ b/PortletV3Demo/src/main/java/basic/portlet/ActEvtProxyServlet.java
@@ -0,0 +1,84 @@
+/*  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package basic.portlet;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import static basic.portlet.TagLibPortlet.ATTRIB_TXT;
+import static basic.portlet.TagLibPortlet.PROXY;
+import static basic.portlet.TagLibPortlet.TEST;
+
+/**
+ * Servlet used by the {@link TagLibPortlet}.
+ */
+@WebServlet(urlPatterns = PROXY)
+public class ActEvtProxyServlet extends HttpServlet {
+	private static final long serialVersionUID = -1798128019502989930L;
+	private static final Logger logger = LoggerFactory.getLogger(ActEvtProxyServlet.class);
+
+	@Override
+	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws
+		ServletException, IOException {
+		ProxyRespWrapper wrapped = new ProxyRespWrapper(resp);
+		String ttype = req.getParameter(TEST);
+		RequestDispatcher rd = req.getRequestDispatcher(ParamUtil.getJsp(ttype));
+		rd.include(req, wrapped);
+		String output = wrapped.getOutput();
+		req.getSession().setAttribute(ATTRIB_TXT, output);
+		logger.debug("Proxy executed. Output length: " + ((output == null) ? "null" : output.length()));
+	}
+
+	@Override
+	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+		doGet(req, resp);
+	}
+
+	private static class ProxyRespWrapper extends HttpServletResponseWrapper {
+
+		StringWriter sw = new StringWriter();
+		PrintWriter pw = new PrintWriter(sw);
+
+		public ProxyRespWrapper(HttpServletResponse response) {
+			super(response);
+		}
+
+		public String getOutput() {
+			pw.flush();
+			return sw.toString();
+		}
+
+		@Override
+		public PrintWriter getWriter() throws IOException {
+			return pw;
+		}
+
+	}
+}

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/2a8facde/PortletV3Demo/src/main/java/basic/portlet/ParamUtil.java
----------------------------------------------------------------------
diff --git a/PortletV3Demo/src/main/java/basic/portlet/ParamUtil.java b/PortletV3Demo/src/main/java/basic/portlet/ParamUtil.java
new file mode 100644
index 0000000..c8e7980
--- /dev/null
+++ b/PortletV3Demo/src/main/java/basic/portlet/ParamUtil.java
@@ -0,0 +1,39 @@
+/*  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package basic.portlet;
+
+/**
+ * Utility class for {@link ActEvtProxyServlet} and {@link TagLibPortlet}.
+ */
+public class ParamUtil {
+	private static final String JSPOBJ     = "/WEB-INF/jsp/tagLibObjects.jsp";
+	private static final String JSPBEANS   = "/WEB-INF/jsp/tagLibBeans.jsp";
+	public static final String  TEST_BEAN  = "bean";
+
+	/**
+	 * for selecting the JSP based on parameter value
+	 */
+	public static String getJsp(String ttype) {
+		String jsp = JSPOBJ;
+		if (ttype != null && ttype.equals(TEST_BEAN)) {
+			jsp = JSPBEANS;
+		}
+		return jsp;
+	}
+}

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/2a8facde/PortletV3Demo/src/main/java/basic/portlet/TagLibPortlet.java
----------------------------------------------------------------------
diff --git a/PortletV3Demo/src/main/java/basic/portlet/TagLibPortlet.java b/PortletV3Demo/src/main/java/basic/portlet/TagLibPortlet.java
index 379c121..6261622 100644
--- a/PortletV3Demo/src/main/java/basic/portlet/TagLibPortlet.java
+++ b/PortletV3Demo/src/main/java/basic/portlet/TagLibPortlet.java
@@ -55,13 +55,6 @@ import javax.portlet.annotations.PortletQName;
 import javax.portlet.annotations.RenderMethod;
 import javax.portlet.annotations.ServeResourceMethod;
 import javax.portlet.filter.HeaderResponseWrapper;
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletException;
-import javax.servlet.annotation.WebServlet;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpServletResponseWrapper;
 import javax.xml.namespace.QName;
 
 /**
@@ -77,7 +70,7 @@ import javax.xml.namespace.QName;
 public class TagLibPortlet {
 
 
-   private static final String PROXY = "/ActEvtProxy";
+   public static final String PROXY = "/ActEvtProxy";
 
    private static final Logger logger     = LoggerFactory.getLogger(TagLibPortlet.class);
 
@@ -90,15 +83,12 @@ public class TagLibPortlet {
    
    public static final String  TEST       = "test";
    public static final String  TEST_OBJ   = "obj";
-   public static final String  TEST_BEAN  = "bean";
 
    public static final String  ATTRIB_TXT          = "text";
    public static final String  ATTRIB_PHASE_TITLE  = "phaseTitle";
 
    private static final String JSPDLG     = "/WEB-INF/jsp/tagLibDialog.jsp";
-   private static final String JSPOBJ     = "/WEB-INF/jsp/tagLibObjects.jsp";
-   private static final String JSPBEANS   = "/WEB-INF/jsp/tagLibBeans.jsp";
-   
+
    // for event processing
    private static final String URI     = "http://www.apache.org/portals/pluto";
    private static final String LPART   = "TagLibPortlet";
@@ -108,17 +98,6 @@ public class TagLibPortlet {
    @Inject
    @Namespace
    private String              pid;
-   
-   /**
-    * for selecting the JSP based on parameter value
-    */
-   private static String getJsp(String ttype) {
-      String jsp = JSPOBJ;
-      if (ttype != null && ttype.equals(TEST_BEAN)) {
-         jsp = JSPBEANS;
-      }
-      return jsp;
-   }
 
    /**
     * Adds required dynamic dependencies
@@ -167,7 +146,7 @@ public class TagLibPortlet {
 
       if (phase.equals(PHASE_REN)) {
          req.setAttribute(ATTRIB_PHASE_TITLE, req.getAttribute(LIFECYCLE_PHASE));
-         prd = req.getPortletContext().getRequestDispatcher(getJsp(ttype));
+         prd = req.getPortletContext().getRequestDispatcher(ParamUtil.getJsp(ttype));
          prd.include(req, resp);
       } else if (phase.equals(PHASE_RES)) {
          ResourceURL resurl = resp.createResourceURL();
@@ -216,7 +195,7 @@ public class TagLibPortlet {
    public void getTable(ResourceRequest req, ResourceResponse resp) throws PortletException, IOException {
       req.setAttribute(ATTRIB_PHASE_TITLE, req.getAttribute(LIFECYCLE_PHASE));
       String ttype = req.getRenderParameters().getValue(TEST);
-      PortletRequestDispatcher prd = req.getPortletContext().getRequestDispatcher(getJsp(ttype));
+      PortletRequestDispatcher prd = req.getPortletContext().getRequestDispatcher(ParamUtil.getJsp(ttype));
       prd.include(req, resp);
    }
 
@@ -227,7 +206,7 @@ public class TagLibPortlet {
       if (phase != null && phase.equals(PHASE_HDR)) {
          req.setAttribute(ATTRIB_PHASE_TITLE, req.getAttribute(LIFECYCLE_PHASE));
          HdrRespWrapper wrapped = new HdrRespWrapper(resp);
-         PortletRequestDispatcher prd = req.getPortletContext().getRequestDispatcher(getJsp(ttype));
+         PortletRequestDispatcher prd = req.getPortletContext().getRequestDispatcher(ParamUtil.getJsp(ttype));
          prd.include(req, wrapped);
          req.getPortletSession().setAttribute(ATTRIB_TXT, wrapped.getOutput());
       }
@@ -299,47 +278,4 @@ public class TagLibPortlet {
          return pw;
       }
    }
-
-   private static class ProxyRespWrapper extends HttpServletResponseWrapper {
-
-      StringWriter sw = new StringWriter();
-      PrintWriter  pw = new PrintWriter(sw);
-
-      public ProxyRespWrapper(HttpServletResponse response) {
-         super(response);
-      }
-
-      public String getOutput() {
-         pw.flush();
-         return sw.toString();
-      }
-
-      @Override
-      public PrintWriter getWriter() throws IOException {
-         return pw;
-      }
-
-   }
-
-   @WebServlet(urlPatterns = PROXY)
-   public static class ActEvtProxyServlet extends HttpServlet {
-      private static final long serialVersionUID = -1798128019502989930L;
-      private static final Logger logger = Logger.getLogger(ActEvtProxyServlet.class);
-
-      @Override
-      protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
-         ProxyRespWrapper wrapped = new ProxyRespWrapper(resp);
-         String ttype = req.getParameter(TEST);
-         RequestDispatcher rd = req.getRequestDispatcher(getJsp(ttype));
-         rd.include(req, wrapped);
-         String output = wrapped.getOutput();
-         req.getSession().setAttribute(ATTRIB_TXT, output);
-         LOGGER.fine("Proxy executed. Output length: " + ((output == null) ? "null" : output.length()));
-      }
-      
-      @Override
-      protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
-         doGet(req, resp);
-      }
-   }
 }

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/2a8facde/PortletV3Demo/src/main/webapp/WEB-INF/jsp/tagLibDialog.jsp
----------------------------------------------------------------------
diff --git a/PortletV3Demo/src/main/webapp/WEB-INF/jsp/tagLibDialog.jsp b/PortletV3Demo/src/main/webapp/WEB-INF/jsp/tagLibDialog.jsp
index 0265e2e..d7588a9 100644
--- a/PortletV3Demo/src/main/webapp/WEB-INF/jsp/tagLibDialog.jsp
+++ b/PortletV3Demo/src/main/webapp/WEB-INF/jsp/tagLibDialog.jsp
@@ -20,6 +20,7 @@ limitations under the License.
 <%@ taglib uri="http://xmlns.jcp.org/portlet_3_0"  prefix="portlet" %>
 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
 <%@ page import="static basic.portlet.TagLibPortlet.*" %>
+<%@ page import="static basic.portlet.ParamUtil.*" %>
 
 <portlet:defineObjects />