Ejemplo n.º 1
0
  public ReceivingSync createReceivingSync(StreamRequestMessage message)
      throws ProtocolCreationException {
    log.fine("Creating protocol for incoming synchronous: " + message);

    if (message.getOperation().getMethod().equals(UpnpRequest.Method.GET)) {

      return new ReceivingRetrieval(getUpnpService(), message);

    } else if (getUpnpService().getConfiguration().getNamespace().isControlPath(message.getUri())) {

      if (message.getOperation().getMethod().equals(UpnpRequest.Method.POST))
        return new ReceivingAction(getUpnpService(), message);

    } else if (getUpnpService()
        .getConfiguration()
        .getNamespace()
        .isEventSubscriptionPath(message.getUri())) {

      if (message.getOperation().getMethod().equals(UpnpRequest.Method.SUBSCRIBE)) {

        return new ReceivingSubscribe(getUpnpService(), message);

      } else if (message.getOperation().getMethod().equals(UpnpRequest.Method.UNSUBSCRIBE)) {
        return new ReceivingUnsubscribe(getUpnpService(), message);
      }

    } else if (getUpnpService()
        .getConfiguration()
        .getNamespace()
        .isEventCallbackPath(message.getUri())) {

      if (message.getOperation().getMethod().equals(UpnpRequest.Method.NOTIFY))
        return new ReceivingEvent(getUpnpService(), message);
    }

    throw new ProtocolCreationException("Protocol for message type not found: " + message);
  }
Ejemplo n.º 2
0
  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);
          }
        });
  }