HTTP connection problem. What is going on?

I am trying to write a simple program to test the validity of the URL via a http connection.

For the good URL, the program works very well.

Bad URL however found two ways:

1: no answer at all (program runs as if nothing happened, waiting for user input.) The text in the EditField is the same incorrect url intentionally being tested)

2: IllegalArgumentException in RIMConnector.open (int, int, String, boolean, FirewallContext) line: 76.

What is going on?

Here is the code:

import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.UiApplication;

final class UrlCheck extends UiApplication {
    private EditField urlField;
    public static void main(String[] args) {
        UrlCheck theApp = new UrlCheck();
        theApp.enterEventDispatcher();
    }

    public UrlCheck() {
        MainScreen theScreen = new MainScreen();
        LabelField title = new LabelField("URL Check");
        theScreen.setTitle(title);

        urlField = new EditField("URL: ", "", Integer.MAX_VALUE, BasicEditField.FILTER_DEFAULT);
        theScreen.add(urlField);

        FieldChangeListener listenerCancel = new FieldChangeListener() {
            public void fieldChanged(Field field, int context) {
                String URL = urlField.getText();
                HttpConnection conn = null;
                int response = 0;
                try {
                    conn = (HttpConnection)Connector.open(URL);
                    conn.setRequestMethod(HttpConnection.GET);
                    response = conn.getResponseCode();
                    if (response == 200){
                        Dialog.inform("URL OK");
                        return;
                    }
                    if(response == 401){
                        Dialog.inform("URL Requires Authorization");
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                    Dialog.inform("Bad URL");
                }
            }
        };
        ButtonField checkUrl = new ButtonField("Check");
        checkUrl.setChangeListener(listenerCancel);
        theScreen.add(checkUrl);
        pushScreen(theScreen);
    }
}

Okay, that was stupid.

I caught the IllegalArgumentException as well and it fixed the problem.

Tags: BlackBerry Developers

Similar Questions

  • Whenever I restart Windows 7, I have to turn off and then turn on my network connection get Windows 7 to recognize my wired Internet connection. What is going on?

    I installed Windows 7 Pro on a system newly built using a motherboard Gigabyte Z77x-UD5H, Intel I7 - 3770 K CPU and 32 GB DRAM3, on a SSD OCZ Vertex 3. Everything went well. It is now about three days, since I installed the operating system. I've been adding on software and other general photo editing programs. The Internet would still work. NOW all of a sudden I lost my Internet connection.  Whenever I restart Windows 7, I have to turn off and then turn on my network connection get Windows 7 to recognize my wired Internet connection. What is going on?

    Hello is a network installed by Apple, iTunes more often software Protocol.  If you do not use iTunes * (or other Apple related programs streaming) you don't need.  If you do not use iTunes check if there are any available software updates.

  • Note 'non connected' returns a lot, even if the printer is connected. What is going on?

    For a month, my printer HP don't printregularily any more, or sporadically. I've done obviously, turning works, but I always get the message "not connected". We live in a dusty, if the printer has collected too much dust in a year? We used to have this problem, what is happening, never please? Thank you... Nicole

    Hi Nicole,.

    First thing I would try is to restart everything. Unplug the printer and let that he unplugged for a minute. Then unplug the router for a few seconds then plug it back. Wait for your router to get booted back completely (when your internet connection works again), then plug the printer back in. Check the printer settings to make sure that its still connected to your wireless network. Sometimes, a good old fashioned reboot will help like that connectivity issues. In addition, depending on which printer you have, it can help to "check for updates". You can go to 'setup' > 'Web Services' > 'Product updates' > 'Check updates' and let it install the updates.

  • I get an error pop-up that says that Web page contains content that is not delivered using a secure HTTPS connection. What does that mean?

    I get an error pop-up that says that Web page contains content that is not delivered using a secure HTTPS connection, but likely to compromise the security of the entire webpage, whatever that means

    In "BOLD" on the very top of the ther security warning she also ask you want to view only the webpage content that was delivered safely?

    original title: HTTPS connection issues

    You are using Internet Explorer 8?

    This article describes the causes of this message and how you can remove:

    http://blogs.msdn.com/b/ieinternals/archive/2009/06/22/HTTPS-mixed-content-in-IE8.aspx

    Information on the changes in Internet Explorer 9 is available here:

    http://blogs.msdn.com/b/ie/archive/2011/06/23/Internet-Explorer-9-security-part-4-protecting-consumers-from-malicious-mixed-content.aspx

  • My WMC does not connect to Neflix, he said: there is a connection problem, what should I do?

    When I try to access my Netflix account in Windows Media Center, it tells me it cannot retrieve the data and check the connection.  I've seen this problem online, but not effective solutions. I uninstalled and re-installed Silverlight and Netflix for WMC but neither helped. I reset my internet connection and there again, no help. What can I do else?

    Hi Askarnes,

    Take a look at this thread and try the troubleshooting provided. Let us know if that helps at all.
  • Http connection problem... Urgent

    I m new to BB development

    I tried a code to connect to the local server to retrieve the news by sending that some Arguments say n username password, using the POST method. But when I m tryg to get the response from the server I m rather retrieve the source CODE, instead of success or failure in our case.

    I m unable to understand, where I m wrong. I want that you guys help, since I have done any hard work in desinging of the user interface and now I m stuck in connection HTTP, without which I can't move any further.

    When I try 2 recovery of response I String m to fill the Source Code of an HTML page... I need 2 get just a String (success r failure) as mentioned above.

    In the hope of a quick answer correct n

    Thanks in advance!

    String answer ="";

    Well, talk about what was your error in the thread and mark it as resolved.

    Thank you!

  • Http connection problem

    Hello

    I have some problems with httpconnection. I have to make 2 connections, first to retrieve data from a web service. The second is used to play audio data stream.

    Here's what I do:

    First of all, I call a web service using a httpconnection (this works well):

    HttpConnection httpConn = (HttpConnection)Connector.open(sLocator, Connector.READ);InputStream is = oHttpConn.openInputStream();byte[] loadedContent = IOUtilities.streamToBytes(is);ByteArrayInputStream bytestream = new ByteArrayInputStream(loadedContent);
    
    // Some work with the bytestream
    
    is.close();httpConn.close();
    

    Later in the code, I do in a separate thread:

    HttpConnection httpConn =(HttpConnection)Connector.open(sLocator);
    InputStream is = httpConn.openInputStream();
    
    player = Manager.createPlayer(is, "audio/mpeg");                                                           player.realize();
    player.prefetch();
    player.start();
    

    My problem is that this second httpconnection only works if I'm not the first one before (the web service call) (actually only when I comment the web service call the player does his job).

    Am I missing something?

    I'm working on a simulator at the moment (with SDM launched), I didn't add the parameter "deviceside" to my URL.

    However if I join '; deviceside = true' for the second connection, it works sometimes, but only if I use it in the first connection.

    Can you help me?

    Thank you

    Franck

    Hello

    Are you running the connection of two in the same thread? If this isn't the case, I make sure that the first thread of the connection was closed successfully without exception.

    Also, you must add the transport protocols to your all URLS.

    I have the same situation when I make two API calls where the 2nd call API is based on the outcome of the first and I do it in the same thread of connection and it works fine.

  • Get Cookies from a HTTP connection problem?

    Hi all!

    I'm trying to get the Http cookie header. This is my code to display the header

    for (int j = 0; j)< 20;="" j++)="">
    Key of type string = httpConn.getHeaderFieldKey (j);
    String field = httpConn.getHeaderField (j);
    If (key == null & j > 0) {}
    break;
    }
    Add (new RichTextField (key + ":" + field));
    }

    But I do not see the 'Set-Cookie' value in my put

    and here is my out put

    connection: close
    x LENGTH: 63
    Server: WEBrick/1.3.1 (Ruby/1.8.7/2009-12-04)
    Date: Friday, April 23, 2010 03:26:30 GMT
    content-length: 7985
    x-rim-etag: "FF10B6C22FA4460C654348D3E2565567D074FEE".
    cache-control: private, max - age = 0, must-revalidate
    ETag: "da5b76f5d045b108fe65b0dfb2a123d8".
    Content-location: http//192.168.11.14:15002/products
    content-type: text/html; charset = utf-8

    Thanks in advance!

    Server fixed the Cookie Set in the HTTP headers. otherwise you will never see this value in the response headers.

    Kind regards

    Sudhakar choup

  • I can't Adobe Business Catalyst. When I publish my site to my testing with Adobe Business Catalyst site, I get a message that I was out. What is going on?

    I can't Adobe Business Catalyst. When I publish my site to my testing with Adobe Business Catalyst site, I have a message that says that my Adobe ID access has expired, check your network connection. What is going on?

    Hello

    Please try to connect on Muse and sign again to make sure that Adobe ID and ID BC are synchronized.

    • To disconnect Muse, click Help > Sign Out
    • Muse of output
    • Revive the Muse and sign in with your Adobe ID.
    • Publish again to check if it works

    If the problem persists please let me know.

    Concerning

    Vivek

  • Problem Timeout of the weird HTTP connection on the BES!

    Nice day

    I seem to be lost on a TCP connection problem.

    Basically, I opened 'a' connection via TCP, and after a period of 120 seconds of inactivity, it is cleaned by the BES. Now, I've read a resource that provides information about a parameter, the "ConnectionTimeout", which I've tried setting 5 minutes (300000 ms). But this does not solve the problem. In addition, I changed a parameter in the MDS, the 'HTTP device connection period' to 300000 (ms) as well. And Ditto for the rimpublic.property file, which is located in the directory config of the BES.

    Everything seems to indicate that the maximum connection time is 120 seconds. Is this correct? This value can be overridden? If this isn't the case, so why give the possibility to increase the time-out period, without going through a sort of validation?

    Advice will be useful, the way I bypassed, now, to renew or create instance login every 90 seconds.

    See you soon,.
    Nik.

    The parameter side pocket allows to reduce the timeout to a value less than the default value set for the BlackBerry Enterprise Server.  May not go beyond what is on the side server.

  • I tried everything, but I get "SERVER NOT FOUND TRY AGAIN" when I try again his connects. What is the prayer of the problem. N ".

    I tried everything but keep getting "SERVER NOT FOUND TRY AGAIN" when I try again once it normally connects. What is the problem please

    This can have several reasons:

    first make sure that your firewall/security software allows firefox to fully access the internet.

    then you can try the solutions (proxy settings, the change of dns server) provided in this support thread: https://support.mozilla.org/de/questi.../704934

    If this does not help, also try disabling ipv6 as described here: https://support.mozilla.org/en-US/kb/Server%20not%20found?s=server%20not%...

  • My computer tells me that I have problems with web connectivity. What should I do?

    I have an Acer Aspire4752Z-4688. It's a laptop and it is ielling me constantly that I lost web connectivity. What should I do to fix this?

    Hello

    1. what web browser do you use?
    2. What is the exact message that you found?
    3. were there any changes to the computer priro to the question?

    Follow the steps in the link.

    Windows wireless and wired network connection problems
    http://Windows.Microsoft.com/en-us/Windows/help/wired-and-wireless-network-connection-problems-in-Windows

  • I have an iPhone 5 that answering an appeal not heard anything. The problem is solved by rebooting the mobile phone. What is going on?

    I have an iPhone 5 that answering an appeal not heard anything. The problem is solved by rebooting the mobile phone. What is going on?

    Try a forced reboot. Hold down the home and Sleep/Wake buttons simultaneously for about 15-20 seconds , until the Apple logo appears. Ignore the "Slide to power off" text if it rises. You won't lose anything.

  • I have connection problems with Skype video chat (Internet Explorer 8 - Windows XP pro). What I haveto do to fix this?

    I have connection problems with Skype video chat (IE 8 - XP pro.) What should I do to correct this?

    Hello

    go to skype.com and make sure you have the latest version of their software.

    Kind regards.

  • Problem in the http connection. (simulators 5.0 os blackberry 9000 smartphone)

    Hello friends,

    I am doing my project in Eclipse Platform Version: 3.4.1 4.5 os and I'm using the 8300 Simulator. I use the http connection. When I debug my project, I work correctly. I'm download 8300 same Simulator to test the object. It worked correctly in Simulator 8300.

    but when I try 4.7 and 5.0 for Simulator that I download this Simulator my project does not work correctly the problem of http connection. Someone tell where I'm wrong?

    Thank you

    Ajay.

    also to install BlackBerry JDE 5.0.

Maybe you are looking for