Uncaught exception on HttpConnection when the URL is blocked

I access my request, a service URL web restful. Whenever the device is connected, but the URL is not accessible or non-responsive for some reason, I get an untrapped exception. All I want is to catch the exception and displays an appropriate message.

Ideally, I'd like

1. check whether the URL is accessible

2. wait a little longer if the URL is accessible but slow

Please suggest. Thank you.

Code: (relevant articles)

    public void fieldChanged(Field field, int context) {

        if (field == btnOK) {
            UiApplication.getUiApplication().invokeLater(new Runnable() {

                public void run() {
                                String value=VerifyPinCode(rdPinCode.getText(),rd.getText());

                                if (value.substring(0,4).equals("true")) {
                                                                        // do stuff
                                } else {
                                    count = count++;
                                }
                              }
            });

        } else if (field == btnCancel) {
            close();
        }

    }

    public String VerifyPinCode(String PinCode, String VRN) {
        try {

            if (WebService.CheckConn())
                    {
                        try{
                    WebService wb = new WebService(
                            "http://webservice.somewhere.com:8088/mywebservice.svc/WebTestMethod/"
                                        + VRN
                                    + "/" + PinCode);
                           wb.start();
                    wb.join();
                    Responce = wb.Call();
                    }
                    catch(InterruptedException  ex)
                    {
                        Dialog.alert("No Internet Connection");
                    }
                }

public class WebService extends Thread {
    static HttpConnection con = null;
    static InputStream is = null;
    static StringBuffer rawResponse;
    String URL;
    public String resultant;

    WebService(String url) {
        URL = url + getConnectionString() + ";ConnectionTimeout=20000";

    }

    public void run() {

        try {
            con = (HttpConnection) Connector.open(URL, Connector.READ_WRITE,
                    true);
            int rcc = con.getResponseCode();

        } catch (IOException e) {
            // TODO Auto-generated catch block
            con = null;
            // Status.show(e.getMessage());
        }

        //catch (Exception ex) {
        // TODO Auto-generated catch block
        //con = null;
        // Status.show(e.getMessage());
        //}

    }

    public String Call() {
        try {

            // ConnectionTimeout=9000;";
            if (CheckConn()) {

                if (con == null) {
                    rawResponse = new StringBuffer();
                    rawResponse.append("Timed out");

                } else {
                    is = con.openInputStream();
                    // // Status.show("3");

                    byte[] responseData = new byte[10000];
                    int length = 0;
                    rawResponse = new StringBuffer();
                    while (-1 != (length = is.read(responseData))) {
                        rawResponse.append(new String(responseData, 0, length));
                        // Status.show("4");

                    }
                }
            } else {
                Status.show("Internet service is not avaiable.");
            }
            // Status.show(result);

        } catch (Exception ex) {
            Status.show("Internet is not responding");
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
                if (con != null) {
                    con.close();
                }
            } catch (Exception e) {
                // Status.show(e.getMessage());
            }
        }
        return rawResponse.toString();

    }

    public String getConnectionString() {

        String connectionString = "";
        if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
            connectionString = ";interface=wifi";
        }

        else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS) {
            connectionString = ";deviceside=false";
        } else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) {
            String carrierUid = getCarrierBIBSUid();
            if (carrierUid == null) {
                connectionString = ";deviceside=true";
            } else {
                connectionString = ";deviceside=false;connectionUID="
                        + carrierUid + ";ConnectionType=amdeeas-public";
            }
        } else if (CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE) {
            connectionString = ";None";

        }

        return connectionString;
    }

    public String getCarrierBIBSUid() {

        net.rim.device.api.servicebook.ServiceRecord[] records = ServiceBook
                .getSB().getRecords();
        int currentRecord;

        for (currentRecord = 0; currentRecord < records.length; currentRecord++) {
            if (records[currentRecord].getCid().toLowerCase().equals("ippp")) {
                if (records[currentRecord].getName().toLowerCase()
                        .indexOf("bibs") >= 0) {
                    return records[currentRecord].getUid();
                }
            }
        }

        return null;
    }

    public static boolean CheckConn() {
        try {
            if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
                return true;
            } else if (CoverageInfo.getCoverageStatus() >= 2) {
                return true;
            } else if (CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_DIRECT) {
                return false; //false for device, true for simulator
            } else {
                return false;
            }
        } catch (Exception ex) {
            Dialog.alert("No Internet Connection");
            return false;
        }
    }

}

remove the thread.join and the call to Call(), you block the user interface and the device to start a thread at all.
To get a response from the thread, you can use the callback model, for example.

Tags: BlackBerry Developers

Similar Questions

  • Uncaught exception handler application when you install the application via the Desktop Manager

    Hello

    I sometimes have a problem when I install my application on the new phones (mainly with OS6 and OS7) using the Desktop Manager. When installing the application net_rim_bb_trust_application_manager raises an uncaught exception as if had been stalled and its eventqueue was too long. The application itself is installed and works perfectly after a battery pull.

    The question is a bit like the problem described in this thread:

    http://supportforums.BlackBerry.com/T5/Java-development/Autostart-on-installation/m-p/471949#M94686

    The problem is that the solution mentioned here does not solve my problem. My request to have multiple entry points and one of them is an autostart entry point but she must leave the application, unless a parameter in the application autostart enabled (which is not the default). I don't see how this should pose problems for the application manager.

    It is also worth mentioning that this happends only when the application is installed the first time on a new device or a new version of the application that is signed with a different code signing key is installed on the device. The problem will not occur if the application is uninstalled and then installed again. This makes me think that it's something with the permissions to a...?

    Someone at - it had the same problem and solved it?

    Here are the 'new' version of this same article:

    http://supportforums.BlackBerry.com/T5/Java-development/write-safe-initialization-code/Ta-p/444795

    Not sure this is the same problem however, because the user described the problem as being present during the installation, date at which the device is fully functional.

    I agree that it is likely to be a permissions issue.  I saw on some devices that the app will throw a ControlledAcessException on first installation, associated with the PersistentStore.  My suspicion is that there is a kind of race condition between the code that runs the auto-start and the code that is supply completely, for the first time the auto start run on installation, the device is not ready for it.  I thought a few seconds delay automatic start of treatment of coding, but never tested it.

  • Bookmarks are impossible to remove when the URL is changed to the page. Why can't we organize bookmarks back?

    There is a Web bookmark page that I haven't visited in a while. They redirect the URL that I have a slightly different now. Once he gets to the page, when I go to delete the bookmark, it does not appear as a bookmark (URL is different) and will not erase the old bookmark.

    Since they changed the bookmarking to use this little window and the star, I had a lot of trouble to change URLs and / or remove bookmarks.

    When we had simple organize bookmarks in the Menu of bookmarks, things worked very well. Now, it's a pain to use, modify or delete bookmarks.

    Accordingly, I have at least two old bookmarks, that I can't remove. I just want Firefox back to something that worked.

    Organize bookmarks has been renamed to display all bookmarks. Everything works as with versions from 3.6 to 3.0.

  • How to catch exceptions in PowerCLI when the cmdlet PowerCLI

    Hello

    I count just one problem when catch exception throw by powercli cmdlet.

    I use the 'trap' to catch the exception like below:

    -


    Get-VMhost 192.168.43.110

    Trap {}

    "Exception when get-vmhost.

    }

    -


    I want to do this: when the 192.168.43.110 host did not exist or can not connect, I have to catch the error and give a friendly advice!

    but unfortunately the code in the block 'trap' has not run, and the error message will appear:

    -


    Get-VMHost: 2010-11-29 15:20:14 VMHost Get-VMHost with the name "192.168."

    .43.110' not found, using the specified filters.

    On line: 1 char: 11

    + Get-VMHost < < < < 192.168.43.110

    + CategoryInfo: ObjectNotFound: ( , VimException)

    + FullyQualifiedErrorId: Core_OutputHelper_WriteNotFoundError, VMware.VimA

    utomation.ViCore.Cmdlets.Commands.GetVMHost

    -


    Your idea will be a great help for me!

    Thanks in advance!

    Hello

    The reason you're trap code is not executed because the trap block intercepts only the errors, but the error you get is non-terminating. You can set the world

    $ErrorActionPreference = "Stop"
    

    or the cmdlet the ErrorAction parameter:

    Get-VMhost 192.168.43.110 -ErrorAction:Stop
    trap {
    "Exception when get-vmhost"
    }
    

    You can take a look at this thread Re: how to catch the VimExceptions correctly? also

    Kind regards

    Yasen Kalchev

    PowerCLI Dev Team

  • Pop-up window displayed when the url of the site is entered?

    Please can someone explain how to have a pop up appear as soon as you enter my website. So I need a little announcement to play when you land at the start of my site - so the video I see of "Lynda.com" is not what I am after forcing you to click on a link in the site. Mine needs to be there as soon as you land on my page with the option to close... Is this possible? If so, how would you please... Thank you in advance.

    You can expand the area of relaxation on the page and set the game slowing, so when the user loads the site and hover the mouse over the page, pop up appears.

    Also if you turn on autoplay, then loading the site itself the pop-up will be displayed on the screen, then you can configure on deployment of the shutter-click and place it behind any object of the page where users will not click.

    As there is no direct widget, this workaround works.

    But please feel free to add your own personalization, where you can insert a context menu using html or JavaScript.

    Thank you

    Sanjit

  • How to redirect the URL in block expection Apex 4.2

    Hi team,

    In our application, we wrote this logic as shown below

    Before the point of the process of the header: On Load before header.

    BEGIN
       IF (:p1_display_eid) IS NOT NULL
       THEN
          SELECT modified_date
            INTO :p1_modified_date
            FROM test
           WHERE id = :p1_display_eid;
       END IF;
    exception 
    when no_data_found then
    --Here i need to redirect URL to other screen 
    
    end;
    

    Kind regards

    Sruthitamiri

    Sruthi Tamiri wrote:

    In our application, we wrote this logic as shown below

    Before the point of the process of the header: On Load before header.

    1. BEGIN
    2. IF (: p1_display_eid) IS NOT NULL
    3. THEN
    4. SELECT modified_date
    5. IN: p1_modified_date
    6. OF the test
    7. WHERE ID =: p1_display_eid;
    8. END IF;
    9. exception
    10. When no_data_found then
    11. -Here, I need to redirect the URL to the other screen
    12. end;

    You can do it programmatically by using the owa_util.redirect_url method:

    BEGIN
    
      IF (:p1_display_eid) IS NOT NULL
      THEN
          SELECT modified_date
            INTO :p1_modified_date
            FROM test
          WHERE id = :p1_display_eid;
      END IF;
    
    exception
    
      when no_data_found
      then
          owa_util.redirect('');
          apex_application.stop_apex_engine();
    
    end;
    

    However I don't like the various side effects inherent in this code. It is not obvious to a developer looking at the page that executes a process will result in changing session state or the redirect to a different URL. It may involve additional database access, but I think I would prefer to implement this as a conditional branch by using a condition is no SQL, and a later calculation to set the value of the page...

  • Cannot connect to apex app with IE8 when the url has an alias DNS inside

    Hello

    Apex: 4.2

    Theme: Reactive blue 22

    IE8 browser

    It's my URL https://rxlinf01:8099/apex/f? p = 106 and I get the login screen and can connect properly.  When I use https://dba_orapwdrst:8099/apex/f? p = 106 where dba_orapwdrst is a DNS alias for rxlinf01 I get the screen to login but when I put identifying information in and press on enter nothing happens.  I'm still at the login screen, just the user name and the password that I entered was cleared.

    I have no problem when using Google Chrome as a browser.

    Any ideas?

    Thank you

    Steve.

    Support fixed it for me.  The problem was to underscore in DNS name.  Weird anyway I changed it to hyphens (-) and its fine.

  • Exception occurs. When the click button

    Hello.

    I use jdev 11.1.5
    I created a page of jspx in master and detail of the table

    I had draaged an af:button and baptized as post

    In the action listner I wrote code like
        public void cb5_actionListener(ActionEvent actionEvent) {
                       BindingContainer bc = this.getBindings();
                OperationBinding op = bc.getOperationBinding("recintGlJrnlHd");
                Object r = op.execute();
     
    In the AMimpl method, I write code like
        public void recintGlJrnlHd(List selectedRowIndexs){
            ViewObjectImpl vo = this.getGlJrnlHd1();
            Row newRow = vo.createRow();
            ViewObjectImpl c1 = this.getCursorC1_1();
            Row cr1 = c1.getCurrentRow();
            newRow.setAttribute("GjhBu", cr1.getAttribute("GrhBu"));
            newRow.setAttribute("GjhPlant", cr1.getAttribute("GrhPlant"));
            newRow.setAttribute("GjhJrnlType", cr1.getAttribute("GrvlJrnlType"));
            newRow.setAttribute("GjhJrnlNo", cr1.getAttribute("GrvlJrnlNo"));
            newRow.setAttribute("GjhJrnlSfx", cr1.getAttribute("GrhJrnlSfx"));
            newRow.setAttribute("GjhJrnlDate", cr1.getAttribute("GrhJrnlDate"));
            newRow.setAttribute("GjhYear", cr1.getAttribute("GrvlYear"));
            newRow.setAttribute("GjhPeriod", cr1.getAttribute("GrvlPeriod"));
            newRow.setAttribute("GjhDesc", cr1.getAttribute("GrhDesc"));
            newRow.setAttribute("GjhAppl", "GLM");
            newRow.setAttribute("GjhReversal", "N");
            newRow.setAttribute("GjhStatus","N");
            newRow.setAttribute("GjhCreBy", "NULL");
           newRow.setAttribute("GjhCreDate", "NULL");
            newRow.setAttribute("GjhUpdBy", "NULL");
            newRow.setAttribute("GjhUpdDate", "NULL");
            this.getTransaction().commit();
        }
    When I press the button an is Null pointer EXception
    to
    Object r = op.execute();
    can someone help me solve this problem

    have you added recintGlJrnlHd method in the section of links in your page definition file?

  • Not allow error when the URL that works in IE is entered in Firefox 17.0.9

    I copied a URL of IE that opens well and stuck to Firefox 17.0.9 and press ENTER.
    All I get is error "unauthorized".

    You can close it. Problem disappeared after erasing cookies, restart my PC and the rear connection to launch any application in Firefox. Didn't need to upgrade to the latest version of Firefox yet, since most of our applications are supported until version 17 or maybe 18 at the latest.

  • When the URL bar is the treatment his research, a fluorescent green color fills the bar for a few seconds. How to change or get rid of the color? It is hurting my eyes.

    I would like to get rid of the bright green color that fills the status bar whenever I search something.

    This feature can be added by the extension of the State-4-Evar (Tools > Modules > Extensions).

    You can check this extension Options, if you want to disable the progress indicated in the address bar.

  • How can I block access to the hard drive to windows when the computer is blocked?

    When I leave the computer on and 'blocked' option it accesses the hard drive and "work like crazy. Simple I want to block all the software to access the disk hard until I connect again.

    I want the computer to be available on the network, but does not.

    Thank you

    Sorry, but that is simply not possible.  Each computer doing something, if you're connected or not, each tick every millisecond it's on.  If you could freeze the process somehow, you would also freeze the processes and services that would allow you to access the network. Better, we advise to leave it alone, lock to prevent others from accessing and then do what you need to on the network.

  • How can I uninstall a progrm when the system administrator blocks? Who is the system administrator? If its me, how will I know what to do to correct the situation?

    I'm trying to uninstall SKYPE but I am stuck because the system administrator does not allow me.  Who is the system administrator?  If its me, how can I correct the situation?

    Hello

    If you forget the administrator password, and you do not have a password reset disk or another administrator account, you will not be able to reset the password. If there is no other user account on the computer, you will not be able to connect to Windows and you will need to re - install Windows.

    What to do if you forget your Windows password:

    http://Windows.Microsoft.com/en-us/Windows7/what-to-do-if-you-forget-your-Windows-password

    Microsoft's strategy concerning lost or forgotten passwords:

    http://support.Microsoft.com/kb/189126

  • The URL loses the settings after chopping, when redirected to the mobile site

    Ecwid shopping cart installed on the page via a plugin of MuseThemes the website http://www.litaastrologa.com/productos a. All Ecwid URL has #! to point to specific pages in the store. When the URL of page Ecwid is open in the mobile browser, web site redirects the user to the mobile site and all parameters after # are lost. Thus, Ecwid is unable to open a specific page of the store.


    For example, if you open the page dedicated to the office http://www.litaastrologa.com/productos#! / compatibility-Negócios-y-Socios/p/50299277/categ ory = 13090316 you will see a product details page. If you open the URL even on a mobile phone, the site will redirect you http://www.litaastrologa.com/phone/productos without parameters #! / compatibility-Negócios-Socios/p/50299277/category = 13090316


    We found a script that is responsible for mobile redirection:


    < script type = "text/javascript" >

    Muse.Redirect.redirect ('Office', ' tablet/productos.html', ' phone/productos.html');

    < /script >

    Is it possible to modify this script and add + window.location.hash; Tablet and phone links?


    Reactive Adobe Muse CC 2015 is now online. Please install the update of CC > Apps.

    What's new: news summary

    Release notes: https://helpx.adobe.com/muse/release-note/adobe-muse-release-notes.html

    Delicate design:

    Adobe help Muse | Create responsive Web sites

    Adobe help Muse | Responsive web design in Adobe Muse

    Adobe help Muse | Migrate existing Adobe Muse Web sites to answer

    Tutorials

    To get started with Adobe Muse (replaces how to make a website with Adobe Muse (coffee of Katie)):

    - https://helpx.adobe.com/muse/how-to/create-responsive-website.html

    Create a sensitive webpage with Adobe Muse:

    - https://helpx.adobe.com/muse/how-to/responsive-web-design.html (more detailed features RWD of Muse demo)

    Thank you

    Sanjit

  • Until the latest update when the AutoComplete bar has been selected, he "went" no other by clicking. I must now click the refresh arrow. It won't work even with the return. How can I operate the old way easier?

    Until the latest update when the url I wanted in the address bar of AutoComplete has been selected, it "accompanies" no more further by clicking on. I must now click the refresh arrow. It won't work even with the return. How can I operate the old way easier?

    You can disable this extension in tools > Modules > Extensions and close and restart Firefox normally.

  • Satellite Z830-10J battery discharge when the system is shut down

    My new Toshiba Satellite Z830 10J ultrabook with Win7 64 bit. all updates, works fine and shows no anomaly, there is however a strange exception.

    When the battery is completely charded and I 'pull the plug', the system runs on the battery for sometimes more than 5 hours, so I guess that the cycle of the battery is ok.

    When the battery is now fully charged again and I SHUT down the system and not using it for a few days.
    Then the battery is completely DISCHARGED to 0%, and the system does not start, until I plug.

    This phenomenon occurs in less than a week. So: loading of the batrery 100%, turn the system off, pull the plug, want to re - use the system after 7 days, yields 0% battery charge.

    Is there a specific reason for this?

    Greetings

    Roland Schweiger

    > It appears that one of the BIOS settings (disabling the sleep_and_charge or disable WOL) solved the problem

    Great! Thanks for the comments!

Maybe you are looking for