×

Discussion Board

Results 1 to 15 of 25

Hybrid View

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    29

    KVM crashes when reading content with HTTP "302 Found" response on N90 and 6680

    Hello
    I found that a MIDlet will silently die on Nokia N90 and 6680 when trying to read the content of an HTTP "302 Found" server response.
    Here is a small code showing it :

    Code:
    import javax.microedition.midlet.*;
    import javax.microedition.io.*;
    import java.io.*;
    import javax.microedition.lcdui.*;
    
    public class Test
    extends MIDlet
    {
      private static final String URL = "http://server.domain/your_script.php"
      
      protected void startApp() throws MIDletStateChangeException
      {
        Form f = new Form( "Test" );
        String response="";
        try {
          HttpConnection con = 
            (HttpConnection)Connector.open( URL, Connector.READ );
          InputStream in = con.openInputStream();
          InputStreamReader reader = new InputStreamReader(in);
          char content[] = new char[1024];
          int len = reader.read( content, 0, 1024 );
          reader.close();
          in.close();
          response = String.valueOf(content,0,len);
        }
        catch( IOException e ) {}
        f.append( new StringItem("Reponse : ", response, StringItem.PLAIN) );
        Display.getDisplay(this).setCurrent(f);
      }
    
      protected void pauseApp() {}
    
      protected void destroyApp(boolean arg0) throws MIDletStateChangeException{}
    }
    And here is the server-side PHP code to generate a HTTP 302 reply with content :
    Code:
    <?php
    header('Location: http://www.forum.nokia.com/' );
    echo 'plop';
    ?>
    It was REALLY hard to find out why my much more complicated app kept on crashing...
    Isn't that part of the HTTP standard to send a content together with a 302 reply ?

  2. #2
    Regular Contributor
    Join Date
    Jun 2003
    Posts
    73

    Re: KVM crashes when reading content with HTTP "302 Found" response on N90 and 6680

    hey, i feel your pain, 6630/6680 crashes too, n70 does not , but conenction still can not get through, any idea?

  3. #3
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: KVM crashes when reading content with HTTP "302 Found" response on N90 and 6680

    hi,

    shouldn't getResponseCode/getResponseMessage of HTTPConnection be used to handle that situation correctly?

    regards,
    Peter

  4. #4
    Registered User
    Join Date
    Oct 2004
    Posts
    29

    Re: KVM crashes when reading content with HTTP "302 Found" response on N90 and 6680

    peterblazejewicz, getResponseCode() would return (int)302 and getResponseMessage() "302 Found".
    What I wanted was the actual content of the HTTP reply (i.e. what comes after the reply headers).

    I had the developer of the web service change his API to let the MIDlet connect but this is a workaround. Even if a 302 HTTP reply means that the content has moved to another URI specified in the Location: header, it seems to me that some content can be sent together (and actual implementations allow it, e.g. Apache 2 for the server-side and Nokia 3230 for client-side).

    See http://www.w3.org/Protocols/rfc2616/...html#sec10.3.3 for info on "302 Found" HTTP reply.

  5. #5
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: KVM crashes when reading content with HTTP "302 Found" response on N90 and 6680

    hi Emmanuel,

    well, I was under impression (remember that I'm still learner) that correct action is to:
    - bypass read headers/content routine
    - close current connection
    - reopen current conenction using Location header to request correct data,
    it's based on sample I've used some time ago:
    Code:
    private HttpConnection open(String url) throws IOException {
        HttpConnection c;
        int status = -1;
    
        // Open the connection and check for redirects
        while (true) {
          c = (HttpConnection) Connector.open(url);
    
          // Get the status code,
          // causing the connection to be made
          status = c.getResponseCode();
    
          if ((status == HttpConnection.HTTP_TEMP_REDIRECT)
              || (status == HttpConnection.HTTP_MOVED_TEMP)
              || (status == HttpConnection.HTTP_MOVED_PERM)) {
    
            // Get the new location and close the connection
            url = c.getHeaderField("location");
            c.close();
          } else {
            break;
          }
        }
    
        // Only HTTP_OK (200) means the content is returned.
        if (status != HttpConnection.HTTP_OK) {
          c.close();
          throw new IOException("Response status not OK");
        }
        return c;
      }
    and notes from MIDP docs:
    302: The requested resource resides temporarily under a different URI. (Note: the name of this status code reflects the earlier publication of RFC2068, which was changed in RFC2616 from "moved temporalily" to "found". The semantics were not changed. The Location header indicates where the application should resend the request.)
    that's I've learned so far but could be wrong of course,
    hth,
    regards,
    Peter

  6. #6
    Regular Contributor
    Join Date
    Jun 2003
    Posts
    73

    Re: KVM crashes when reading content with HTTP "302 Found" response on N90 and 6680

    keep watching the thread , hope to get a way to handle 302 on s50 properly....

Similar Threads

  1. Play video downloaded over HTTP on 6680 and N90
    By Emmanuel Raulo in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2006-02-07, 08:29

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×