The Service Locator feature can be used for both SOAP and RESTful Web Services.
The Service Locator configuration for Web services using the REST architectural style is similiar to the SOAP services configuration as described in previous sections.
To add the Locator feature to a RESTful service provider, use
<jaxrs:features>
including the
org.talend.esb.servicelocator.cxf.LocatorFeature
as below:
<reference id="locatorFeature" interface="org.talend.esb.servicelocator.cxf.LocatorFeature" />
<bean id="orderService" class="demo.service.OrderServiceImpl" />
<jaxrs:server id="orderRESTService" address="/rest">
<jaxrs:features>
<ref component-id="locatorFeature" />
</jaxrs:features>
<jaxrs:serviceBeans>
<ref bean="orderService" />
</jaxrs:serviceBeans>
</jaxrs:server>
To add the Locator feature to a CXF service consumer, use
<jaxrs:client>
including the
org.talend.esb.servicelocator.cxf.LocatorFeature
as below:
<reference id="locatorFeature" interface="org.talend.esb.servicelocator.cxf.LocatorFeature" />
<bean id="orderService" class="demo.service.OrderServiceImpl" />
<jaxrs:client id="restClient"
address="locator://some_useful_information"
serviceClass="demo.common.OrderService"
xmlns:serviceNamespace="http://service.demo/"
serviceName="serviceNamespace:OrderServiceImpl"
inheritHeaders="true">
<jaxrs:headers>
<entry key="Accept" value="application/xml"/>
</jaxrs:headers>
<jaxrs:features>
<ref component-id="locatorFeature" />
</jaxrs:features>
</jaxrs:client>
As shown in the example above, <jaxrs:client>
was configured by
setting the serviceName
attribute. You need this service name to
discover the endpoint from the Locator server. Please note the
serviceName
attribute specifies a service QName
, here
xmlns:serviceNamespace="http://service.demo/"
serviceName="serviceNamespace:OrderServiceImpl"
The locator
protocol in the address
attribute is used
to enable the Locator feature.