Skip to main content

API to get the url of ContentItem?

2 replies [Last post]
Joined: 2011-11-23

I have an xlet which lists the url of all the contentitems published.
The IP address in the url is not consistent.
The APIs I tried are,

1. contentItem.getItemService().getLocator().toExternalForm().trim();
2. contentItem.getRootMetadataNode().getMetadata(UPnPConstants.RESOURCE);

Am I using the right API to get the URL?


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2009-07-25

The correct format to get the resource from the CDS is your second option.

The first option retrieves a platform dependent external representation that is not required to represent a URI, and is subject to change.

Your second option which is to read a resource from the CDS will return you a URI representing your content item. This is defined in the DIDL-Lite schema used by the UPnP CDS as a "xsd.anyURI".

When you speak of IP addresses you are referring to the "domain" section of a URL, a subset of URI. ie scheme://domain:port/path?query_string#fragment_id

The CDS returns a URL resource for network clients, with the domain portion being an IP address that is routable from the client who requested it. In this sense the IP address is required by UPnP to not be a single static address, but rather to be the correct address for the client that requested the content item. The only time you can assume it to be a singular static address is if the CDS and content server are configured to only service a single static address.

Your example doesn't demonstrate how your item was retrieved from the CDS. If this came from a ContentList as a result of a search or browse, it will have an appropriate routable domain section based upon the IP address that sent the request. ie. localhost, DHCP assigned IP, etc.

There is a configuration that can be set in the, that can enumerate the interfaces you wish to bind the CDS and content server to. This will bind to all IP addresses serviced on the interfaces specified. So only a single interface with a single assigned IP address will result in a single domain defined servicing all requests.

For finer control of the IP addresses used to service requests, there is the UPnPManagedDevice.setInetAddresses() API.

In 1.3 there is also a new API MediaServerManager.getHttpMediaPortNumber() to return the port that is being used to service content requests.

With that information you can infer the correct URL domain:port section.

Please post any follow on questions.

Joined: 2011-11-23

Thanks a lot for your detailed explanation.

As you said, I set the property "" in Now the domain section of URL is always consistent.