×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    2

    Post HTTP OutputStream - hangup app on flush?

    Hello, I try several weeks solve my issue. I try build any example for error testing:

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package hello;

    import java.io.InputStream;
    import java.io.OutputStream;
    import javax.microedition.io.Connector;
    import javax.microedition.io.HttpConnection;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Form;
    import javax.microedition.midlet.*;

    /**
    * @author Licman
    */
    public class TestConn extends MIDlet
    implements CommandListener {

    static Display d;
    public Form form;
    private Command cmdExit;
    private Command cmdConnect;

    private static String URL = "http://flexijobsin.lsw.cz/recfile.aspx";

    public void startApp() {
    d = Display.getDisplay(this);
    form = new Form("Test HTTP connection");
    cmdExit = new Command("Exit", Command.CANCEL, 2);
    cmdConnect = new Command("Connect", Command.OK, 2);
    form.addCommand(cmdExit);
    form.addCommand(cmdConnect);
    form.setCommandListener(this);

    d.setCurrent(form);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    private void Exit()
    {
    destroyApp(true);
    notifyDestroyed();
    }

    private void SendData() {
    String s = "ABCDEFGHIJKLMNOPXXXXXXXXXXXXX";
    byte outputBytes[] = s.getBytes();

    String strRes = SendBuffer(outputBytes);

    form.append(strRes);

    }

    public void commandAction(Command c, Displayable d) {
    if(c == cmdExit) {
    Exit();
    }
    if(c == cmdConnect) {
    SendData();
    }
    }

    public String SendBuffer(byte FldBytes[]){

    HttpConnection conn = null;
    OutputStream os = null;
    InputStream is = null;
    int intBytesShots = 0;

    StringBuffer b = new StringBuffer();
    StringBuffer sbErr = new StringBuffer();

    boolean blnIsInProgress = false;

    if (blnIsInProgress == false) {

    blnIsInProgress = true;

    try{
    if (FldBytes != null) {
    intBytesShots = FldBytes.length;

    form.append("Before open HTTP \n");
    try {
    conn = (HttpConnection)Connector.open(URL);
    conn.setRequestMethod(HttpConnection.POST);
    } catch (Exception e) {
    sbErr.append("1: ").append(e.toString());
    }


    form.append("Before openOutputStream \n");
    try {
    os = conn.openOutputStream();
    } catch (Exception e) {
    sbErr.append("2: ").append(e.toString()).append("\n");
    }

    // SEND buffers in loop
    int index = 0;
    int size = 512;

    form.append("Before send stream in loop \n");
    try {
    do{
    if((index+size) > intBytesShots){
    size = intBytesShots - index;
    if (size == 0) {
    break;
    }
    }
    os.write(FldBytes, index, size);
    index+=size;
    }while(index < intBytesShots);
    } catch (Exception e) {
    sbErr.append("3: ").append(e.toString()).append("\n");
    }

    form.append("Will flush and close \n");
    os.flush();
    os.close();

    form.append("Before openInputStream \n");
    is = conn.openInputStream();

    long len = 0;
    int ch = 0;

    len = conn.getLength();

    if (len != -1) {

    for (int i = 0; i < len; i++)
    if ((ch = is.read()) != -1)
    b.append((char) ch);
    } else {
    // Read til the connection is closed.
    // (Typical HTTP/1.0 script generated output)
    while ((ch = is.read()) != -1) {
    // is.available() );
    len = is.available();
    // For HTTP 1.1 servers, chunked reads.
    b.append((char) ch);
    }
    }
    }
    }catch(Exception e){
    sbErr.append("4: ").append(e.toString()).append("\n");
    }finally{
    try{
    os.close();
    }catch(Exception e){}
    try{
    is.close();
    }catch(Exception e){}
    try{
    conn.close();
    }
    catch(Exception e){}
    }
    os = null;
    is = null;
    conn = null;
    }

    if (sbErr.length() >0) {
    b = null;
    b = new StringBuffer();
    b.append(sbErr.toString());
    }

    blnIsInProgress = false;

    return b.toString();
    }

    }


    My Issue is:
    On first calling of "SendBuffer" function it works fine. Anytime in second calling too. Test application hangup in next calling. Application stop on command "os.flush();" Response is not after several minutes. Anytime it write "IOException -33" but anytime it do nothing. ONly applicaciton from.

    I use for testing mobile device Nokia C5-00 with OS symbian. For developing I use NetBeans7.

    Can you get me a tip or help please? It's very imporetant form me and I lost lot of time with finding of any solution. But I don't have a succes.

    Thank you in advice for all tips.

  2. #2
    Super Contributor
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Re: HTTP OutputStream - hangup app on flush?

    have u tried it on some other devices? Code seems OK. Im trying it on my end.. I will get back to you once i got the point..
    thanks,
    jitu_goldie..

    KEEP TRYING..

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    2

    Re: HTTP OutputStream - hangup app on flush?

    Hi,
    thank you for your answer. Yes, I was traing my code on E52, works fine and the code don't work on E51 and Samsung Xcover 271.

    Have you any tips please?

    Thank you for your answer in advice.


    Hubert Licman

    Quote Originally Posted by jitu_goldie View Post
    have u tried it on some other devices? Code seems OK. Im trying it on my end.. I will get back to you once i got the point..

Similar Threads

  1. The issue of "OutputStream.flush()"/Memory leak.
    By hreny in forum Mobile Java General
    Replies: 13
    Last Post: 2010-04-22, 13:24
  2. Urgent::ConnectionClosed Exception on outputStream.flush()
    By aparna_bhure in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2009-12-15, 18:00
  3. flush() on HTTP-POST seems to be a bad idea
    By internetlabor in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2009-05-20, 16:06
  4. http & outputstream memory problem
    By pillar in forum Mobile Java Networking & Messaging & Security
    Replies: 8
    Last Post: 2007-11-09, 13:48
  5. Does OutputStream.flush() work?
    By denisamselem in forum Mobile Java Networking & Messaging & Security
    Replies: 8
    Last Post: 2003-12-11, 08:51

Posting Permissions

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