Skip to main content

Flex and Java - HTTP Post Example

Below is Flex code sample to communicate to a Java servlet in the back-end using HTTP Post Service.


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns="*" creationComplete="send_data()">

<mx:Script>
<![CDATA[
private function send_data():void {
userRequest.send();
}
]]>
</mx:Script>

<mx:Form x="22" y="10" width="493">
<mx:HBox>
<mx:Label text="Username"/>
<mx:TextInput id="username"/>
</mx:HBox>

<mx:HBox>
<mx:Label text="Email Address"/>
<mx:TextInput id="emailaddress"/>
</mx:HBox>
<mx:Button label="Submit" click="send_data()"/>
</mx:Form>

<mx:HTTPService id="userRequest" url="http://localhost:8080/flexJavaIntegration/opendesk" useProxy="false" method="POST">
<mx:request xmlns="">
<username>{username.text}</username>
<emailaddress>{emailaddress.text}</emailaddress>
</mx:request>
</mx:HTTPService>

</mx:Application>




Now, here is the Java Servlet.


package com.opendesk.flexjava;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class OpenDeskService extends HttpServlet {

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

Enumeration en = req.getParameterNames();

while (en.hasMoreElements()) {
String key = (String) en.nextElement();
String value = (String) req.getParameter(key);

System.out.println("Key : " + key + " Value : " + value);
}
}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {

response.setContentType("text/xml");
PrintWriter writer = response.getWriter();

writer.println("<?xml version=\"1.0\"?>\n");
writer.println("<salesdata>");
writer.println("<item type=\"xxxxxxxxxxxxCDs\">");
writer.println("<profit>");
writer.println(" <beforetax>1750</beforetax>");
writer.println(" <aftertax>1600</aftertax>");
writer.println("</profit>");
writer.println("<sales>21000.23</sales>");
writer.println("</item>");
writer.println("<item type=\"DVD\">");
writer.println("<profit>");
writer.println(" <beforetax>1550.34</beforetax>");
writer.println(" <aftertax>1350.10</aftertax>");
writer.println("</profit>");
writer.println("<sales>11010.98</sales>");
writer.println("</item>");
writer.println("</salesdata>");
}
}

Comments

Popular posts from this blog

SAAS Simple Maturity Model

There are two architectural models – commonly referred as SAAS Maturity models- that describe the transition of a service to what is called Multi-tenant efficient, highly scalable application. The SAAS Maturity model described by Microsoft has four distinct stages and is illustrated below. Another similar well-known model for SaaS-maturity is known as Forrester-model but adds another stage known as "Dynamic Business Apps-as-a-service". The three key Attributes of a SAAS Architecture: Configurability: Metadata used to configure the way the application behaves for customers Multi-tenant Efficiency : Maximizing the sharing of resources across tenants Scalability: Maximizing concurrency, resource efficiency SAAS Simple Maturity Model (Microsoft, 2006) SaaS Maturity Model (Forres

SpringBoot : Performance War

Reactive Systems are designed to address challenges posed by modern software systems - the challenges related to large number of users and high throughput. Reactive systems are expected to be highly responsive, resilient, elastic and message driven. In this article we will: Build a set of fully non-blocking REST API using SpringBoot 2.0, WebFlux and Reactive Redis. Performance test the above Reactive APIs against the traditional non-reactive APIs. The code used in this example can be downloaded from GitHub Step 1: Create a skeleton Reactive WebFlux SpringBoot project Create a SpringBoot maven project using - https://start.spring.io/ Add the following dependencies: spring-boot-starter-web spring-boot-starter-data-redis spring-webflux spring-boot-starter-data-redis-reactive Refer to the dependencies in pom.xml Step 2: Create Domain Objects The demo project uses the domain objects Customer and Account . A customer can have multiple accounts.

Java Web Framework Comparison

Wikipedia has listed over 85 web applications frame works with Java based on the top – 28. Below table lists of most widely used web Application Frameworks products available today. Product what type of project is best fit? Struts 2 The new version Struts 2.0 is a combination of the Sturts action framework and Webwork (a total redesign). Struts2 may a good fit for an enterprise application when there is existing Struts resource and projects of medium complexity. Spring MVC Good choice for medium sized project. Convention-based defaults for controllers, model object names, and view resolves. Spring MVC addresses request-driven processing at the HTTP level. It does not aim to provide a component model like JSF. Stripes