- package mule.webservice.service;
- import javax.jws.WebParam;
- import javax.jws.WebResult;
- import javax.jws.WebService;
- @WebService
- public interface Hello {
- @WebResult(name="text")
- public String sayHello(@WebParam(name="text")String name);
- }
- package mule.webservice.service.impl;
- import mule.webservice.service.Hello;
- public class HelloImpl implements Hello {
- @Override
- public String sayHello(String name) {
- System.out.println("Hello," + name);
- return "Hello," + name;
- }
- }
配置config文件
- <?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:soap="http://www.mulesource.org/schema/mule/soap/2.2"
- xmlns:axis="http://www.mulesource.org/schema/mule/axis/2.2"
- xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2"
- xsi:schemaLocation="
- 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/soap/2.2 http://www.mulesource.org/schema/mule/soap/2.2/mule-soap.xsd
- http://www.mulesource.org/schema/mule/axis/2.2 http://www.mulesource.org/schema/mule/axis/2.2/mule-axis.xsd
- http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd
- ">
- <model name="echoSample">
- <service name="testService">
- <inbound>
- <axis:inbound-endpoint address="http://localhost:65088/services"/>
- </inbound>
- <component class="mule.webservice.service.impl.HelloImpl"></component>
- </service>
- </model>
- </mule>
测试类
- package mule.webservice.client;
- import org.mule.api.MuleContext;
- import org.mule.api.MuleException;
- import org.mule.api.MuleMessage;
- import org.mule.api.config.ConfigurationException;
- import org.mule.api.lifecycle.InitialisationException;
- import org.mule.context.DefaultMuleContextFactory;
- import org.mule.module.client.MuleClient;
- public class Client1 {
- 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-1.xml");
- MuleClient client = null;
- try {
- client = new MuleClient();
- String url = "axis:http://localhost:65088/services/testService?method=sayHello";
- MuleMessage message = client.send(url, "zhuyoufeng", null);
- Object obj = message.getPayload();
- System.out.println(obj.getClass().getName());
- if (obj instanceof String) {
- System.out.println(obj);
- }
- } catch (MuleException e) {
- e.printStackTrace();
- } finally {
- client.dispose();
- }
- }
- }