Span | ||
---|---|---|
| ||
JAX-RS : Client API |
Table of Contents |
---|
Maven Dependency
...
Code Block | ||||
---|---|---|---|---|
| ||||
<jaxrs:client id="restClient" address="http://localhost:${testutil.ports.BookServerRestSoap}/test/services/rest" serviceClass="org.apache.cxf.systest.jaxrs.BookStoreJaxrsJaxws" inheritHeaders="true"> <jaxrs:headers> <entry key="Accept" value="text/xml"/> </jaxrs:headers> </jaxrs:client> |
See this bean for a full example of how jaxrs:client can be used to inject a proxy. Note that WebClient can also be injected as a jaxrs:client.
...
The above code will send requests like "GET http://books/1", "GET http://books/2", etc.
If the request URI can be parameterized then you may want to use the following code:
...
Code Block | ||||
---|---|---|---|---|
| ||||
<bean id="myJsonProvider" class="org.apache.cxf.jaxrs.provider.JSONProvider" > <property name="supportUnwrapped" value="true" /> <property name="wrapperName" value="nodeName" /> </bean> <util:list id="webClientProviders"> <ref bean="myJsonProvider"/> </util:list> <bean id="myWebClient" class="org.apache.cxf.jaxrs.client.WebClient" factory-method="create"> <constructor-arg type="java.lang.String" value="http://some.base.url.that.responds/" /> <constructor-arg ref="webClientProviders" /> </bean> |
...
Code Block | ||||
---|---|---|---|---|
| ||||
<jaxrs:client id="webClient" address="https://localhost:${port}/services/rest" serviceClass="org.apache.cxf.jaxrs.client.WebClient"> <jaxrs:headers> <entry key="Accept" value="text/xml"/> </jaxrs:headers> </jaxrs:client> |
The only limitation of using this option is that some of jaxrs:client attributes ("inheritHeaders", "modelRef") and elements ("model") are not really applicable to WebClient.
...