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 ms...@apache.org on 2015/02/25 09:58:43 UTC
[6/9] portals-pluto git commit: Added portlet to test
setAuthenticated() on the URLs and the ResourceResponse#setStatus() method.
Completed this phase of prototyping work.
Added portlet to test setAuthenticated() on the URLs and the
ResourceResponse#setStatus() method.
Completed this phase of prototyping work.
Project: http://git-wip-us.apache.org/repos/asf/portals-pluto/repo
Commit: http://git-wip-us.apache.org/repos/asf/portals-pluto/commit/d5e61601
Tree: http://git-wip-us.apache.org/repos/asf/portals-pluto/tree/d5e61601
Diff: http://git-wip-us.apache.org/repos/asf/portals-pluto/diff/d5e61601
Branch: refs/heads/V3Prototype
Commit: d5e61601dc993500fc19bde989469a53056bcfad
Parents: 7ae768d
Author: Scott Nicklous <ms...@apache.org>
Authored: Tue Feb 24 13:56:37 2015 +0100
Committer: Scott Nicklous <ms...@apache.org>
Committed: Tue Feb 24 13:56:37 2015 +0100
----------------------------------------------------------------------
.../main/java/basic/portlet/AuthSCPortlet.java | 128 +++++++++++++++++++
.../src/main/java/basic/portlet/Constants.java | 4 +
.../src/main/webapp/WEB-INF/jsp/view-ascp.jsp | 80 ++++++++++++
.../src/main/webapp/WEB-INF/portlet.xml | 18 +++
4 files changed, 230 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/d5e61601/PortletV3Demo/src/main/java/basic/portlet/AuthSCPortlet.java
----------------------------------------------------------------------
diff --git a/PortletV3Demo/src/main/java/basic/portlet/AuthSCPortlet.java b/PortletV3Demo/src/main/java/basic/portlet/AuthSCPortlet.java
new file mode 100644
index 0000000..62b5fe0
--- /dev/null
+++ b/PortletV3Demo/src/main/java/basic/portlet/AuthSCPortlet.java
@@ -0,0 +1,128 @@
+/* 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 static basic.portlet.Constants.*;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.portlet.ActionParameters;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.GenericPortlet;
+
+import static javax.portlet.MimeResponse.ParameterCopyOption.*;
+
+import javax.portlet.ActionURL;
+import javax.portlet.MutableActionParameters;
+import javax.portlet.MutableRenderParameters;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.RenderParameters;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.ResourceRequest;
+import javax.portlet.ResourceResponse;
+
+
+/**
+ * A portlet that allows render parameter names & values to be entered and set.
+ *
+ * @author Scott Nicklous
+ */
+public class AuthSCPortlet extends GenericPortlet {
+
+ // Set up logging
+ private static final String LOG_CLASS = AuthSCPortlet.class.getName();
+ private static final Logger logger = Logger.getLogger(LOG_CLASS);
+ private static final boolean isDebug = logger.isLoggable(Level.FINE);
+
+ @Override
+ public void init() throws PortletException {
+ super.init();
+ }
+
+ protected void doView(RenderRequest req, RenderResponse resp)
+ throws PortletException, IOException {
+
+ resp.setContentType("text/html");
+
+ PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(
+ "/WEB-INF/jsp/view-ascp.jsp");
+ rd.include(req, resp);
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.portlet.GenericPortlet#serveResource(javax.portlet.ResourceRequest, javax.portlet.ResourceResponse)
+ */
+ @Override
+ public void serveResource(ResourceRequest req, ResourceResponse resp)
+ throws PortletException, IOException {
+
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+
+ StringBuilder txt = new StringBuilder();
+
+ String scText = req.getRenderParameters().getValue(PARAM_STATUSCODE);
+ if (scText != null && scText.matches("\\d+")) {
+ int sc = Integer.parseInt(scText);
+ if (isDebug) {
+ logger.fine("Setting HTTP status code to: " + sc);
+ }
+ resp.setStatus(sc);
+ }
+
+ txt.append("<p>serveResource</p>")
+ .append("<p>Status code: ").append(scText).append("</p>");
+
+ writer.write(txt.toString());
+ }
+
+ public void processAction(ActionRequest req, ActionResponse resp)
+ throws PortletException, IOException {
+
+ ActionParameters ap = req.getActionParameters();
+ MutableRenderParameters mrp = resp.getRenderParameters();
+ mrp.set(ap);
+
+ if (isDebug) {
+ StringBuffer sb = new StringBuffer();
+ sb.append("Long portlet action parameters:");
+ for (String k : ap.getNames()) {
+ sb.append("\nName: ").append(k);
+ sb.append(", Values: ").append(Arrays.toString(ap.getValues(k)));
+ }
+ logger.fine(sb.toString());
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/d5e61601/PortletV3Demo/src/main/java/basic/portlet/Constants.java
----------------------------------------------------------------------
diff --git a/PortletV3Demo/src/main/java/basic/portlet/Constants.java b/PortletV3Demo/src/main/java/basic/portlet/Constants.java
index e69d869..32c3b10 100644
--- a/PortletV3Demo/src/main/java/basic/portlet/Constants.java
+++ b/PortletV3Demo/src/main/java/basic/portlet/Constants.java
@@ -82,5 +82,9 @@ public class Constants {
public final static String PARAM_FRAG = "frag";
public final static String PARAM_LINE = "line";
public final static String ATTRIB_LONGLINES = "longlines";
+
+ // For Auth & Status Code portlet
+
+ public final static String PARAM_STATUSCODE = "statusCode";
}
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/d5e61601/PortletV3Demo/src/main/webapp/WEB-INF/jsp/view-ascp.jsp
----------------------------------------------------------------------
diff --git a/PortletV3Demo/src/main/webapp/WEB-INF/jsp/view-ascp.jsp b/PortletV3Demo/src/main/webapp/WEB-INF/jsp/view-ascp.jsp
new file mode 100644
index 0000000..86a9080
--- /dev/null
+++ b/PortletV3Demo/src/main/webapp/WEB-INF/jsp/view-ascp.jsp
@@ -0,0 +1,80 @@
+<%--
+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.
+--%>
+<%@ page session="false" %>
+<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<%@ page import="java.io.*,java.util.*,javax.portlet.*" %>
+<%@ page import="javax.portlet.MimeResponse.ParameterCopyOption" %>
+<%@ page import="static javax.portlet.MimeResponse.ParameterCopyOption.*" %>
+<%@ page import="static basic.portlet.Constants.*" %>
+
+<portlet:defineObjects />
+
+
+<h3>Authenticated URL & Status Code Test Portlet</h3>
+<p>V3 portlet that displays a resource URL link that causes a status code to be set
+and other URLs that are marked as authenticated.</p>
+<p>Use the form below to enter the HTTP status code.</p>
+<%
+ ActionURL aurl = renderResponse.createActionURL();
+ String colStyle = "align='left' style='min-width: 25px; padding:0 10px 0 10px;'";
+%>
+<FORM METHOD='POST' ACTION='<%=aurl.toString() %>' enctype='application/x-www-form-urlencoded' accept-charset='UTF-8'>
+ <table><tr><td <%=colStyle %>>
+ Status code:
+ </td><td <%=colStyle %>>
+ <input name='<%=PARAM_STATUSCODE%>' type='text' value='' size='10' maxlength='10'>
+ </td><td <%=colStyle %>>
+ <INPUT VALUE='send' TYPE='submit'>
+ </td></tr></table>
+</FORM>
+<p><hr/></p>
+<%
+ String scStr = renderRequest.getRenderParameters().getValue(PARAM_STATUSCODE);
+ int sc = -1;
+ if (scStr != null && scStr.matches("\\d+")) {
+ sc = Integer.parseInt(scStr);
+ ResourceURL resurl = renderResponse.createResourceURL();
+ out.print("<p><a href='");
+ out.print(resurl.toString());
+ out.println("'>Resource URL, status code = " + sc + "</a></p>");
+ }
+
+ RenderURL renurl = renderResponse.createRenderURL(COPY_RENDER_PARAMETERS);
+ renurl.setAuthenticated(true);
+ out.print("<p><a href='");
+ out.print(renurl.toString());
+ out.println("'>Render URL with setAuthenticated(true)</a></p>");
+
+ ResourceURL resurl = renderResponse.createResourceURL();
+ resurl.setAuthenticated(true);
+ out.print("<p><a href='");
+ out.print(resurl.toString());
+ out.println("'>Resource URL with setAuthenticated(true)</a></p>");
+
+ ActionURL acturl = renderResponse.createActionURL(COPY_RENDER_PARAMETERS);
+ acturl.setAuthenticated(true);
+ StringBuilder txt = new StringBuilder();
+ txt.append("<form METHOD='POST' ACTION='").append(acturl.toString()).append("'>")
+ .append("<button type='submit'>").append("Action URL with setAuthenticated(true)")
+ .append("</button>")
+ .append("</form>");
+ out.println(txt.toString());
+%>
+<p><hr/></p>
http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/d5e61601/PortletV3Demo/src/main/webapp/WEB-INF/portlet.xml
----------------------------------------------------------------------
diff --git a/PortletV3Demo/src/main/webapp/WEB-INF/portlet.xml b/PortletV3Demo/src/main/webapp/WEB-INF/portlet.xml
index 2b246b1..e341c35 100644
--- a/PortletV3Demo/src/main/webapp/WEB-INF/portlet.xml
+++ b/PortletV3Demo/src/main/webapp/WEB-INF/portlet.xml
@@ -251,6 +251,24 @@
</portlet-info>
</portlet>
+ <portlet>
+ <portlet-name>AuthSCPortlet</portlet-name>
+ <display-name>V3 Authentication and Status Code Test Portlet</display-name>
+
+ <portlet-class>basic.portlet.AuthSCPortlet</portlet-class>
+
+ <supports>
+ <mime-type>text/html</mime-type>
+ <portlet-mode>VIEW</portlet-mode>
+ </supports>
+
+ <supported-locale>en</supported-locale>
+
+ <portlet-info>
+ <title>V3 Authentication and Status Code Test Portlet</title>
+ </portlet-info>
+ </portlet>
+
<custom-portlet-mode>
<description>Test mode #1</description>
<portlet-mode>MyMode_nonPortalManaged_1</portlet-mode>