Utils.java revision 0f14c5266d32ed727cd64ba10f2d2da0ed623a41
af062818b47340eef15700d2f0211576ba3506eevboxsync * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
af062818b47340eef15700d2f0211576ba3506eevboxsync * Copyright (c) 2007 Sun Microsystems Inc. All Rights Reserved
af062818b47340eef15700d2f0211576ba3506eevboxsync * The contents of this file are subject to the terms
af062818b47340eef15700d2f0211576ba3506eevboxsync * of the Common Development and Distribution License
af062818b47340eef15700d2f0211576ba3506eevboxsync * (the License). You may not use this file except in
af062818b47340eef15700d2f0211576ba3506eevboxsync * compliance with the License.
af062818b47340eef15700d2f0211576ba3506eevboxsync * You can obtain a copy of the License at
af062818b47340eef15700d2f0211576ba3506eevboxsync * https://opensso.dev.java.net/public/CDDLv1.0.html or
af062818b47340eef15700d2f0211576ba3506eevboxsync * See the License for the specific language governing
af062818b47340eef15700d2f0211576ba3506eevboxsync * permission and limitations under the License.
af062818b47340eef15700d2f0211576ba3506eevboxsync * When distributing Covered Code, include this CDDL
af062818b47340eef15700d2f0211576ba3506eevboxsync * Header Notice in each file and include the License file
af062818b47340eef15700d2f0211576ba3506eevboxsync * If applicable, add the following below the CDDL Header,
af062818b47340eef15700d2f0211576ba3506eevboxsync * with the fields enclosed by brackets [] replaced by
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * your own identifying information:
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * "Portions Copyrighted [year] [name of copyright owner]"
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * $Id: Utils.java,v 1.4 2008/11/10 22:57:00 veiming Exp $
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * Portions Copyrighted 2013-2015 ForgeRock AS.
af062818b47340eef15700d2f0211576ba3506eevboxsync * Util class to implement simple Http request/response transactions.
af062818b47340eef15700d2f0211576ba3506eevboxsync * Http POST
af062818b47340eef15700d2f0211576ba3506eevboxsync * Redirects to <code>redirectUrl</code> as a GET or a POST
af062818b47340eef15700d2f0211576ba3506eevboxsync * based on <code>action</code> parameter provided.
af062818b47340eef15700d2f0211576ba3506eevboxsync * in case of POST all params need to be specified in <code>pmap</code>
af062818b47340eef15700d2f0211576ba3506eevboxsync * parameter.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @param hres HttpSevletResponse to be used for the redirect
af062818b47340eef15700d2f0211576ba3506eevboxsync * @param out the print writer for writing out presentation
af062818b47340eef15700d2f0211576ba3506eevboxsync * @param redirectUrl URL to redirect to.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @param pmap http parameters to be sent as part of the redirect
af062818b47340eef15700d2f0211576ba3506eevboxsync * @param action http action to be executed : GET or POST
af062818b47340eef15700d2f0211576ba3506eevboxsync public static void redirect(HttpServletResponse hres, PrintWriter out, String redirectUrl,
589fd26cedb2b4ebbed14f2964cad03cc8ebbca2vboxsync // Put it all together in query part of Url
af062818b47340eef15700d2f0211576ba3506eevboxsync String html = formFromMap(redirectUrl, pmap, true);
af062818b47340eef15700d2f0211576ba3506eevboxsync * Generates a query string from the parameters in the request.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @param request http request to pick params from.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @return query string
af062818b47340eef15700d2f0211576ba3506eevboxsync public static String queryStringFromRequest(HttpServletRequest request)
af062818b47340eef15700d2f0211576ba3506eevboxsync boolean priorparam = false;
af062818b47340eef15700d2f0211576ba3506eevboxsync * Generates a query string from the a <code>Map</code>.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @param pmap params to be added to the query string.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @return query string
af062818b47340eef15700d2f0211576ba3506eevboxsync boolean priorparam = false;
af062818b47340eef15700d2f0211576ba3506eevboxsync buf.append(name).append("=").append(URLEncoder.encode(val));
af062818b47340eef15700d2f0211576ba3506eevboxsync * Generates a html hidden form to acccomplish a auto POST from the browser
af062818b47340eef15700d2f0211576ba3506eevboxsync * Form is assigned an id=saeform
af062818b47340eef15700d2f0211576ba3506eevboxsync * @param redirectUrl URL to post teh form to.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @param pmap parameters to be sent in the POST
589fd26cedb2b4ebbed14f2964cad03cc8ebbca2vboxsync * @param addAutoSubmit adds html and javascript to autosubmit form
af062818b47340eef15700d2f0211576ba3506eevboxsync * @return html code
af062818b47340eef15700d2f0211576ba3506eevboxsync public static String formFromMap(String redirectUrl, Map pmap,
af062818b47340eef15700d2f0211576ba3506eevboxsync buf.append("<HTML><HEAD><TITLE>SAE POST</TITLE></HEAD>");
af062818b47340eef15700d2f0211576ba3506eevboxsync buf.append("<BODY Onload=\"document.forms[0].submit()\">");
af062818b47340eef15700d2f0211576ba3506eevboxsync buf.append("<FORM id=\"saeform\" METHOD=\"POST\" ACTION=\"").append(redirectUrl).append("\">");
af062818b47340eef15700d2f0211576ba3506eevboxsync buf.append("<INPUT TYPE=\"HIDDEN\" NAME=\"").append(name).append("\" VALUE=\"");