0 Replies Latest reply: May 27, 2011 9:11 AM by 824983 RSS

    httpRequest is truncated

    824983
      I call the function userDataRequest() when the program starts to get my test user information (i=23).
      A variable with userDataRequest (var http) is bound to a function call (HttpRequest).
      This function sends data (usually from a form, but I hard code it) to my server as a POST type format.
      It sends “user=23”. My server runs the correct file, correctly interprets the $_POST and sends back the correct data.
      The (onInput: function(is: java.io.InputStream)) sees that data is.available() and sets the user.parser.input = is; which is the input stream.
      It then calls the parser -- user.parser.parse();
      The parser sees ALL the matching MODE names and ids and captures the data for each.
      My printLn test points print the correct data for confirmation.
      My Problem is that the last item (PROFILE) is truncated. This is a string of 416 characters and stop at 343 characters.
      I know it is not special characters like a linefeed, because they cause the whole parser read to fail.

      QUESTIONS –
      is it possible to make the Java IO Stream buffer larger?
      Is this my problem?





      public var ids: String[] = [];
      public var names: String[] = [];
      
      
      
      public function userDataRequest(): Void{
      
          var i = 23; //java.lang.Integer.parseInt(currentUser.userId);
      
      
          var conv = URLConverter{};
          delete ids;
          delete names;
          var postData = [
              Pair{name:"user" value:"{i}"}
          ];
          var data = conv.encodeParameters(postData);
          var url = "http://lydias-kitchen.com/FXuser.php";
      
      
          var http: HttpRequest = HttpRequest {
      
          location: url
          method: HttpRequest.POST
          headers: [
              HttpHeader {
                  name: HttpHeader.CONTENT_TYPE;
                  value:  "application/x-www-form-urlencoded";
              },
              HttpHeader {
                  name: HttpHeader.CONTENT_LENGTH;
                  value: "{data.length()}";
              }
          ];
      
           onOutput:function (toServer: OutputStream){
                  try {
                      println("onOutput - about to write {data} bytes to output stream");
                      toServer.write(data.getBytes());
                      println ("data = {data}");
                  }finally{
                      toServer.close();
                      println ("did my output");
      
                  }
              }
      
          onInput: function(is: java.io.InputStream) {
              try {
                  if(is.available()> 0){
                    user.parser.input = is;
                    user.parser.parse();
                  }
               } finally {
                   is.close();
                   var a = ids.size();
                   println ("user ids size = {a}");
                   println("CatId = {Main.CategoryId}") ;
                   var b = bind (a-1);
      
                   for (i in [0 .. b]){
                      println("user names = {names} user ids = { ids[i]} ");

      };
      }

      }
      onException: function(ex: java.lang.Exception) {
      println("Recipe onException - exception: {ex.getClass()} {ex.getMessage()}");
      }

      }
      //Make the request connect.
      http.start();

      }




      // Temporary variables

      var ids2: String;
      var names2: String;
      var mode : String;
      var parentMode : String;
      var debug : String;

      // Pull parser object to be used in parsing the data
      def parser = PullParser {


      documentType : PullParser.JSON,
      // Event handler to handle JSON data parsing
      onEvent: function(event: Event) {
      // Temporary object used during parsing rows

      if(event.level == 0) {
      if (event.type == PullParser.START_VALUE) {
      mode = event.name;
      }
      else if(event.type == PullParser.END_VALUE) {
      }

      else if(mode != null) {
      if(mode == "user") {
      parentMode = "user";
      }
      }

      } // end of level == 0

      else if(event.level == 1){
      if(event.type == PullParser.START_ELEMENT){
      if(parentMode == "user"){
      }
      }
      else if(event.type == PullParser.END_ELEMENT) {
      insert ids2 into ids;
      insert names2 into names;
      }
      else if(event.type == PullParser.START_VALUE) {
      mode = event.name;
      }
      else if(event.type == PullParser.END_VALUE) {
      mode = null;
      }
      else if(mode != null){
      if(mode == "UserID"){
      ids2 = event.text;
      names2 = "UserID";
      }
      else if(mode == "FirstName") {
      ids2 = event.text;
      names2 = "First Name";
      }
      else if(mode == "LastName") {
      ids2 = event.text;
      names2 = "Last Name";
      }
      else if(mode == "City") {
      ids2 = event.text;
      names2 = "City";
      }
      else if(mode == "State") {
      ids2 = event.text;
      names2 = "State";
      }
      else if(mode == "Email") {
      ids2 = event.text;
      names2 = "Email";
      }
      else if(mode == "ShortName") {
      ids2 = event.text;
      names2 = "Short Name";
      }
      else if(mode == "Registered") {
      ids2 = event.text;
      names2 = "registered";
      }
      else if(mode == "Club1") {
      ids2 = event.text;
      names2 = "Club1";
      }
      else if(mode == "Club2") {
      ids2 = event.text;
      names2 = "Club2";
      }
      else if(mode == "Club3") {
      ids2 = event.text;
      names2 = "Club3";
      }
      else if(mode == "Club4") {
      ids2 = event.text;
      names2 = "Club4";
      }
      else if(mode == "moderates") {
      ids2 = event.text;
      names2 = "moderates";
      }
      else if(mode == "UserName") {
      ids2 = event.text;
      names2 = "user Name";
      }
      else if(mode == "Profile") {
      ids2 = event.text;
      names2 = "profile";
      }





      }
      } // end of level == 1
      } //end of onEvent
      } // end of parser def