Results 1 to 3 of 3
  1. #1
    jeremy.wilson is offline Member
    Join Date
    Jul 2009
    Location
    Seattle, WA
    Posts
    23
    Rep Power
    0

    Default 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 (Go-ID being a predetermined five digit integer value)

    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.

    Java Code:
    <%@ page session="false" %>
    
    <%@ 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>
    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:

    Java 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)
    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.

  2. #2
    jeremy.wilson is offline Member
    Join Date
    Jul 2009
    Location
    Seattle, WA
    Posts
    23
    Rep Power
    0

    Default stripped tag libraries from my first post.

    So in order to post the first part, I had to strip out for lines of code, some of which were OpenCMS tag library references, a JSTL core/taglib, and the last two were a Jakarta string and regexp taglib.

    How do I include those lines of code if this board is preventing me from posting links until I have 20 or better?

    I supposed I could email the code offline but that seems like a huge pain.

  3. #3
    jeremy.wilson is offline Member
    Join Date
    Jul 2009
    Location
    Seattle, WA
    Posts
    23
    Rep Power
    0

    Default

    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. Thanks in advance.

Similar Threads

  1. Desktop Application - Suggestions
    By jedai in forum AWT / Swing
    Replies: 0
    Last Post: 04-26-2009, 04:43 AM
  2. Storing Array from HTTP Post
    By kskinner in forum New To Java
    Replies: 1
    Last Post: 09-08-2008, 06:00 AM
  3. three tier Desktop Application
    By newmember in forum AWT / Swing
    Replies: 0
    Last Post: 07-27-2008, 03:10 PM
  4. Installer for Java desktop application
    By nitingupta183 in forum SWT / JFace
    Replies: 0
    Last Post: 03-18-2008, 07:53 AM
  5. SOAP over HTTP/POST
    By sabatier in forum NetBeans
    Replies: 0
    Last Post: 07-10-2007, 08:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •