Mapping Publication IDs to friendly URLs

By default, your Content Service calls refer to Publications by their IDs, not their Web site URLs. For your convenience, you can map a Publication ID to the URL of the site that the Publication ID represents, or to another property of the Publication.

About this task

For example, say that the Publication with ID 12 corresponds to your Japanese Web site, www.example.co.jp. Without friendly URL mapping, your Content Service calls would look something like this:

http://devserver:8080/content.svc/Publications(12)/Pages

But by mapping the Publication with ID 12 to the URL www.example.co.jp, you can write the more understandable:

http://devserver:8080/www.example.co.jp/content.svc/Pages

You can also map to a full URL, including a protocol, port number, and path. Your Content Service call URL would then look something like this:

http://devserver:8080/http://www.example.co.jp:81/a/path/content.svc/Pages

Procedure

  1. To enable mapping to friendly URLs, first enable the mapping functionality. To do this, find the web.xml file of the Web application that runs your Java Content Service.
  2. Open this web.xml file for editing.
  3. Insert the following fragment in this file at the bottom of the file, as the very last child element of the root element:
    <filter>
    	<filter-name>OData publication mapping filter</filter-name>
    	<filter-class>com.tridion.webservices.odata.ODataPublicationMappingFilter</filter-class>
    </filter>
    
    <filter-mapping>
    	<filter-name>OData publication mapping filter</filter-name>
    	<servlet-name>Content Service</servlet-name>
    </filter-mapping>

    Now save and close web.xml to commit your changes.

    You have now enabled friendly URL mapping.
  4. Next, map the complex URLs you use to friendly URLs. You can configure mappings in several ways:
    Hard-coded single Publication ID

    You can redirect all friendly URLs (that is, any string after content.svc/) to a single Publication ID. To do this, access the Storage Layer configuration file, cd_storage_conf.xml, in your Web application that runs the Content Service, open it for editing, and insert the following:

    <OData>
    	<FixedPublicationId>16</FixedPublicationId>
    </OData>

    Then save and close cd_storage_conf.xml.

    If you configure this mapping, all other mappings in all other configuration files are ignored.

    Static mapping

    You can map one or more individual Web sites, identified by a domain name, port, protocol and path, to a Publication ID. To do this, access the cd_dynamic_conf.xml file in your Web application that runs the Content Service, open it for editing, and insert the following structure as the first child element inside the root element. This section may already exist, in which case you can use the mappings you see, and add new ones if needed.

    <URLMappings>
    	<StaticMappings>
    		<Publications>
    			<Publication Id="23">
    				<Host Domain="example.com" Port="91" Protocol="http" Path="/local-fr" />
    			</Publication>
    		</Publications>
    	</StaticMappings>
    	[...possible StorageMapping...]
    </URLMappings>

    In this example, you mapped the URL http://example.com:91/local-fr/ to the Publication with ID 23. Change the values to the values you need, and add new Publication elements for additional mappings you want to configure. However, the Domain attribute must have a unique value.

    Then save and close cd_dynamic_conf.xml to commit your changes.

    This type of mapping overrides the more generic table lookup mapping described below.

    Table lookup mapping

    You can configure the Content Service to map any property of the Publication to the Publication ID. To do this, access the cd_dynamic_conf.xml file in your Web application that runs the Content Service, open it for editing, and insert the following structure (if you added static mappings, the URLMappings element is already there):

    <URLMappings>
    	[...possible StaticMappings...]
    	<StorageMapping IdentifyPublicationByProperty="publicationUrl" />
    </URLMappings>

    In this example, you map the publicationUrl property to the Publication ID, but you can replace it with the name of any other property of the Publication, including ID.

    Then save and close cd_dynamic_conf.xml to apply your changes.

    This mapping is a fall-through option: only mappings that are not covered by the StaticMappings section above are looked up in the database table.

Results

You can now write Content Service command URLs that contain a mapped Web site URL (possibly including a port number, protocol and path) instead of a Publication ID.