/    Sign up×
Community /Pin to ProfileBookmark

Communicating with desktop application via HTTP POST

Hello, I am trying to communicate back to desktop application that is sending a number of parameters to a web page I’ve created via HTTP POST and having difficulty determining how exactly one responds back, not to another web page but in what strikes me as somewhat of a “broadcast to the world” method.

The platform for my pages is Tomcat 5.5.17 within an OpenCMS 6 environment.

On this page, I am expecting some parameters via HTTP POST to be sent to a URL I’ve created.

At a minimum, I am trying to parse these post values and return information to the application, which the Network Monitor/Nettrace logs show me as my local machine’s IP address.

I’ve never done this before and have only a basic exposure to JSP but do have some ASP methods to reference for ideas.

Anyway, when I send values to this page via HTTP POST I do not see any activity in the Network Monitor trace. I believe it is because I am confused about what response methods to use in JSP.

The application is sending me five parameters. I am supposed to parse and match these and send back three in return.

Those are:

result=OK|ERR
update=1|0
updatedid=[Go-ID]|NULL [SIZE=”1″](Go-ID being a predetermined five digit integer value)[/SIZE]

Here is my code. Am I going about this the right way and if not, can you please provide me with an alternative example in a scriptlet format.

[CODE]<%@ page session=”false” %>
<%@ taglib prefix=”cms” uri=”http://www.opencms.org/taglib/cms” %>
<%@ 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.net.*”%>
<%@ 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>

<%
// Get the POST parameters from installer .EXE – should be passed in the HTTP POST request

String product = request.getParameter(“product”);
String language = request.getParameter(“language”);
String versionmajor = request.getParameter(“versionmajor”);
String versionminor = request.getParameter(“versionminor”);
String versionbuild = request.getParameter(“versionbuild”);
%>

<!– set the current version numbers here –>
<!– product and language values for Some Product 11.5.4165 ***** –>
<c:set var=”currentProduct”>Some Product</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 Some Product 11.5.4165 ***** –>
<c:set var=”currentMajor”>11</c:set>
<c:set var=”versionmaj” value=”${param.versionmajor}” />
<c:set var=”currentMinor”>5</c:set>
<c:set var=”versionmin” value=”${param.versionminor}” />
<c:set var=”currentBuild”>4165</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}”>
<!– product and major version HTTP POST parameters passed match ******** –>
<c:set var=”result”>OK</c:set>
<c:set var=”update”>0</c:set>
<c:set var=”updateid”>NULL</c:set>

<% response.setStatus(response.SC_OK); %>
<% response.setContentType(“text/html”); %>

<% response.setHeader(“result”, “OK”); %>
<% response.setIntHeader(“update”, 0); %>
<% response.setHeader(“updateid”, “NULL”); %>

</c:when>
<c:when test=”${versionmin < currentMinor}”>
<!– product and major version HTTP POST parameters passed match ******** –>
<c:set var=”result”>OK</c:set>
<c:set var=”update”>1</c:set>
<c:set var=”updateid”>90017</c:set>

<% response.setStatus(response.SC_OK); %>
<% response.setContentType(“text/html”); %>

<% response.setHeader(“result”, “OK”); %>
<% response.setIntHeader(“update”, 1); %>
<% response.setIntHeader(“updateid”, 90017); %>

</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 application are matched –>
<!– user HTTP POST parameters are less than major and minor versions specified above ******** –>
<c:set var=”result”>ERR</c:set>

<% response.setStatus(response.SC_OK); %>
<% response.setContentType(“text/html”); %>

<% response.setHeader(“result”, “ERR”); %>

</c:when>

<c:otherwise>
<!– user come to the page with no URL parameters ****************** –>
<c:set var=”result”>ERR</c:set>

<% response.setStatus(response.SC_OK); %>
<% response.setContentType(“text/html”); %>

<% response.setHeader(“result”, “OK”); %>
<% response.setIntHeader(“update”, 0); %>
<% response.setHeader(“updateid”, “NULL”); %>

</c:otherwise>
</c:choose>
[/CODE]

The other problem I am seeing is that when you access the page with no HTTP POST parameters, I get an internal server error. The OpenCMS error details are as follows:

[CODE]java.lang.NullPointerException
at org.apache.jsp.WEB_002dINF.jsp.offline.sites.go.index_html_jsp._jspService(index_html_jsp.java:112)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:574)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:499)
at org.opencms.flex.CmsFlexRequestDispatcher.includeExternal(CmsFlexRequestDispatcher.java:194)
at org.opencms.flex.CmsFlexRequestDispatcher.include(CmsFlexRequestDispatcher.java:170)
at org.opencms.loader.CmsJspLoader.service(CmsJspLoader.java:433)
at org.opencms.flex.CmsFlexRequestDispatcher.includeInternalWithCache(CmsFlexRequestDispatcher.java:423)
at org.opencms.flex.CmsFlexRequestDispatcher.include(CmsFlexRequestDispatcher.java:174)
at org.opencms.loader.CmsJspLoader.dispatchJsp(CmsJspLoader.java:467)
at org.opencms.loader.CmsJspLoader.load(CmsJspLoader.java:412)
at org.opencms.loader.CmsResourceManager.loadResource(CmsResourceManager.java:719)
at org.opencms.main.OpenCmsCore.showResource(OpenCmsCore.java:1332)
at org.opencms.main.OpenCmsServlet.doGet(OpenCmsServlet.java:151)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
[/CODE]

I would prefer not to see any error here but I’m not sure what I’m doing or “not doing” here that is creating this error.

to post a comment
Java

2 Comments(s)

Copy linkTweet thisAlerts:
@jeremybwilsonauthorJul 17.2009 — Can anyone speak to the issue at all? If anything about the previous post was unclear or leaves anything to the imagination please let me know and I will attempt to clarify.

At the most basic level, I need clarification on what the accepted method for broadcasting back HTTP POST parameters to a desktop application, in this case .EXE installer performing a "check for updates" that is itself an HTTP POST to my web page.

Thanks in advance.
Copy linkTweet thisAlerts:
@KuriyamaJul 17.2009 — Just to make sure I understand your objective. . .

You have a desktop app with a check for updates button. You want to send data to your web server and perform some sort of business logic then return a result back to the application.

I would recommend a web service approach for this sort of thing. From what I can tell you have a JSP sitting out there using JSTL to do your business logic and you are trying to have the application read the response of that page. You will probably want to use a web service for this sort of thing as you have a lot more control over the the process. If you develop using eclipse it will do most of the heavy lifting for you.

I don't have any examples off the top of my head. Hope this helps.
×

Success!

Help @jeremybwilson spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...