Java源码示例:org.jupnp.model.types.UDN

示例1
@Before
public void setUp() {
    discoveryParticipant = getService(UpnpDiscoveryParticipant.class, HueBridgeDiscoveryParticipant.class);
    assertThat(discoveryParticipant, is(notNullValue()));

    try {
        final RemoteService remoteService = null;

        hueDevice = new RemoteDevice(
                new RemoteDeviceIdentity(new UDN("123"), 60, new URL("http://hue"), null, null),
                new DeviceType("namespace", "type"),
                new DeviceDetails(new URL("http://1.2.3.4/"), "Hue Bridge", new ManufacturerDetails("Philips"),
                        new ModelDetails("Philips hue bridge"), "serial123", "upc", null),
                remoteService);

        otherDevice = new RemoteDevice(
                new RemoteDeviceIdentity(new UDN("567"), 60, new URL("http://acme"), null, null),
                new DeviceType("namespace", "type"), new DeviceDetails("Some Device",
                        new ManufacturerDetails("Taiwan"), new ModelDetails("$%&/"), "serial567", "upc"),
                remoteService);
    } catch (final ValidationException | MalformedURLException ex) {
        Assert.fail("Internal test error.");
    }
}
 
示例2
protected Thing createThing(ThingTypeUID thingTypeUID, String channelID, String itemAcceptedType,
        WemoHttpCall wemoHttpCaller) {
    Configuration configuration = new Configuration();
    configuration.put(WemoBindingConstants.UDN, DEVICE_UDN);

    ThingUID thingUID = new ThingUID(thingTypeUID, TEST_THING_ID);

    ChannelUID channelUID = new ChannelUID(thingUID, channelID);
    Channel channel = ChannelBuilder.create(channelUID, itemAcceptedType).withType(DEFAULT_CHANNEL_TYPE_UID)
            .withKind(ChannelKind.STATE).withLabel("label").build();

    thing = ThingBuilder.create(thingTypeUID, thingUID).withConfiguration(configuration).withChannel(channel)
            .build();

    managedThingProvider.add(thing);

    ThingHandler handler = thing.getHandler();
    if (handler != null) {
        AbstractWemoHandler h = (AbstractWemoHandler) handler;
        h.setWemoHttpCaller(wemoHttpCaller);
    }

    return thing;
}
 
示例3
private RemoteDevice createUnknownRemoteDevice() throws ValidationException, MalformedURLException {
    int deviceIdentityMaxAgeSeconds = 60;
    RemoteDeviceIdentity identity = new RemoteDeviceIdentity(new UDN("unknownUDN"), deviceIdentityMaxAgeSeconds,
            new URL("http://unknownDescriptorURL"), null, null);
    URL anotherBaseURL = new URL("http://unknownBaseUrl");
    String friendlyName = "Unknown remote device";
    ManufacturerDetails manifacturerDetails = new ManufacturerDetails("UnknownManifacturer");
    ModelDetails modelDetails = new ModelDetails("unknownModel");
    String serialNumber = "unknownSerialNumber";

    DeviceDetails deviceDetails = new DeviceDetails(anotherBaseURL, friendlyName, manifacturerDetails, modelDetails,
            serialNumber, DEFAULT_UPC, DEFAULT_URI);

    final RemoteService remoteService = null;
    return new RemoteDevice(identity, DEFAULT_TYPE, deviceDetails, remoteService);
}
 
示例4
@Test
public void registryListenerShouldDetectService() throws Exception {
  upnpManager.start();

  ArgumentCaptor<RegistryListener> captor = ArgumentCaptor.forClass(RegistryListener.class);
  verify(mockedRegistry).addListener(captor.capture());
  RegistryListener listener = captor.getValue();

  assertThat(listener).isNotNull();

  // create a remote device that matches the WANIPConnection service that UpnpNatManager
  // is looking for and directly call the registry listener
  RemoteService wanIpConnectionService =
      new RemoteService(
          new UDAServiceType("WANIPConnection"),
          new UDAServiceId("WANIPConnectionService"),
          URI.create("/x_wanipconnection.xml"),
          URI.create("/control?WANIPConnection"),
          URI.create("/event?WANIPConnection"),
          null,
          null);

  RemoteDevice device =
      new RemoteDevice(
          new RemoteDeviceIdentity(
              UDN.valueOf(UpnpNatManager.SERVICE_TYPE_WAN_IP_CONNECTION),
              3600,
              new URL("http://127.63.31.15/"),
              null,
              InetAddress.getByName("127.63.31.15")),
          new UDADeviceType("WANConnectionDevice"),
          new DeviceDetails("WAN Connection Device"),
          wanIpConnectionService);

  listener.remoteDeviceAdded(mockedRegistry, device);

  assertThat(upnpManager.getWANIPConnectionService().join()).isEqualTo(wanIpConnectionService);
}
 
示例5
@Override
protected void ended(GENASubscription subscription, CancelReason reason, UpnpResponse response) {
    final Service service = subscription.getService();
    if (service != null) {
        final ServiceId serviceId = service.getServiceId();
        final Device device = service.getDevice();
        if (device != null) {
            final Device deviceRoot = device.getRoot();
            if (deviceRoot != null) {
                final DeviceIdentity deviceRootIdentity = deviceRoot.getIdentity();
                if (deviceRootIdentity != null) {
                    final UDN deviceRootUdn = deviceRootIdentity.getUdn();
                    logger.debug("A GENA subscription '{}' for device '{}' was ended", serviceId.getId(),
                            deviceRootUdn);
                }
            }
        }

        if ((CancelReason.EXPIRED.equals(reason) || CancelReason.RENEWAL_FAILED.equals(reason))
                && upnpService != null) {
            final ControlPoint cp = upnpService.getControlPoint();
            if (cp != null) {
                final UpnpSubscriptionCallback callback = new UpnpSubscriptionCallback(service,
                        subscription.getActualDurationSeconds());
                cp.execute(callback);
            }
        }
    }
}
 
示例6
@Override
public boolean isRegistered(UpnpIOParticipant participant) {
    if (upnpService.getRegistry().getDevice(new UDN(participant.getUDN()), true) != null) {
        return true;
    } else {
        return false;
    }
}
 
示例7
@Override
public URL getDescriptorURL(UpnpIOParticipant participant) {
    RemoteDevice device = upnpService.getRegistry().getRemoteDevice(new UDN(participant.getUDN()), true);
    if (device != null) {
        return device.getIdentity().getDescriptorURL();
    } else {
        return null;
    }
}
 
示例8
@Override
protected void ended(GENASubscription subscription, CancelReason reason, UpnpResponse response) {
    final Service service = subscription.getService();
    if (service != null) {
        final ServiceId serviceId = service.getServiceId();
        final Device device = service.getDevice();
        if (device != null) {
            final Device deviceRoot = device.getRoot();
            if (deviceRoot != null) {
                final DeviceIdentity deviceRootIdentity = deviceRoot.getIdentity();
                if (deviceRootIdentity != null) {
                    final UDN deviceRootUdn = deviceRootIdentity.getUdn();
                    logger.debug("A GENA subscription '{}' for device '{}' was ended", serviceId.getId(),
                            deviceRootUdn);
                }
            }
        }

        if ((CancelReason.EXPIRED.equals(reason) || CancelReason.RENEWAL_FAILED.equals(reason))
                && upnpService != null) {
            final ControlPoint cp = upnpService.getControlPoint();
            if (cp != null) {
                final UpnpSubscriptionCallback callback = new UpnpSubscriptionCallback(service,
                        subscription.getActualDurationSeconds());
                cp.execute(callback);
            }
        }
    }
}
 
示例9
@Override
public boolean isRegistered(UpnpIOParticipant participant) {
    if (upnpService.getRegistry().getDevice(new UDN(participant.getUDN()), true) != null) {
        return true;
    } else {
        return false;
    }
}
 
示例10
@Override
public URL getDescriptorURL(UpnpIOParticipant participant) {
    RemoteDevice device = upnpService.getRegistry().getRemoteDevice(new UDN(participant.getUDN()), true);
    if (device != null) {
        return device.getIdentity().getDescriptorURL();
    } else {
        return null;
    }
}
 
示例11
RemoteDevice createUpnpDevice(String modelName)
        throws MalformedURLException, ValidationException, URISyntaxException {
    return new RemoteDevice(new RemoteDeviceIdentity(new UDN(DEVICE_UDN), 60, new URL("http://wemo"), null, null),
            new DeviceType("namespace", "type"),
            new DeviceDetails(DEVICE_FRIENDLY_NAME,
                    new ManufacturerDetails(GenericWemoOSGiTest.DEVICE_MANUFACTURER), new ModelDetails(modelName),
                    new URI("http://1.2.3.4/")),
            (RemoteService) null);
}
 
示例12
public void testDiscoveryResult(ThingTypeUID thingTypeUid)
        throws MalformedURLException, ValidationException, URISyntaxException {
    String thingTypeId = thingTypeUid.getId();
    RemoteDevice device = createUpnpDevice(thingTypeId);
    DiscoveryResult result = participant.createResult(device);

    assertNotNull(result);
    assertThat(result.getThingUID(), is(new ThingUID(thingTypeUid, DEVICE_UDN)));
    assertThat(result.getThingTypeUID(), is(thingTypeUid));
    assertThat(result.getBridgeUID(), is(nullValue()));
    assertThat(result.getProperties().get(WemoBindingConstants.UDN), is(DEVICE_UDN.toString()));
    assertThat(result.getRepresentationProperty(), is(WemoBindingConstants.UDN));
}
 
示例13
protected void addUpnpDevice(String serviceTypeID, String serviceNumber, String modelName)
        throws MalformedURLException, URISyntaxException, ValidationException {
    UDN udn = new UDN(DEVICE_UDN);
    URL deviceURL = new URL(DEVICE_URL + DEVICE_DESCRIPTION_PATH);

    RemoteDeviceIdentity identity = new RemoteDeviceIdentity(udn, WemoBindingConstants.SUBSCRIPTION_DURATION,
            deviceURL, new byte[1], null);
    DeviceType type = new DeviceType(DEVICE_MANUFACTURER, DEVICE_TYPE, DEVICE_VERSION);

    ManufacturerDetails manufacturerDetails = new ManufacturerDetails(DEVICE_MANUFACTURER);
    ModelDetails modelDetails = new ModelDetails(modelName);
    DeviceDetails details = new DeviceDetails(DEVICE_FRIENDLY_NAME, manufacturerDetails, modelDetails);

    ServiceType serviceType = new ServiceType(DEVICE_MANUFACTURER, serviceTypeID);
    ServiceId serviceId = new ServiceId(DEVICE_MANUFACTURER, serviceNumber);

    // Use the same URI for control, event subscription and device description
    URI mockURI = new URI(DEVICE_URL + DEVICE_DESCRIPTION_PATH);
    URI descriptorURI = mockURI;
    URI controlURI = mockURI;
    URI eventSubscriptionURI = mockURI;

    RemoteService service = new RemoteService(serviceType, serviceId, descriptorURI, controlURI,
            eventSubscriptionURI);

    RemoteDevice localDevice = new RemoteDevice(identity, type, details, service);
    mockUpnpService.getRegistry().addDevice(localDevice);
}
 
示例14
private Device getDevice(UpnpIOParticipant participant) {
    return upnpService.getRegistry().getDevice(new UDN(participant.getUDN()), true);
}
 
示例15
private Device getDevice(UpnpIOParticipant participant) {
    return upnpService.getRegistry().getDevice(new UDN(participant.getUDN()), true);
}