Mule学习笔记(三)

发布webservice--axis

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文件

 

测试类

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(); } } }  

 

你可能感兴趣的:(mule)