/** Registers/subscribes the application for receiving BPS pushes */
  public void registerBPSPush(
      final String appId, final String BPDSUri, final String contentUri, final String listenUri) {
    NonBlockingReceiverDestination listenDest = null;
    NonBlockingSenderDestination bpsServerDest = null;
    try {
      final MessageListener bpsListener = new DestinationListener("BPS", true);

      final InboundDestinationConfiguration config1 =
          InboundDestinationConfigurationFactory.createBPSConfiguration(
              true, true, false, appId, BPDSUri); // serverUrl

      listenDest =
          DestinationFactory.createNonBlockingReceiverDestination(
              config1, URI.create(listenUri), bpsListener);
      final MessageListener subscriptionListener = new SubscriptionResponseListener("Subscription");
      bpsServerDest =
          DestinationFactory.createNonBlockingSenderDestination(
              _context, URI.create(contentUri), subscriptionListener);

      final ByteMessage subscrMsg =
          BpsSubscriptionMessageBuilder.createByteSubscriptionMessage(
              bpsServerDest, listenDest, "user", "pwd");

      ((HttpMessage) subscrMsg).setQueryParam("field1", "xxxxx");
      ((HttpMessage) subscrMsg).setQueryParam("osversion", "6.0");
      bpsServerDest.send(subscrMsg);
    } catch (final Exception e) {
      alertDialog(e.toString());
    }
  }
  /**
   * Uploads data in the form of streams to a server
   *
   * @param callback Callback object responsible for updating UI upon message delivery / request
   *     timeout
   */
  public void uploadStream(final String uploadUri, final ResponseCallback callback) {

    MonitoredDestinationListener responseListener;

    try {
      final URI uri = URI.create(uploadUri + ";deviceSide=true");

      responseListener =
          new MonitoredDestinationListener(
              "StreamData MessageListener [id: " + _listenerId++ + "]");
      final SenderDestination senderDestination =
          DestinationFactory.createNonBlockingSenderDestination(_context, uri, responseListener);

      // Create a byte array of size 10000
      final byte[] input = new byte[10000];
      for (int i = 0; i < input.length; i++) {
        input[i] = '5';
      }

      final ByteArrayInputStream bais = new ByteArrayInputStream(input);

      final StreamMessage message = senderDestination.createStreamMessage();
      ((HttpMessage) message).setMethod(HttpMessage.POST);

      message.setStreamPayload(bais);
      message.setPriority(2);
      message.setTransportHeader("Transfer-Encoding", "chunked");

      final TimeoutMonitor timeoutThread =
          new TimeoutMonitor(senderDestination, true, callback, responseListener, message);
      final Thread t1 = new Thread(timeoutThread, "monitor");

      t1.start();

    } catch (final Exception e) {
      alertDialog(e.toString());
    }
  }