Request data using a BlockingSenderDestination object

  1. Import the required classes and interfaces.
  2. Create a thread from which to call BlockingSenderDestination.sendReceive().
    Thread t = new Thread( new Runnable()
        public void run()
  3. Create a Message object to hold the response from the URL.
            Message response = null;
  4. Create a URI object to pass to the DestinationFactory class.
            URI uri = new URI("");
  5. Create a BlockingSenderDestination object.
            BlockingSenderDestination bsd = null;
  6. Retrieve the BlockingSenderDestination object for your context, if one exists.
                bsd = (BlockingSenderDestination) 
                                                 ("MyContext", uri);
  7. If no BlockingSenderDestination exists, create one.
                if(bsd == null)
                    bsd = DestinationFactory.createBlockingSenderDestination
                                                 (new Context("MyContext"), uri);
  8. Send a message and wait for the response.
                response = bsd.sendReceive();
  9. If the web service sent a response, process the response.
                if(response != null)
  10. Catch any errors that occur if the message could not be sent for some reason.
            catch (Exception e)
                // Process the error
  11. Release the BlockingSenderDestination.
                if(bsd != null)
  12. Start the thread.
After you finish: If your processResponse() updates the UI, you must do so on the main event thread, not on the thread that you created in this task. For more information, read the knowledge base article at

For a complete code sample, see "Code sample: Requesting data using a BlockingSenderDestination object".

Was this information helpful? Send us your comments.