6 Replies Latest reply on Jul 15, 2009 7:16 AM by agreeshma

    Problem reading servlet response in HttpService result handler

    agreeshma

      Hello,

       

      I am trying to invoke a service (servlet) which returns a string in xml format and I would like to read the same in the result handler of my HttpService. But I am having no luck with it. Below is my code. Please advice!

       

           My mxml code

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application

       

      xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="fetchGallery();" layout="absolute">

      <mx:TraceTarget/>

       

      <mx:Script>

      <![CDATA[

       

      import ItemListObject;

       

      import mx.controls.Alert;

       

      import mx.rpc.events.FaultEvent;

       

      import mx.rpc.events.ResultEvent;

       

      import mx.utils.ObjectUtil;

       

       

      public function fetchGallery():void

      {

      Security.allowDomain(

      "*");

      imageFetcher.send();

      }

       

      private function getResultOk(event:ResultEvent):void{

      Alert.show(

      "event.result.toString() is "+ imageFetcher.lastResult.ROW);

       

      //resultDisplay.text = ObjectUtil.toString(imageFetcher.lastResult);

      }

       

      private function getFault(event:FaultEvent):void{

      Alert.show(event.fault.toString(),

      "Error Occurred!!");

      }

       

      ]]>

       

      </mx:Script>

       

       

      <mx:HTTPService id="imageFetcher"

      url="**********

      images.do"

      method="

      GET" showBusyCursor="true"

      result="getResultOk(event)"

      fault="getFault(event)"

      >

       

      </mx:HTTPService>

       

      <mx:TextArea id="resultDisplay" width="100%" height="100%">

       

       

       

      </mx:TextArea>

       

      </mx:Application>

       

       

      My Servlet code

          public void doGet(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
              Connection con = null;
              PrintWriter out = null;
              try {
                      con = <getconnection>
                      OracleXMLQuery qry = new OracleXMLQuery(con, "<my query>");
                      String xmlString = qry.getXMLString();
                      System.out.println(xmlString);
                      response.setContentType("text/xml");
                      out=response.getWriter();
                      out.write(xmlString);

              } catch (Exception ee) {
                  ee.printStackTrace();
              }
              finally{
                   out.close();
              }

          }


      My xmlString is something like

      <?xml version = '1.0'?>
      <ROWSET>
         <ROW num="1">
            <ID>1</ID>
            <NAME>Image 1</NAME>
            <DESCRIPTION>Image 1</DESCRIPTION>
            <URL>1.jpg</URL>
            <CATEGORY_ID>1</CATEGORY_ID>
            <TYPE>1</TYPE>
         </ROW>
         <ROW num="2">
            <ID>2</ID>
            <NAME>Image 2</NAME>
            <DESCRIPTION>Image 2</DESCRIPTION>
            <URL>2.jpg</URL>
            <CATEGORY_ID>2</CATEGORY_ID>
            <TYPE>1</TYPE>
         </ROW>
      </ROWSET>