- package mule.webservice.service;
- import javax.jws.WebParam;
- import javax.jws.WebResult;
- import javax.jws.WebService;
- @WebService
- public interface HelloCXF {
- @WebResult(name="text")
- public String sayHello(@WebParam(name="text")String name);
- }
- package mule.webservice.service.impl;
- import javax.jws.WebService;
- import mule.webservice.service.HelloCXF;
- @WebService(endpointInterface = "mule.webservice.service.HelloCXF",
- serviceName = "HelloCXF")
- public class HelloCXFImpl implements HelloCXF {
- @Override
- public String sayHello(String name) {
- return "Hello," + name + "! by cxf.";
- }
- }
配置文件
- <?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:cxf="http://www.mulesource.org/schema/mule/cxf/2.2"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://www.mulesource.org/schema/mule/core/2.2
- http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
- http://www.mulesource.org/schema/mule/cxf/2.2
- http://www.mulesource.org/schema/mule/cxf/2.2/mule-cxf.xsd">
- <model name="helloCXF">
- <service name="helloService">
- <inbound>
- <inbound-endpoint address="cxf:http://localhost:63081/hello" />
- </inbound>
- <component class="mule.webservice.service.impl.HelloCXFImpl" />
- </service>
- </model>
- </mule>
测试类
- package mule.webservice.client;
- import mule.webservice.service.HelloCXF;
- import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
- import org.mule.api.MuleContext;
- import org.mule.api.MuleException;
- import org.mule.api.config.ConfigurationException;
- import org.mule.api.lifecycle.InitialisationException;
- import org.mule.context.DefaultMuleContextFactory;
- public class Client3 {
- public static void startMule(String config) {
- try {
- MuleContext muleContext;
- muleContext = new DefaultMuleContextFactory()
- .createMuleContext(config);
- muleContext.start();
- } catch (InitialisationException e) {
- e.printStackTrace();
- } catch (ConfigurationException e) {
- e.printStackTrace();
- } catch (MuleException e) {
- e.printStackTrace();
- }
- }
- public static void main(String[] args) {
- startMule("ws-config-cxf.xml");
- JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
- factory.setAddress("http://localhost:63081/hello");
- factory.setServiceClass(HelloCXF.class);
- HelloCXF helloworld = (HelloCXF) factory.create();
- System.out.println(helloworld.sayHello("abc"));
- }
- }