How to cancel a http connection mid-way

Hi,
I would like to cancel a http connection mid-way.
For example, I may make a connection to a web server and the midlet will display a wait screen with a Gauge showing the status of the connection. The screen also has a Cancel button to allow the user to cancel the connection.
I have written a method to cancel the connection (as below), but it doesn't work. The connection continues to be processed.
public void cancel () {
      try {
      if (httpconn != null) httpconn.close();
      if (instrm!=null) instrm.close();
      if (outstrm!=null) outstrm.close();
      if (bStrm!=null) bStrm.close();
      } catch (Exception e) { logger.addLog("cancel "+e.toString()); }
}Has anyone successfully tried to cancel a http connection mid-way?
Thanks.

Hi,
I was also facing such problem but i got a solution for it.Method in which your are making HTTP Connection check a boolean variable after every line if
boolean variable is true than terminate connection otherwise continue connection. And set boolean variable true when cancel method is called.

Similar Messages

  • How to establish an Https connection from a html client

    Hi! I�m totally new to Java so my question is rather"stupid". I have an html page that sends a post to a servlet
    <form name="form" action="servlet/ServletLogOn" method="post">
    I want to establish an https connection between the client and the servlet. How is it?
    Thanks in advance.

    Ignore the previous poster's reply - he was obviously mislead by my original post re: JSSE.
    How you install an SSL certificate on your webserver is completely dependent on the webserver you are using. Ususally there is some functionality for doing this from the administrative interface - usually involves pasting some text from the CA's (certificate authority, e.g. Verisign) site into a text box and designating a port number for SSL traffic (use 443, it's internet standard). I've actually only done this for Netscape Enterprise Server - you may want to find a forum for users of your webserver to ask for specifics.

  • How do i make http connection  from an applet to  a servlet

    i am not able to make a http connection from the applet to servlet
    my code for servlet is as follows
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class newDatabaseServlet extends HttpServlet {
    //      Connection con;
    // Statement stmt;
         public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
              resp.setContentType("text/content");
              System.out.println("megha");
              String mthd[] = req.getParameterValues("event");
              System.out.println(mthd.length);
              System.out.println(mthd);
              System.out.println(req.getQueryString());
              // System.out.println("megha");
    PrintWriter fw = new PrintWriter(new FileOutputStream(new File("e:/JRun/servers/default/default-app/mycontent.txt")));
    String s = "this text comes from servlet";
    fw.print(s);
    fw.flush();
              if(mthd[0].equalsIgnoreCase("callEditor")) {
                   openEditor(req,resp);
    public void openEditor(HttpServletRequest req, HttpServletResponse resp) {
         /* try {
              Class.forName("oracle.jdbc.driver.OracleDriver");
         con = DriverManager.getConnection("jdbc:oracle:thin:@pc6:1521:oradba","test","test");
         catch(Exception e) {
              e.printStackTrace();
              try {
                   resp.sendRedirect("/RunApp1.html");
              catch(IOException e) {
                   e.printStackTrace();
    /*try {
         Class.forName("oracle.jdbc.driver.OracleDriver");
    con = DriverManager.getConnection("jdbc:oracle:thin:@pc6:1521:oradba","test","test");
         catch(Exception e) {
         e.printStackTrace();
         resp.setContentType("text/html");
         PrintWriter output = resp.getWriter();
         try {
    stmt = con.createStatement();
    String strContent = "select * from edTable where newsid = 2";
    ResultSet rs = stmt.executeQuery(strContent);
    if(rs.next()) {
                   String newsText = rs.getString(2);
    /* StringBuffer buf = new StringBuffer();
                   buf.append("<B>servlet</B>");
                   try {
                   resp.sendRedirect("RunApp");
              catch(IOException e) {
                   e.printStackTrace();
    //               output.println(buf.toString());
    //          output.close();
    my code for applet is
    import javax.swing.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
    import java.awt.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    public class EdApplet extends JApplet {
    public void init() {
         Container c;
         c = getContentPane();
    JPanel but = new JPanel();
    c.add(but,BorderLayout.NORTH);
    final JEditorPane je = new JEditorPane();
    JScrollPane jsp = new JScrollPane(je);
    HTMLEditorKit ht = new HTMLEditorKit();
    je.setEditorKit(ht);
    je.setEditable(true);
    HTMLDocument mdoc = (HTMLDocument)ht.createDefaultDocument();
    StyleSheet mcontext =mdoc.getStyleSheet();
    je.setDocument(mdoc);
    c.add(jsp,BorderLayout.CENTER);
    JPanel bot = new JPanel();
    c.add(bot,BorderLayout.SOUTH);
    JButton save = new JButton("save");
    but.add(save);
    String str = getInitialText();
         je.setText(str);
         String servletUrl="http://pc7:8100/servlet/newDatabaseServlet";
    try{
                   URL servletURL = new URL(servletUrl);
                   URLConnection servletConnection = servletURL.openConnection();
              servletConnection.setRequestProperty("event","saveText");
              servletConnection.setDoOutput(true);
              servletConnection.setUseCaches(false);
         catch(Exception e) {
    //          je.setText(e.printStackTrace());
         ActionListener lst = new ActionListener() {
              public void actionPerformed(ActionEvent ae) {
                   String save = je.getText();
                   saveText(save,je);
         save.addActionListener(lst);
    //je.setText("<B>this</B>");
    //URLConnection servletConnection = null;
    /* try {
              String servletUrl="http://pc7:8100/servlet/newDatabaseServlet";
              URL myUrl = new URL(servletUrl);
              servletConnection = myUrl.openConnection();
              servletConnection.setDoOutput(true);
              servletConnection.setUseCaches(false);
         /*     BufferedReader br = new BufferedReader(new InputStreamReader(servletConnection.getInputStream()));
    String t = br.readLine();
    je.setText(t);
         catch(Exception e) {
              e.printStackTrace();
    /* ActionListener lst = new ActionListener() {
              public void actionPerformed(ActionEvent ae) {
                   BufferedReader br = new BufferedReader(new InputStreamReader(servletConnection.getInputStream()));
                   String t = br.readLine();
    je.setText(t);
    click.addActionListener(lst);
    /*void String changeText(UrlConnection con) {
    BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream));
    String t = br.readLine();
    return t;
    public String getInitialText()
         //String me = null;
         URLConnection textConnection = null;
         StringBuffer sb = new StringBuffer();
         try {
                   String textUrl="http://pc7:8100/mycontent.txt";
                   URL myUrl = new URL(textUrl);
                   textConnection = myUrl.openConnection();
                   textConnection.setDoInput(true);
                   textConnection.setUseCaches(false);
                   BufferedReader br = new BufferedReader(new InputStreamReader(textConnection.getInputStream()));
                   // me = (String)servletConnection.getContent();
                   String s = null;
                   while((s = br.readLine())!=null) {
                        sb.append(s);
              catch(Exception e) {
                             e.printStackTrace();
                   return sb.toString();
         public void saveText(String saveStr,JEditorPane je) {
              //String saveStr = je.getText();
              //String servletUrl="http://pc7:8100/servlet/newDatabaseServlet?event='saveText'&newsid='2'";
              //String servletGet="http://pc7:8100/servlet/newDatabaseServlet";
              String servletUrl="http://pc7:8100/servlet/newDatabaseServlet";
              //String servletUrl = servletGet + "?"
              //     + URLEncoder.encode("event") + "="
         // + URLEncoder.encode("saveText");
    //     je.setText(servletUrl);
              try {
              URL servletURL = new URL(servletUrl);
              URLConnection servletConnection = servletURL.openConnection();
         //     servletConnection.setRequestProperty("event","saveText");
         servletConnection.setRequestProperty(
         "User-Agent","Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
              //System.out.println("from applet");
              servletConnection.setDoOutput(true);
              servletConnection.setUseCaches(false);
              //Propertiew prop = new Properties();
         //     prop.put("event","saveText");
              PrintStream out = new PrintStream(servletConnection.getOutputStream());
    out.println("event");
    out.close();
         catch(IOException e) {
              je.setText(e.toString());
    kindly tell me what is the error
    what is the best method of doing this
    thanking u in anticipation
    megha sood

    omg O_o
    We cannot debug your code, but:
    Did you try the servlet directly from your browser? Does it work?
    Best regards from Germany,
    r.v.

  • How  to create and test HTTP connection for proxy

    HI
    Can anybody help me by providing step by step guide for how to create a HTTP connection for inbound abap proxy?
    How i will get sure that connection is working properly?
    Thanks
    Debraj

    Hi Debraj,
       You should be able to do that in SM59 of the XI Box.
    Create the connection under "HTTP Connections to R/3 System".
    Provide the Target Host IP Address.Service Number and Path Prefix.
    Select the logon procedure as SAP Standard.
    SSL Inactive.
    Provide Logon details.
    Regards,
    Ravi

  • How to make HTTP connection between a midlet and a php server?

    As the title above, can anyone share how to make a HTTP connection between those 2? J2ME and PHP. Thanks a lot!

    Can you be a little more specific on what you really want.
    When i started doing j2me application, i was required to be able to comunicate to a oracle client database, and my first though was using PHP based pages to comunicate and do the query. Later they would just generate the answer and get it on the cellphone. You can communicate with a PHP server via either GET or POST. I'd choose POST as is more secure IMO.
    Here are quite a good ammount of examples of how you can do it
    http://www.java2s.com/Code/Java/J2ME/Networks.htm
    They aren't PHP based examples, but you have can an idea of how it can be done

  • How to cancel a print job in progress

    I have a HP C5580.  When i was using Windows ME on my former PC, I could easily go to Printers, select the 5580,  hit documents in queue, and hit cancel , and the printer stopped.
    Got a new Compaq  PC with Windows 7, and I can't figure out how to cancel a print job  mid stream.  I go to Printers and Devices, giet the page that allows me to view the print jobs in queue, I hit "print job in process", but the "Cancel" is not in bold print and I can'tfind any other way to cancel the job.
    Help !

    The easiest way to cancel a print job would be by pressing the cancle button on the front panel.  This is the "X" button near the right side of the control panel, see pages 10 and 11 of the user manual here.
    Bob Headrick,  HP Expert
    I am not an employee of HP, I am a volunteer posting here on my own time.
    If your problem is solved please click the "Accept as Solution" button ------------V
    If my answer was helpful please click the "Thumbs Up" to say "Thank You"--V

  • HTTP Connection For Proxies

    Hi all,
    Can anyone explain me how to create the http connection in SM59.
    Here iam getting a status error as HTTP_CONNECTION_FAILED
    here my scenario is File to Proxy
    Suggest me where i have to make this connection means in XI or SAP system regarding this scenario (file to proxy)?
    Any suggestions.
    thanx,
    krishna.

    Hi Krishna,
    When you create a RFC in SM59 provide/check the following info
    Provid the RFC destination
    Provide connection type as G HTTP connection to external server
    In description tab provide at least one description
    In technical settings provide target host name and provide service no then provide the path prefix
    Leave the  HTTP proxy options empty
    In Logon&Security tab choose basic authentication in logon procedure
    In Status of Secure Protocol choose SSL as Inactive then choose SSL Client Certificate as DEFAULT SSL Client(standard)
    In Special Options tab choose and set Specify time out 900 msec
    In HTTP Settings choose HTTP 1.0
    Compression Status choose as inactive
    Choose compression status inactive then choose compressed response as YES
    In HTTP Cookies choose Accept Cookies choose NO
    Save the connection and do a test connection it will prompt for Response from Web Server Contains Cookies Accept?  Accept all further cookies tick the box and say YES
    If you still have problem please paste the error.
    You can refer the XI trouble shooting doc at https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/bd5950ff-0701-0010-a5bc-86d45fd52283
    Cheers,
    Shyam

  • RecordStore, HTTP connections

    Hi all!
    I'm not familiar with Midlet programming, so I have some questions. I hope that programmers who have experience can give me answer.
    I think there are two things which are whireless device specific: the data storing facility and the handling of http connections.
    So my questions are:
    1. Approximately how many bytes can be stored on a mobile phone?
    2. If there are more than one midlets uploaded how can they share the storage space? If a midlet occupy the half of the available space, the other midlets the remaining space can use?
    3. How is resolved a http connection? Is it something like a dial-up connection? If yes, when is finished? When the connection is closed?
    If my midlet uses several http connections this dial-up process is always repeated?
    4. I would like to write a simple 'pizza shop'. That means that the midlet would often communicate with a web server. Is it a realizable idea? (I know it is a little bit stupid...:)
    Thanks in advance,
    holex

    answeres that i can give:
    1. its device specific, some have more memory then others.
    2. just as on your computer, they just share the memory, problems may only occure when u have 2 or more midlets running at the same time, as i heard i should be posible but never needet to do it myself.
    3. on the most mobile phones in the new group of m. phones (think all java phones are of the new generation) you phone is always on the net, you pay per package that you transfer, that meens you are always on the net, so you just need to open a connection to a server just as your pc does if you have already programmed java.net programs. you need to open only a connection and close it but do not need to dial into anything.
    remember, you are alway online, just what you send and recieve ist what you pay for.
    4. it is not only realizable but even it should be kind of easy if you are aware of client server programming. the j2me would only be your GUI.
    i will give you some idea on how to do it:
    1st. create a server in java2 or java2ee (the first one would be easyer) which will listen to a port, on request tell if there is a new pizza menue, if yes send the new one to the client if not send a 'no update' flag, listen for incoming requests and if there is a request, show it on the desktop pc's screen.
    2nd. client, which on start send a request to the server, asking for a new menue if there is one, if not show the old one. save what the user wants, (pizza with tuna and 1l coke a bottle of wine and so on...) after choosing sends the data to the server. I would do one more thing, one the first start of the programm ask the user vor his infos: tel. num., addres, and what ever you need and a unique id (time+ infos+math algo). save the settings and send it to the server which saves it.
    on the next time the saved id will be send to the server and so the user will have less connection time and less packages to send.
    there might be some more things to do but if you know java2 the normal version it should be kinda easy.
    wish you luck
    jeliel

  • What is the best way to open a HTTPS connection?

    What is the best way to open a HTTPS connection and retrieve the content as XML? This is how most of the online API is done nowadays, how can this be done on the iphone SDK?
    Thanks

    Have a look at the SeismicXML example that comes with the iPhone SDK. It uses http instead of https but it may work for you.
    You can also look at the NSURLRequest and NSURLConnection classes.
    Enjoy.

  • I would appreciate your help on how to configure a gmail in a way  it  ask  for the password  everytime I connect?. In the only way I can configure it  I have to include the pw when configuring the account  and  after that  it do not ask for pw

    I would appreciate your help on how to configure a gmail in a way  it  ask  for the password  everytime I connect?. In the only way I can configure it  I have to include the pw when configuring the account  and  after that  it do not ask for pw  so  everyone that shares my iPad can  oppen my mail  with  no pw  required.
    Thank

    The iPad is designed to be a single user device, and there is currently no way to password protect the Mail app - even removing the account password from Settings > Mail, Contacts, Calendars will just prevent new mail being downloaded, it won't hide those that have already been downloaded. There is this work-around for the app : https://discussions.apple.com/message/13127632#13127632 . Also there might be third-party email apps that feature password protecting.

  • Apple TV Movie dropped out mid way through viewing. How do I restart

    Apple TV Movie dropped out mid way through viewing. How do I restart

    If you downloaded the movie you should not need internet. My internet is over 2MGB download and around 1MGB upload and it's working perfect. The problem is to watch any movie through the apple TV2. I tried connecting via Ethernet and nothing changed.

  • I plugged in my brand new nano to my husbands desktop to get it registered, but had a problem mid way through when I tried to used an apple login that already existed.  Now it's not registered and the computer won't recognize my device.  How do I fix this

    I plugged in my brand new nano to my husbands desktop to get it registered, but had a problem mid way through when I tried to used an apple login that already existed.  Now it's not registered and the computer won't recognize my device.  How do I fix this?

    iPod not recognized in 'My Computer' and in iTunes for Windows
    Call U.S. iPod and Mac technical support: 1-800-APL-CARE (1-800-275-2273) to register your iPod Nano.

  • How do i use an alredy open HTTP connection belong to aother class

    When my apps logs in the User by checking that the username and password are correct against the server then there has been a connection opened to perform this task.
    Then the user is returned to the Main Menu.
    After that they can send some data to the server.
    Class 1 handles the sending of Username and Password.
    And has already opened a HTTP connection.
    Class 2 that will send more data to the server will need to open a connection if there is not one already open.
    How do i check if there is an open connection?
    Do i need to check?
    Can both classes use the same connection? As its to the same server and same php script.
    Thanks for you help on this (once again :-/ )
    Brian

    endPointURL = "http://www.druidev.com/php/verification_script.php";
    try
                        c = (HttpConnection)Connector.open(endPointURL);
                        c.setRequestMethod(HttpConnection.POST);
                        c.setRequestProperty("IF-Modified-Since", "20 Jan 2001 16:19:14 GMT");
                        c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Configuration/CLDC-1.0");
                        c.setRequestProperty("Content-Language", "en-CA");
                              c.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
                        os = c.openOutputStream();
                   String name = "string=name=";
                   String password_tmp = "#password=";
                   String end ="#";
                   String num_origin ="#num_origin=";
                   String num_destination= "#num_destination=";
                   String t1 = name.concat(Start.current_Username);                                                                  String t2 = password_tmp.concat(Start.current_Password);
                   String t3 = t1.concat(t2);     
                   String t4 = t3.concat(num_origin);
                   String t5 = t4.concat(phoneNum1);     
                   String t6 = t5.concat(num_destination);
                   String t7 = t6.concat(phoneNum2);
                   String Final_str = t7.concat(end);                              
                        byte postmsg[] = Final_str.getBytes();
                        for(int i=0;i<postmsg.length;i++)
                               os.write(postmsg);
              is = c.openDataInputStream();
              int ch;
              while ((ch = is.read()) != -1)
              b.append((char) ch);
    I am not using flush etc.
    I need to update a phone book that is downloaded to the phone(MIDlet) once the User is verified.
    The user can edit the phonebook on the phone then each change needs to be sent back to the php script on the server.
    Can i have a loop for the number of updates i need to do then just loop through the code?
    Or will i need to repeat the whole above operation for every update i need to make.
    E.g. 5 edits?

  • How to solve Error in http connection. Error -1

    urlMidlet2===http://localhost:8080/testProj?userId=20&selMPBL=23&svMPBL=IPOD+Touch+Screen+e!1!Tue+Jan+06+00:00:00+UTC+2009!Tue+Jan+06+00:00:00+UTC+2009!Sat+Jan+31+00:00:00+UTC+2009!Mp3+Player!IPOD!Rejected!12
    [j2mepolish] Generic/DefaultColorPhone: !1!2!1222!13333
    [j2mepolish] Generic/DefaultColorPhone: Protocol for this connection is http
    [j2mepolish] Generic/DefaultColorPhone: This object is connected to localhost host
    [j2mepolish] Generic/DefaultColorPhone: HTTP Port in use is 8080
    [j2mepolish] Generic/DefaultColorPhone: respCode=====-1
    [j2mepolish] Generic/DefaultColorPhone: Error in opening HTTP Connection. Error#-1
    Why is this error coming? How to solve it?
    Thanks in advance.
    Edited by: J2me_Beginner on Jun 7, 2009 9:38 PM

    I am making a form using an interface. When Activate the Form, I got this error:
    Invalid HTTP connection: ADS
    Message no. FPRUN000
    But I do not know how to solve or config ADS. Any one know how to slove this error ?
    Thanks a lot.

  • How do I cancel a printing job half way through?

    How do I cancel a printing job half way through?  hp psc 1310 series
    This question was solved.
    View Solution.

    Press the "Cancel" button on the printer.  It is the button on the upper left, just below the power button.  See page 2 of the manual here.
    Bob Headrick,  HP Expert
    I am not an employee of HP, I am a volunteer posting here on my own time.
    If your problem is solved please click the "Accept as Solution" button ------------V
    If my answer was helpful please click the "Thumbs Up" to say "Thank You"--V

Maybe you are looking for

  • Osx won't boot

    Hi there. I'm new here and after googling around I thought it'd be best to ask here. I attempted to use a Fedora Core 6 live cd on my mini. To have it boot up from the CD I used the Startup Utility to select it and rebooted. After ejecting the CD (ho

  • Black to white gradient?

    I am following a tutorial and need to select a fill for a shape and choose the Black to White Gradient swatch from Gradient Panel 1. I do not seem to have the black to white gradient. I only see the fade to black gradient swatch. Is this the same thi

  • Foreign Key reference

    Hi all, I have two tables called PATIENT and PERSON. All persons are not patients but all patients are persons. Now how to define the relation between the two tables? Should PATIENT have foreign key reference to PERSON or should PERSON have foreign k

  • How to create scheduled GANTT with subresources?

    Hi, Jdev 11.1.1.2.0 I want to create a scheduled GANTT where the first column contains a group name and the second column the name of the resource. I could found examples for project GANTT where the first column is a group which can be collapsed. But

  • Generate quick output to the labview

    Hi, I have two boards. One is PCI 6250 and anther one is NI 5112. I have create a program of generating a DC current for PCI 6250.  My plan is to put reset button, enable button, beep button, shock beep button, power on and off swtich, 6V to 4V switc