1 Reply Latest reply: Nov 29, 2011 5:13 AM by ohad.redlich RSS

    How to retrieve data sent by Flash 4 HttpService, in the server side (Servlet)

    ohadr.com Community Member

      I'm using Flash 4.0 as UI tier, and I'm trying to send data to the server side, which runs on Tomcat. I wrote a servlet that the calls are directed to it. But I do not understand how can I see the data that was sent from the flash tier. to clarify, hereby example:

      Flash tier:

      <fx:Declarations>
         
      <s:HTTPService
             
      id="setCustomerDataService"
             
      url="http://localhost:8080/AnalyticsPortalWebUI-1.0/setCustomerData"
             
      useProxy="false" method="POST" resultFormat="text"
             
      result="onSetCustomerDataResult(event)"
             
      fault="fault(event)">
         
      </s:HTTPService>

      </fx:Declarations>

      <fx:Script>
          <![CDATA[

              private function onSubmitCustomerDataClick(event:MouseEvent):void
              {
                  var item:UsageInfoItem = new UsageInfoItem();
                              ....
                  //i use JSON to encode,but it's not related to my question
                                  var data:String = JSON.encode(item);
                  //query:
                  setCustomerDataService.send(data);
              }


          ]]>
      </fx:Script>

      my Servlet:

      public void service(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
      {
        
      //how can I retrieve "data" from flash here?
      }

      so my question - how can I retrieve "data" from Flash, in my Servlet?

      Do I sent the data correctly to the server, or do I have a mistake here? What am I missing?

      thanks, Ohad

        • 1. Re: How to retrieve data sent by Flash 4 HttpService, in the server side (Servlet)
          ohad.redlich Community Member

          this is how you do it:

          in the flash side:

                  private function onSubmitCustomerDataClick(event:MouseEvent):void
                 
          {
                     
          var item:UsageInfoItem = new UsageInfoItem();
                                     
          ....
                     
          **//this is how you do it:**
                     
          var params:Object = {};

                     
          var data:String = JSON.encode(item);
                     
          params["paramName"] = data;
                     
          //query:
                      setCustomerDataService
          .send(params);
                 
          }

          in the server end:

          public void service(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
          {
            
          String customerDataJsoned = httpRequest.getParameter("paramName");

            
          if(customerDataJsoned != null)
            
          {
                
          ObjectMapper mapper = new ObjectMapper();
                
          CustomerData customerData = mapper.readValue(customerDataJsoned, CustomerData.class);
                
          String customerId = customerData.getCustomerId();
            
          }
          }