You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Please see the Configuration section to learn how to supply a configuration to CXF. The following sections just include the JAX-WS specific configuration information.

Configuring an Endpoint

A JAX-WS Endpoint can be configured in XML in addition to using the JAX-WS APIs. Once you've created your server implementation, you simply need to provide the class name and an address. Here is a simple example:

<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-2.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

<jaxws:endpoint 
  id="helloWorld" 
  implementor="demo.spring.HelloWorldImpl" 
  address="http://localhost/HelloWorld" />  

</beans>

Be sure to include the JAX-WS schemaLocation attribute specified on the root beans element. This allows CXF to validate the file and is required.

The <jaxws:endpoint> element supports many additional attributes:

Name

Value

portName

The port name this service is implementing. In the format of "{NAMESPACE}PORT_NAME".

publish

Whether the endpoint should be published now, or whether it will be published at a later point.

serviceName

The service name this service is implementing. In the format of "{NAMESPACE}SERVICE_NAME".

wsdlLocation

The location of the WSDL. Can be on the classpath, file system, or be hosted remotely.

It also supports many child elements:

Name

Value

jaxws:executor

A Java executor which will be used for the service. This can be supplied using the Spring <bean class="MyExecutor"/> syntax.

jaxws:inInterceptors

The incoming interceptors for this endpoint. A list of <bean>s or <ref>s.

jaxws:inFaultInterceptors

The incoming fault interceptors for this endpoint. A list of <bean>s or <ref>s.

jaxws:outInterceptors

The outgoing interceptors for this endpoint. A list of <bean>s or <ref>s.

jaxws:outFaultInterceptors

The outgoing fault interceptors for this endpoint. A list of <bean>s or <ref>s.

jaxws:properties

A properties map which should be supplied to the JAX-WS endpoint. See below.

Here is a more advanced example which shows how to provide interceptors and properties:

<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-2.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

  <jaxws:endpoint 
    id="helloWorld" 
    implementor="demo.spring.HelloWorldImpl" 
    address="http://localhost/HelloWorld">
    <jaxws:inInterceptors>
      <bean class="com.acme.SomeInterceptor"/>
      <ref bean="anotherInterceptor"/>
    </jaxws:inInterceptor>
    <jaxws:properties>
      <entry key="mtom-enabled" value="true"/>
    </jaxws:properties>
  </jaxws:endpoint>

  <bean id="anotherInterceptor" class="com.acme.SomeInterceptor"/>

</beans>

If you are a Spring user, you'll notice that the <jaxws:properties> element follows the Spring Map syntax.

Configuring a Client Proxy

Building a Client using this configuration is only applicable for those wishing to inject a Client into their Spring ApplicationContext.

To build a Client using Spring, you'll need to declare a proxy factory bean and also a client bean which is created by that proxy factory. Here is an example:

<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-2.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
    
  <bean id="proxyFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
    <property name="serviceClass" value="demo.spring.HelloWorld"/>
    <property name="address" value="http://localhost:9002/HelloWorld"/>
  </bean>
	  
  <bean id="client" class="demo.spring.HelloWorld" 
    factory-bean="proxyFactory" factory-method="create"/>

</beans>

The JaxWsProxyFactoryBean in this case takes two properties. The service class, which is the interface of the Client proxy you wish to create. The address is the address of the service you wish to call.

The second bean definition is for the client. In this case it implements the HelloWorld interface and is created by the proxyFactory <bean> by calling the create() method. You can then reference this "client" bean and inject it anywhere into your application.

The ProxyFactoryBean supports many other properties:

Name

Value

clientFactoryBean

The ClientFactoryBean used in construction of this proxy.

password

The password which the transport should use.

username

The username which the transport should use.

wsdlURL

The wsdl the client should use to configure itself.

Configuring an Endpoint/Client Proxy Using CXF APIs

JAX-WS endpoints and client proxies are implemented on top of CXF's frontend-neutral endpoint API. You can therefore use CXF APIs to enhance the functionality of a JAX-WS endpoint or client proxy, for example by adding interceptors.

To cast a client proxy to a CXF client:

GreeterService gs = new GreeterService();
Greeter greeter = gs.getGreeterPort();

org.apache.cxf.endpoint.Client client = 
org.apache.cxf.frontend.ClientProxy.getClient(greeter); 
org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
cxfEndpoint.getOutInterceptors().add(...);

To cast a JAX-WS endpoint to a CXF server:

javax.xml.ws.Endpoint jaxwsEndpoint = javax.xml.ws.Endpoint.publish("http://localhost:9020/SoapContext/GreeterPort", new GreeterImpl(););
org.apache.cxf.jaxws.EndpointImpl jaxwsEndpointImpl = (org.apache.cxf.jaxws.EndpointImpl)endpoint;
org.apache.cxf.endpoint.Server server = jaxwsEndpointImpl.getServer();
org.apache.cxf.endpoint.Endpoint cxfEndpoint = server.getEndpoint();
cxfEndpoint.getOutInterceptors().add(...);
org.apache.cxf.service.Service cxfService = cxfEndpoint.getService();
cxfService.getOutInterceptors().add(...); 
  • No labels