Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

CXF includes an "HTTP binding" which makes it easy to build REST style services. The HTTP binding allows you to take any operation and map it to arbitrary URIs and HTTP verbs (i.e. GET, PUT, POST, DELETE).

Info

This binding has been deprecated and is likely to be removed from CXF in one of its future releases.

Convention based services

...

That's straightforward enough. We see "get", we map it to a GET operation. Then people is extracted from the operation name and turned into a simple URI. Accessing http://server/peopleImage Removed would result in a document like so:

...

This will allow users to do a POST to the /customers URI with their document and add it to the collection of customers contained there.

Example with multiple arguments

To use multiple arguments, the @WebParam annotation has to be used to map the parameters of the url to the service parameters.
For example:

Code Block
java
java

@Get
@HttpResource(location="/customers/{first}/{last}") 
void findCustomer(@WebParam(name="first") String firstName, @WebParam(name="last") String lastName);

Configuring the Service

Configuration for JRA style services is exactly the same as the convention based services. However, in this example, the service is not in "wrapped" mode. So the configuration is slightly different as we don't need to explicitly set the wrapped setting:

...

Code Block
xml
xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:jaxws="http://cxf.apache.org/jaxws"
	xsi:schemaLocation="
	http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans.xsd
	http://cxf.apache.org/jaxws 
	http://cxf.apache.org/schemas/jaxws.xsd">

  <import resource="classpath:META-INF/cxf/cxf.xml"/>
  <import resource="classpath:META-INF/cxf/cxf-extension-http-binding.xml"/>
  <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
  
   <bean id="JaxWsServiceFactoryBean"
       class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean">
       <property name="wrapped" value="true" />
   </bean>
 
   <jaxws:endpoint id="userService"
		   implementor="org.apache.cxf.CustomerServiceImpl"
		   address="/customerService"
		   bindingUri="http://apache.org/cxf/binding/http">
		       <jaxws:serviceFactory>
		           <ref<bean beanclass="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean">
               <property name="wrapped" value="true" />
		           </bean>
       </jaxws:serviceFactory>
   </jaxws:endpoint>
	  
</beans>
Info
titleUseful Information

The JaxWsServiceFactoryBean is not resusable across various services.

Wrapped vs. Unwrapped Mode

...