×

Discussion Board

Results 1 to 12 of 12
  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    14

    j2me HttpConnection download fails

    Hi,

    I am simply trying to get an image from a cgi script in order to display it on my Nokia N90 phone.

    My code works through the S60 Nokia emulator but not on the deployed Nokia N90 Phone (I am using Eclipse + EclipseME + Nokia S60 SDK 3rd edition). The download image size is 0K.


    Could anyone help me please? This is an urgent issue for me...

    Here is an extract of my code :


    public void paint(Graphics g) {

    .....

    String imageData = getMapFromMapServer2(mapServerUrl+"/fast-cgi/mapservmode=map&map=/exec/applis/esgmap/current/mapserv/enville.map&mapext="+minX +"+"+minY +"+"+maxX+"+"+maxY+"&mapsize=352+290&layers=georoute4000k+georoute1000k+georoute500k+georoute250k+georoute100k+georoute50k+georoute20k+georoute5k+departements");



    ...




    The called function :

    public static String getMapFromMapServer2(String url) throws IOException {

    StringBuffer b = new StringBuffer();
    InputStream is = null;
    HttpConnection c = null;

    long len = 0;
    int ch = 0;
    c = (HttpConnection) Connector.open(url);
    is = c.openInputStream();

    //I know the size in advance
    len = 25389;


    for (int i = 0; i < len; i++)
    b.append((char) ch);

    is.close();
    c.close();
    return b.toString();
    }



    Many thanks in advance for help !!!!

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

    Re: j2me HttpConnection download fails

    hi,
    assuming you're using GET can you implement that via POST?
    it could be something with mobile data providers (lengthy urls) gateways,

    also add try/catch to your data fetching routine, check for response code from server, that helps with debuggin issues - we actually don't know what issue you're exactly getting on your device,

    btw: put fetching data route into separate thread outside of your paint method (so updates takes place after data is loaded without blocking ui thread),

    regards,
    Peter

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    14

    Re: j2me HttpConnection download fails

    Indeed, the problem is located in the URL .

    If I only use one layer like department and remove the others (georouteX...), I can download and preview the image on the mobile phone.

    If the returned image contains several layers then my method algorithm can't download any data (seems that the inputstream is empty and my downloaded image size is 0).

    On the server side, it is MAPSERVER , a server that can buid maps.

    Any idea?

    Thanks

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    14

    Re: j2me HttpConnection download fails

    Are there any issues between the S60 Nokia phones whose N90 is part of and the MIDP HttpConnection API?

    It seems weird that I can download data fine through the S60 SDK emulator and not from the real Phone (I am using Orange provider with 3G subscription)..


    Please help..............

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

    Re: j2me HttpConnection download fails

    hi barbeNoire,
    what issues? are you getting some exception at all while trying to establish connection or no data is retrieved (-1)?
    I know issue with HTTP REDIRECT responses which is discussed somewhere on forum not working as expected (but can be workarounded), others are related to data carriers (length of urls in GET, urls encoding, custom headers in POST, etc) or general microedition limits (memory size/threads/releasing resources)
    regards,
    Peter

  6. #6
    Registered User
    Join Date
    Jul 2005
    Posts
    29

    Re: j2me HttpConnection download fails

    Hi barbenoir !

    I wonder how this code works at all (correctly) because you never read from that stream. So variable 'char ch' stays 0. I hope I am right, but i looked through the code more than three times.

    regards

    Michael

  7. #7
    Registered User
    Join Date
    Nov 2006
    Posts
    14

    Re: j2me HttpConnection download fails

    Hi,

    I have modified my code as follows but the problem remains the same. I can get data fine from the cgi script on the emulator but not from the real phone :

    public String getMapFromMapServer2(String url) throws Exception {


    StringBuffer b = new StringBuffer();
    InputStream is = null;
    OutputStream os;
    HttpConnection c = null;

    long len = 0;
    int ch = 0;
    c = (HttpConnection) Connector.open(url);

    int rc = c.getResponseCode();

    System.out.println("HTTP response code: " + rc);

    if (rc != HttpConnection.HTTP_OK) {
    throw new Exception("HTTP response code: " + rc);
    }


    is = c.openInputStream();

    /*I need to hardcode the len value (size of returned image) because the cgi script does not fill the content-lenth header(len = c.getLength() returns null)*/

    len = 200000;


    System.out.println("Header content-length : " + c.getHeaderField("Content-length"));

    if (len != -1) {
    // Read exactly Content-Length bytes
    for (int i = 0; i < len; i++)

    //This is the issue : is.read() returns -1 !!!!
    if ((ch = is.read()) != -1) {
    b.append((char) ch);
    }
    }

    return b.toString();

    }



    I get Http 200 response code from the server. However, the returned inputStream is null (-1).

    Why does is.read() returns -1 on the mobile phone but not from the emulator?
    What could be the problem?

    Thanks

  8. #8
    Regular Contributor
    Join Date
    Aug 2006
    Location
    Rawalpindi, Pakistan
    Posts
    486

    Re: j2me HttpConnection download fails

    I think ur still using get method try to do it by post Method. The error ur mentioning about url usually occurs in get method.

    Also the code u provided rosenholzer is rite it is a bit hard to understand how its working. Can u provide us with detail
    Regards
    Nouman

  9. #9
    Registered User
    Join Date
    Nov 2006
    Posts
    14

    Re: j2me HttpConnection download fails

    In fact, the problem is not due to the url (I have tried shorter url without success). Same thing for POST (anyway , I need to use GET since I want to retrieve data ,not post).
    I have also moved my code out of the paint method in order to avoid thread issues ( following peterblazejewicz's advise) .

    The root of the problem is that my returned InputStream is empty (-1) when I execute my midlet on the real phone (3G Orange subscription) .This is not the case on the emulator though...

    Any ideas?

    cheers

  10. #10
    Regular Contributor
    Join Date
    Aug 2006
    Location
    Rawalpindi, Pakistan
    Posts
    486

    Re: j2me HttpConnection download fails

    when u receive a 200 response this means ur request has reached server. check the logs of the server and see what ser did after getting ur request. it would be easier for u to debug on the server side if its in ur control.
    Regards
    Nouman

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

    Re: j2me HttpConnection download fails

    hi,

    and test on other phone (device) with different data carrier or test sample midlets from SunWTK that downloads data via http requests (they are within "apps" folder in installation root). If they work rewrite your code further, if Sun's samples does not work check device access point settings o request configuration from Orange web page to reset APN. I've such issues with my APN settings that using some access points does not allow some content, so I'm using only one of available apn from my data carrier,
    thanks,
    regards,
    Peter

  12. #12
    Registered User
    Join Date
    Jul 2010
    Posts
    1

    Re: j2me HttpConnection download fails

    Quote Originally Posted by barbeNoire View Post
    Hi,

    I have modified my code as follows but the problem remains the same. I can get data fine from the cgi script on the emulator but not from the real phone :

    public String getMapFromMapServer2(String url) throws Exception {


    StringBuffer b = new StringBuffer();
    InputStream is = null;
    OutputStream os;
    HttpConnection c = null;

    long len = 0;
    int ch = 0;
    c = (HttpConnection) Connector.open(url);

    int rc = c.getResponseCode();

    System.out.println("HTTP response code: " + rc);

    if (rc != HttpConnection.HTTP_OK) {
    throw new Exception("HTTP response code: " + rc);
    }


    is = c.openInputStream();

    /*I need to hardcode the len value (size of returned image) because the cgi script does not fill the content-lenth header(len = c.getLength() returns null)*/

    len = 200000;


    System.out.println("Header content-length : " + c.getHeaderField("Content-length"));

    if (len != -1) {
    // Read exactly Content-Length bytes
    for (int i = 0; i < len; i++)

    //This is the issue : is.read() returns -1 !!!!
    if ((ch = is.read()) != -1) {
    b.append((char) ch);
    }
    }

    return b.toString();

    }



    I get Http 200 response code from the server. However, the returned inputStream is null (-1).

    Why does is.read() returns -1 on the mobile phone but not from the emulator?
    What could be the problem?

    Thanks
    hello can i see your code for request map (mapserver to j2me)
    thx very much

Similar Threads

  1. J2ME game demo download - to play and feedback
    By FrankFera in forum Mobile Java General
    Replies: 0
    Last Post: 2005-05-16, 06:55
  2. Free J2ME Web Site for download testing
    By arspeiser in forum Mobile Java General
    Replies: 10
    Last Post: 2004-03-31, 23:46
  3. drm object download fails
    By aurola in forum Digital Rights Management & Content Downloading
    Replies: 4
    Last Post: 2003-08-12, 11:28
  4. j2me application download
    By m_mogensen in forum Mobile Java General
    Replies: 1
    Last Post: 2002-08-22, 13:08

Posting Permissions

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