/** * Sends get request and receives response using BlockingSenderDestination * * @see Thread#run() */ public void run() { BlockingSenderDestination blockSendDest = null; try { blockSendDest = (BlockingSenderDestination) DestinationFactory.getSenderDestination(_context.getName(), URI.create(_uriStr)); if (blockSendDest == null) { blockSendDest = DestinationFactory.createBlockingSenderDestination(_context, URI.create(_uriStr)); } // Send message and wait for response _response = blockSendDest.sendReceive(); if (_response != null) { _completed = true; // For "http" final String alertString = "received Message [id:" + _response.getMessageId() + "]\n" + "Response Code: " + ((HttpMessage) _response).getResponseCode(); alertDialog(alertString); } } catch (final Exception e) { _completed = true; alertDialog(e.toString()); } finally { if (blockSendDest != null) { blockSendDest.release(); } } }
/** Sets the destination. Used by message cancellation test. */ public void setNonBlockingSenderDestination(final String uriStr) { final MessageListener responseListener = new DestinationListener("Cancellation Listener", true); try { final URI uri = URI.create(uriStr); SenderDestination destination = DestinationFactory.getSenderDestination(_context.getName(), uri); if (destination == null) { // Destination not registered yet destination = DestinationFactory.createNonBlockingSenderDestination(_context, uri, responseListener); } _cancellationDest = (NonBlockingSenderDestination) destination; } catch (final Exception e) { alertDialog(e.toString()); } }
/** * Sends message to the URI using FireAndForget destination * * @param uriSenderStr Sender destination URI */ public void sendFireForget(final String uriSenderStr) { FireAndForgetDestination fireForgetDest = null; try { fireForgetDest = (FireAndForgetDestination) DestinationFactory.getSenderDestination(_context.getName(), URI.create(uriSenderStr)); if (fireForgetDest == null) { fireForgetDest = DestinationFactory.createFireAndForgetDestination(_context, URI.create(uriSenderStr)); } final int msgId = fireForgetDest.sendNoResponse(); alertDialog("Message [id:" + msgId + "] has been sent!"); } catch (final Exception e) { alertDialog(e.toString()); } }