In Apache CXF, you create a WS endpoint by defining a jaxws:endpoint element
in XML. The WS endpoint is effectively the runtime representation of the Web service: it
opens an IP port to listen for SOAP/HTTP requests, is responsible for marshalling and
unmarshalling messages (making use of the generated Java stub code), and routes incoming
requests to the relevant methods on the implementor class.
In other words, creating a Web service in Spring XML consists essentially of the following two steps:
Create an instance of the implementor class, using the Spring
beanelement.Create a WS endpoint, using the
jaxws:endpointelement.
You can instantiate a WS endpoint using the jaxws:endpoint element in a
Spring file, where the jaxws: prefix is associated with the
http://cxf.apache.org/jaxws namespace.
![]() | Note |
|---|---|
Take care not to confuse the |
The following sample Spring file shows how to define a JAX-WS endpoint in XML, using
the jaxws:endpoint element.
<?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"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.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-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http.xml"/>
<import resource="classpath:META-INF/cxf/osgi/cxf-extension-osgi.xml"/>
<jaxws:endpoint
xmlns:customer="http://demo.fusesource.com/wsdl/CustomerService/"
id="customerService"
address="http://0.0.0.0:9191/Customer"
serviceName="customer:CustomerService"
endpointName="customer:SOAPOverHTTP"
implementor="#customerServiceImpl">
</jaxws:endpoint>
<bean id="customerServiceImpl"
class="com.fusesource.customer.ws.CustomerServiceImpl"/>
</beans>To instantiate a custom Jetty container for the endpoint, specify a complete HTTP URL,
including the host and IP port (the value of the IP port effectively identifies the target
Jetty container). Typically, for a Jetty container, you specify the host as
0.0.0.0, which is interpreted as a wildcard that matches every IP network
interface on the local machine (that is, if deployed on a multi-homed host, Jetty opens a
listening port on every network card).
The implementor attribute of the jaxws:endpoint element
references the implementation of the WS service. The value of this attribute can either be
the name of the implementation class or (as in this example) a bean reference in the
format, #, where the BeanID#
character indicates that the following identifier is the name of a bean in the bean
registry.
Because of the modular structure of Apache CXF, additional configuration is added as needed
using the relevant <import ...> tags in XML. Depending on which version of
Apache CXF you use, it might not be necessary to include all of these import tags.
The imported resources are needed as follows:
META-INF/cxf/cxf.xmlRequired for all Apache CXF versions (creates the default bus instance).
META-INF/cxf/cxf-extension-soap.xmlNeeded only for versions prior to Apache CXF 2.4.
META-INF/cxf/cxf-extension-http.xmlNeeded only for versions prior to Apache CXF 2.4.
META-INF/cxf/osgi/cxf-extension-osgi.xmlNeeded only for versions prior to Apache CXF 2.4.3.






![[Note]](imagesdb/note.gif)


