[opencms-dev] Responding back to application's HTTP POST values with HttpContentType=application/x-www-form-urlencoded
Jeremy Wilson
jeremy.wilson at laplink.com
Tue Aug 4 19:42:33 CEST 2009
I am trying to communicate back to an executable (installer file) that
is sending me values via HTTP POST but continue to run into problems
with the HttpContentType being converted back to
"text/html;charset=UTF-8" within OpenCMS 6.2.1.
How do I set my pages's response (HttpContentType) as
"application/x-www-form-urlencoded" and keep it that way. I've tried a
number of different methods but it seems as though OpenCMS is forcing
the HttpContentType to revert back before I can communicate back to the
application by way of out.print("something");
Is this a known problem in OpenCMS 6.2.1? Is there something within the
configuration files that I can do to prevent my attempts to responsd
from being converted back to "text/html;charset=UTF-8".
Thanks in advance.
Here is the code (index.jsp) I'm trying to create the response back to
the application with:
<%@ page session="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib uri="http://jakarta.apache.org/taglibs/regexp-1.0"
prefix="rx" %>
<%@ taglib uri="http://jakarta.apache.org/taglibs/string-1.1"
prefix="str" %>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.net.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<%@ page import="javax.servlet.http.HttpServletRequest"%>
<%@ page import="javax.servlet.http.HttpServletResponse"%>
<jsp:useBean id="cms" class="org.opencms.jsp.CmsJspActionElement">
<% cms.init(pageContext, request, response); %>
</jsp:useBean>
<%-- ******** set POST submission type, a) register, b) subscribe, or c)
null which is the product update post ***** --%>
<c:set var="regcheck">register</c:set>
<c:set var="regtype" value="${param.type}" />
<c:choose>
<c:when test="${regcheck == regtype}">
<%-- ****************************************
// get the HTTP POST values and set them as variables :
// 1) type, 2) product, 3) language, 4) versionmajor, 5)
versionminor, 6) versionbuild,
// 7) email, 8) user, 9) company and 10) serial values
// for product registration HTTP POST submission
****************************************--%>
<c:set var="email" value="${param.email}" />
<c:out value="${email}"/>
<c:set var="user" value="${param.user}" />
<c:out value="${user}"/>
<c:set var="company" value="${param.company}" />
<c:out value="${company}"/>
<c:set var="serial" value="${param.serial}" />
<c:out value="${serial}"/>
<c:set var="currentProduct">Laplink Defrag Professional
Edition</c:set>
<c:set var="prod" value="${param.product}" />
<c:out value="${currentProduct}"/>
<c:set var="currentLanguage">EN</c:set>
<c:set var="lang" value="${param.language}" />
<c:out value="${currentLanguage}"/>
<%-- major, minor and version build values for Laplink Defrag
11.0.0000 ***** --%>
<c:set var="currentMajor">11</c:set>
<c:set var="versionmaj" value="${param.versionmajor}" />
<c:set var="currentMinor">0</c:set>
<c:set var="versionmin" value="${param.versionminor}" />
<c:set var="currentBuild">0000</c:set>
<c:set var="versionbld" value="${param.versionbuild}" />
<c:set var="serverresponse">OK</c:set>
<c:out value="${serverresponse}"/>
<%
// Get the POST parameters from Laplink Defrag .EXE - should be
passed in the HTTP request
String strregtype = request.getParameter("type");
String strregemail = request.getParameter("email");
String strreguser = request.getParameter("user");
String strregcompany = request.getParameter("company");
String strregserial = request.getParameter("serial");
String strregproduct = request.getParameter("product");
String strreglanguage = request.getParameter("language");
String strregversionmajor = request.getParameter("versionmajor");
String strregversionminor = request.getParameter("versionminor");
String strregversionbuild = request.getParameter("versionbuild");
// TEST the HTTP POST values from O&O Check for Updates to see
what actual values are being passed.
// String paramString =
"&product="+product+"&language="+language+"&versionmajor="+versionmajor+
"&versionminor="+versionminor+"&versionbuild="+versionbuild;
// String paramStringSubscribe =
"&type="+typeooreg+"&product="+product+"&language="+language+"&versionma
jor="+versionmajor+"&versionminor="+versionminor+"&versionbuild="+versio
nbuild;
String paramStringRegister =
"type="+strregtype+"&email="+strregemail+"&user="+strreguser+"&company="
+strregcompany+"&serial="+strregserial+"&product="+strregproduct+"&langu
age="+strreglanguage+"&versionmajor="+strregversionmajor+"&versionminor=
"+strregversionminor+"&versionbuild="+strregversionbuild;
%>
<%
response.setStatus(response.SC_OK);
response.setContentType("application/x-www-form-urlencoded");
response.setHeader("Content-Type",
"application/x-www-form-urlencoded");
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("result", "OK");
// Respond to the application with OK result
String result = "OK";
out.print("result=" + result);
// <c:set var="serverresponse">OK</c:set>
// <c:out value="${serverresponse}"/>
%>
<% response.setStatus(307); %>
<% response.setHeader("Location",
"http://www.laplink.com/mysupport/register/ooreg.asp?"+paramStringRegist
er); %>
<%--
response.sendRedirect("http://www.laplink.com/mysupport/register/ooreg.a
sp?"+paramStringRegister); --%>
</c:when>
</c:choose>
<c:set var="subcheck">subscribe</c:set>
<c:set var="subtype" value="${param.type}" />
<c:choose>
<c:when test="${subcheck == subtype}">
<%-- ****************************************
// get the HTTP POST values and set them as variables :
// 1) type, 2) email and return OK | ERR
// for newsletter subscription HTTP POST submission
****************************************--%>
<%-- HTTP POST parameter type is equal to subscribe and email is
equal to user email ***** --%>
<c:set var="email" value="${param.email}" />
<c:out value="${email}"/>
<c:out value="${subtype}"/>
<%
response.setStatus(response.SC_OK);
response.setContentType("application/x-www-form-urlencoded");
response.setHeader("Content-Type",
"application/x-www-form-urlencoded");
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("result", "OK");
// Respond to the application with OK result
String result = "OK";
out.print("result=" + result);
// out.print("OK");
%>
<% response.setStatus(307); %>
<% response.setHeader("Location",
"http://www.laplink.com/mysupport/register/ooreg.asp"); %>
</c:when>
</c:choose>
<c:set var="updatecheck"></c:set>
<c:set var="updatetype" value="${param.type}" />
<c:choose>
<c:when test="${updatetype eq null}">
<%-- ****************************************
// get the HTTP POST values and set them as variables :
// 1) type, 2) product, 3) language, 4) versionmajor, 5)
versionminor, 6) versionbuild,
// for product registration HTTP POST submission
**************************************** --%>
<%-- set the current version number, product, and language values
for Laplink Defrag 11.5.4165 ***** --%>
<c:set var="currentProduct">Laplink Defrag Professional
Edition</c:set>
<c:set var="prod" value="${param.product}" />
<c:set var="currentLanguage">EN</c:set>
<c:set var="lang" value="${param.language}" />
<%-- major, minor and version build values for Laplink Defrag
11.0.0000 ***** --%>
<c:set var="currentMajor">11</c:set>
<c:set var="versionmaj" value="${param.versionmajor}" />
<c:set var="currentMinor">0</c:set>
<c:set var="versionmin" value="${param.versionminor}" />
<c:set var="currentBuild">0000</c:set>
<c:set var="versionbld" value="${param.versionbuild}" />
<c:choose>
<c:when test="${prod == currentProduct}">
<c:choose>
<c:when test="${versionmaj == currentMajor}">
<c:choose>
<c:when test="${versionmin ==
currentMinor}">
<c:choose>
<c:when test="${versionbld ==
currentBuild}">
<%-- product and major version URL
parameters passed match ******** --%>
<c:set var="result">OK</c:set>
<c:set var="update">0</c:set>
<c:set
var="updateid">NULL</c:set>
<%
// <c:out
value="${result}"/>
// <c:out
value="${update}"/>
// <c:out
value="${updateid}"/>
response.setStatus(response.SC_OK);
response.setContentType("application/x-www-form-urlencoded");
response.setHeader("Content-Type", "application/x-www-form-urlencoded");
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("result", "OK");
response.setIntHeader("update", 0);
response.setHeader("updateid", "NULL");
// Respond to the
application with 1) result, 2) update, and 3) updateid values
String result = "OK";
String update= "0";
String updateid= "NULL";
out.print("result=" +
result + "&");
out.print("update=" +
update + "&");
out.print("updateid=" +
updateid);
%>
</c:when>
<c:when test="${versionbld <
currentBuild}">
<%-- product and major version URL
parameters passed match ******** --%>
<c:set var="result">OK</c:set>
<c:set var="update">1</c:set>
<c:set
var="updateid">90017</c:set>
<%
// <c:out
value="${result}"/>
// <c:out
value="${update}"/>
// <c:out
value="${updateid}"/>
response.setStatus(response.SC_OK);
response.setContentType("application/x-www-form-urlencoded");
response.setHeader("Content-Type", "application/x-www-form-urlencoded");
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("result", "OK");
response.setIntHeader("update", 1);
response.setIntHeader("updateid", 90017);
// Respond to the
application with 1) result, 2) update, and 3) updateid values
String result = "OK";
String update= "1";
String updateid= "90017";
out.print("result=" +
result + "&");
out.print("update=" +
update + "&");
out.print("updateid=" +
updateid);
%>
</c:when>
</c:choose>
</c:when>
</c:choose>
</c:when>
</c:choose>
</c:when>
<c:when test="${prod != currentProduct}">
<%-- do something in the event that none of the above
parameters sent from O&O are matched --%>
<%-- user URL parameters are less than major and minor
versions specified above ******** --%>
<c:set var="result">OK</c:set>
<c:out value="${result}"/>
<% response.setStatus(response.SC_OK); %>
<%--
response.setContentType("application/x-www-form-urlencoded"); --%>
<% response.setHeader("ContentType",
"application/x-www-form-urlencoded"); %>
<% response.setHeader("result", "ERR"); %>
<%
// Respond to the application with OK result
String result = "OK";
out.print("result=" + result);
%>
<p>Your product does not match our list of available
products. There is no update for <c:out value="${prod}"/> <c:out
value="${versionmaj}"/>.<c:out value="${versionmin}"/>.<c:out
value="${versionbld}"/> available here.</p>
</c:when>
<c:otherwise>
<%-- user come to the page with no URL parameters
****************** --%>
<c:set var="result">OK</c:set>
<c:out value="${result}"/>
<% response.setStatus(response.SC_OK); %>
<%--
response.setContentType("application/x-www-form-urlencoded"); --%>
<% response.setHeader("ContentType",
"application/x-www-form-urlencoded"); %>
<% response.setHeader("result", "OK"); %>
<% response.setIntHeader("update", 0); %>
<% response.setHeader("updateid", "NULL"); %>
<%
// Respond to the application with OK result
String result = "OK";
out.print("result=" + result);
%>
<p>No URL parameters branch</p>
</c:otherwise>
</c:choose>
</c:when>
</c:choose>
Jeremy Wilson | Web Developer | Laplink Software, Inc | 425.952.6029
office | 425.952.6002 fax | mailto:jeremy.wilson at laplink.com
<mailto:jeremy.wilson at laplink.com> | www.laplink.com
<http://www.laplink.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20090804/9a759159/attachment.htm>
More information about the opencms-dev
mailing list