8 Replies Latest reply on Jun 1, 2011 4:09 AM by uteare

    Flex, Java and web services

    uteare

      I wrote a web service to update database with data come from flex. I defined a structure in an ".as" file, I defined the same class Java. I run flex application and I saw the data passed from flex to the web services from network monitor.

      Later I added a field just after the first field, I had defined i in both the files (Flex, Java) and then I run again flex application; in network monitor I saw that new field is missing.
      Have anyone had same problem? How do you solve it?
      Here is my code.

       

      DatiBlob.java:
      public class DatiBlob {

          private int key;
          private String codeMat; // add this field later
          private byte[] content;
      private String nomefile;
          private int grandezza;

      public DatiBlob()
          {
              this.key = 0;
              this.codeMat = "";
              this.content = null;
              this.nomefile = "";
              this.grandezza = 0;
      }
      // methods to get and set variables
      }

       

      DatiBlob.as:
      package valueObjects
      {
      import flash.utils.ByteArray;

       

      public class DatiBlob
      {
        public var key:int;
        public var codeMat:String;
        public var content:ByteArray;
        public var nomefile:String;
        public var grandezza:int;

        public function DatiBlob()
        {
         this.key = 0;
         this.codeMat = "";
         this.content = null;
         this.nomefile = "";
         this.grandezza = 0;
        }
      }
      }

       

      Prova.mxml:
      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark"
            xmlns:mx="library://ns.adobe.com/flex/mx"
            minWidth="955" minHeight="600">
      <fx:Script>
        <![CDATA[
         import mx.controls.Alert;
         import mx.rpc.events.FaultEvent;
         import mx.rpc.events.ResultEvent;
         import mx.utils.StringUtil;

         import valueObjects.DatiBlob;

         public var file:FileReference;

         public function browseFileSystem():void
         {
          file = new FileReference();
          file.addEventListener(Event.SELECT, selectHandler);
          file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
          file.addEventListener(ProgressEvent.PROGRESS, progressHandler);
          file.addEventListener(Event.COMPLETE, completeHandler);
          file.browse();
         }

         private function selectHandler(event:Event):void
         {
          var tipofile:String;
          var file:FileReference = FileReference(event.target);
          tipofile = (file.type).toLowerCase();
          if ((tipofile != ".doc")
           && (tipofile != ".pdf")
           && (tipofile != ".jpeg")
           && (tipofile != ".jpg"))
          {
           Alert.show("Allowed file type: doc, pdf, jpg, jpeg.");
          }
          else
          {
           if (file.name.length > 125)
            Alert.show("Filename too long.");
           else
            file.load();
          }
         }

         private function ioErrorHandler(event:IOErrorEvent):void
         {
          trace("Error io:" + event);
         }

         private function progressHandler(event:ProgressEvent):void
         {
          var file:FileReference = FileReference(event.target);
      trace("progress name:" + file.name + " bytes loaded:" + event.bytesLoaded + " total bytes:" + event.bytesTotal);
         }

         private function completeHandler(event:Event):void
         {
          var file:FileReference = FileReference(event.target);
          var grandezza:Number;
          var varDat:DatiBlob = new DatiBlob();

      trace("filename:" + file.name + " size:" + file.size + " typo:" + file.type + " key:" + varDat.key);
          if (file.size > 1048576)
          {
           Alert.show("File size exceeds the limit. File not load.");
           return;
          }
          varDat.codeMat = cheChiave.text;
          varDat.nomefile = file.name;
          varDat.content = file.data;
          varDat.grandezza = file.size;
          inserimento.scriviDatiBlob(varDat);
         }
         protected function butScrivi_clickHandler(event:MouseEvent):void
         {
          browseFileSystem();
         }
         protected function inserimento_resultHandler(event:ResultEvent):void
         {
          var risultato:String;

          risultato = inserimento.scriviDatiBlob.lastResult;
          if ((risultato != null)
           && (StringUtil.trim(risultato) != ""))
           Alert.show(risultato);
         }

         protected function inserimento_faultHandler(event:FaultEvent):void
         {
          Alert.show("Fault: insert fail.");
         }

        ]]>
      </fx:Script>
      <fx:Declarations>
        <s:WebService id="inserimento"
             wsdl="http://servername:8080/example/UpdateData?wsdl">
         <s:operation name="scriviDatiBlob"
             resultFormat="object"
             fault="mx.controls.Alert.show(event.fault.faultString)"
             result="inserimento_resultHandler(event)"/>
        </s:WebService>
      </fx:Declarations>
      <s:Button x="296" y="11" label="Write" id="butScrivi" click="butScrivi_clickHandler(event)"/>
      <s:Label x="10" y="10" text="Code" id="lblchiave"/>
      <s:TextInput x="143" y="10" id="cheChiave"/>
      </s:Application>

       

      Hope there is somebody to help me ...

      Thanks

       

      Emanuela

        • 1. Re: Flex, Java and web services
          uteare Level 1

          Nobody can help me?

           

          Emanuela

          • 2. Re: Flex, Java and web services
            Claudiu Ursica Level 4

            Did you actually get the data into Java the first time? Not only show it on the network monitor?

             

             

            I never had this issue so I can only shoot in the dark a little bit. Do you need to change anything in the wsdl file for this field?

            You can try to automatically generate the service with FB and see if it works like that...

             

            C

            • 3. Re: Flex, Java and web services
              uteare Level 1

              Hi,

              yes, the first time I ran the application I can get data in Java side, now I can get data in Java too, but only for fields defined before the change.

              In wsdl I add the field in sql insert statement and the field in database is null, in flex it isn't empty, in network monitor there isn't the field.

               

              I deleted the .as file from flex, the java class, restart tomcat and rewrite all (with the field I forgot the first time) but there wasn't any change. It seems that in some place, on disk, there are the old classes. I defined a new class (with a new name) in both flex and Java, with all the fields I need and it run correctly, but in the case I forgot something in a class (or I need to add a field in my database table) I can't delete and rewrite the class every time. Or this is the way ?

               

              Emanuela

              • 4. Re: Flex, Java and web services
                flexiblekrish Level 1

                might be stupid suggestion, cache clear and build the project and tun it.

                • 5. Re: Flex, Java and web services
                  uteare Level 1

                  Hi flexiblekrish,

                  I have already clear the cache and rebuild the project many times, but the result doesn't change.

                  So what to do now?

                   

                  Emanuela

                  • 6. Re: Flex, Java and web services
                    Claudiu Ursica Level 4

                    I am not sure how far away you are with the development of server side. Maybe try a REST style service see how that goes. I connected to .Net webservices in the past but did not encountered any issues like yours. Do you have a testing environnemnt maybe if you deploy there and test instead of flash builder?

                     

                    C

                    • 7. Re: Flex, Java and web services
                      EvyatarBH Level 3

                      When you ask the server to show the WSDL, do you see the new field?

                      Have you redeployed the updated WSDL to the server?

                      1 person found this helpful
                      • 8. Re: Flex, Java and web services
                        uteare Level 1

                        Hi,
                        I found the solution ...
                        Name variables for web service are extracted from get and set method of the class I wrote (DatiBlob) and not from the class field. So if I write getNomeFile() and setNomeFile() variable's name is nomeFile. The variable order doesn't matter because they are ordered alphabetically.


                        I hope this could help someone else.


                        Thanks to flexiblekrish, Claudiu, and, in particular, to EvyatarBH with his/her questions he/she brings me to the correct way.