Search
Calendar
April 2024
S M T W T F S
« Sep    
 123456
78910111213
14151617181920
21222324252627
282930  
Your widget title
Archives

PostHeaderIcon Deploy a webservice under Mule ESB using CXF

This short tutorial is aimed at showing the main steps allowing to deploy a WebService, using CXF framework, under a Mule ESB instance.

Java code

Declare an interface:

@WebService
  public interface BasicExampleServices {
       @WebResult(name = "myReturnedInteger")
        Integer getInteger(@WebParam(name="myInteger") Integer myInteger);
    }

Implement this interface:

@WebService(endpointInterface = "com.lalou.jonathan.services.BasicExampleServices", serviceName = "basicExampleServices")
public class WSBasicExampleServices implements BasicExampleServices {

     public Integer getInteger(Integer param) {
          return 12345;
     }
}

XML files

Create a Spring config file ws-basicExample.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:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

      <bean id="basicExampleService" scope="singleton"/>
</beans>

Create a Mule configuration file ws-basicExample-config.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:spring="http://www.springframework.org/schema/beans"
 xmlns:management="http://www.mulesource.org/schema/mule/management/2.2"
 xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.2"
 xmlns:cxf="http://www.mulesource.org/schema/mule/cxf/2.2"
 xmlns:jetty="http://www.mulesource.org/schema/mule/jetty/2.2"
 xsi:schemaLocation="http://www.mulesource.org/schema/mule/management/2.2
 http://www.mulesource.org/schema/mule/management/2.2/mule-management.xsd
 http://www.mulesource.org/schema/mule/core/2.2
 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
 http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
 http://www.mulesource.org/schema/mule/vm/2.2
 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd
 http://www.mulesource.org/schema/mule/cxf/2.2
 http://www.mulesource.org/schema/mule/cxf/2.2/mule-cxf.xsd
http://www.mulesource.org/schema/mule/stdio/2.2
 http://www.mulesource.org/schema/mule/stdio/2.2/mule-stdio.xsd">

 <spring:beans>
      <spring:import resource="ws-basicExample.xml"/>
 </spring:beans>

 <model name="wsBasicExampleModel">
      <service name="wsBasicExampleService">
          <inbound>
              <cxf:inbound-endpoint address="http://localhost:8282/services/basicExampleServices"/>
           </inbound>
           <component>
              <spring-object bean="basicExampleService"/>
           </component>
       </service>
   </model>
</mule>

Checks

  • Run the Mule, pointing your config file.
  • In your favorite webbrowser, open the URL:
    http://localhost:8282/services/basicExampleServices?wsdl
  • The webservice contract is expected to be displayed.

  • You can also execute a runtime test:
    public class WSBasicExampleServicesRuntimeTest {
    
     private BasicExampleServices basicExampleServices;
    
     @Before
       public void setup() {
         JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
         factory.getInInterceptors().add(new LoggingInInterceptor());
         factory.getOutInterceptors().add(new LoggingOutInterceptor());
         factory.setServiceClass(BasicExampleServices.class);
         factory.setAddress("http://localhost:8282/services/basicExampleServices");
         basicExampleServices = (BasicExampleServices) factory.create();
       }
      
       @Test
       public void testGetInteger() {
         final Integer expectedAnswer = 12345;
         final Integer actualAnswer;
         final Integer param = 912354;
        
         actualAnswer = basicExampleServices.getInteger(param);
        
         assertNotNull(actualAnswer);
         assertEquals(expectedAnswer, actualAnswer);
       }
    
    }

Leave a Reply