public void established(GENASubscription subscription) {
   Workbench.log(
       new LogMessage(
           Level.INFO,
           "RenderingControl ControlPoint",
           "Subscription with service established, listening for events."));
 }
 public void ended(
     GENASubscription subscription, final CancelReason reason, UpnpResponse responseStatus) {
   Workbench.log(
       new LogMessage(
           reason != null ? Level.WARNING : Level.INFO,
           "RenderingControl ControlPoint",
           "Subscription with service ended. " + (reason != null ? "Reason: " + reason : "")));
   onDisconnect(reason);
 }
  public void onRemoteDeviceComplete(@Observes @Phase.Complete RemoteDeviceDiscovery discovery) {

    RemoteDevice device = discovery.getDevice();

    Workbench.log(new LogMessage(Level.INFO, "Remote device added: " + device));

    final DeviceItem deviceItem =
        new DeviceItem(
            device,
            device.getDetails().getFriendlyName(),
            device.getDisplayString(),
            "(REMOTE) " + device.getType().getDisplayString());

    Icon usableIcon = findUsableIcon(device);

    if (usableIcon != null) {

      // We retrieve it using our own infrastructure, we know how that works and behaves

      final StreamRequestMessage iconRetrievalMsg =
          new StreamRequestMessage(
              UpnpRequest.Method.GET, device.normalizeURI(usableIcon.getUri()));

      StreamResponseMessage responseMsg = router.send(iconRetrievalMsg);

      if (responseMsg != null && !responseMsg.getOperation().isFailed()) {

        MimeType contentType =
            responseMsg
                .getHeaders()
                .getFirstHeader(UpnpHeader.Type.CONTENT_TYPE, ContentTypeHeader.class)
                .getValue();

        if (isUsableImageType(contentType)) {
          byte[] imageBody = (byte[]) responseMsg.getBody();
          if (imageBody != null) {
            ImageIcon imageIcon = new ImageIcon(imageBody);
            deviceItem.setIcon(imageIcon);
          } else {
            Workbench.log(
                Level.WARNING,
                "Icon request did not return with response body '"
                    + contentType
                    + "': "
                    + iconRetrievalMsg.getUri());
          }
        } else {
          Workbench.log(
              Level.WARNING,
              "Icon was delivered with unsupported content type '"
                  + contentType
                  + "': "
                  + iconRetrievalMsg.getUri());
        }

      } else {
        if (responseMsg != null) {
          Workbench.log(
              Level.WARNING,
              "Icon retrieval of '"
                  + iconRetrievalMsg.getUri()
                  + "' failed: "
                  + responseMsg.getOperation().getResponseDetails());
        } else {
          Workbench.log(
              Level.WARNING,
              "Icon retrieval of '"
                  + iconRetrievalMsg.getUri()
                  + "' failed, no response received.");
        }
      }
    }

    if (deviceItem.getIcon() == null) {
      deviceItem.setIcon(getUnknownDeviceIcon(deviceItem.getLabel()[0]));
    }

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            view.addDeviceItem(deviceItem);
          }
        });
  }