Request data using a NonBlockingSenderDestination object

Before you begin: To request data using the NonBlockingSenderDestination class, create an object that implements the MessageListener interface. For more information, see "Implement the MessageListener interface".
  1. Import the required classes and interfaces.
    import net.rim.device.api.io.messaging.*;
    import net.rim.device.api.io.URI;
  2. Create a Message object to hold the response from the URL.
    Message response = null;
  3. Create a URI object to pass to the DestinationFactory class.
    URI uri = new URI("http://www.blackberry.com");
  4. Create a NonBlockingSenderDestination object.
    NonBlockingSenderDestination nbsd = null;
  5. Create a reference to your MessageListener.
    MyMessageListener msgListener = new MyMessageListener();
  6. Retrieve the NonBlockingSenderDestination object for your context, if one exists.
    try
    {
        nbsd = (BlockingSenderDestination) DestinationFactory.getSenderDestination
                                              ("MyContext", uri);
  7. If no NonBlockingSenderDestination exists, create one.
        if(nbsd == null)
        {
            nbsd = DestinationFactory.createNonBlockingSenderDestination
                              (new Context("MyContext"), uri, msgListener);
        }
  8. Send a message to the web service.
        nbsd.send();
  9. Catch any errors that occur if the message could not be sent for some reason.
        catch (Exception e)
        {
            // Process the error
        }
After you finish: Release the NonBlockingSenderDestination when you are done processing the response.

For a complete code sample, see "Code sample: Request data using a NonBlockingSenderDestination object"


Was this information helpful? Send us your comments.