<?xml version="1.0" encoding="UTF-8"?> <mule xmlns="http://www.mulesource.org/schema/mule/core/2.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.1" xmlns:cxf="http://www.mulesource.org/schema/mule/cxf/2.1" xmlns:axis="http://www.mulesource.org/schema/mule/axis/2.1" xmlns:smtps="http://www.mulesource.org/schema/mule/smtps/2.1" xmlns:http="http://www.mulesource.org/schema/mule/http/2.1" xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.1" xmlns:soap="http://www.mulesource.org/schema/mule/soap/2.1" 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.1 http://www.mulesource.org/schema/mule/core/2.1/mule.xsd http://www.mulesource.org/schema/mule/stdio/2.1 http://www.mulesource.org/schema/mule/stdio/2.1/mule-stdio.xsd http://www.mulesource.org/schema/mule/vm/2.1 http://www.mulesource.org/schema/mule/vm/2.1/mule-vm.xsd http://www.mulesource.org/schema/mule/cxf/2.1 http://www.mulesource.org/schema/mule/cxf/2.1/mule-cxf.xsd http://www.mulesource.org/schema/mule/axis/2.1 http://www.mulesource.org/schema/mule/axis/2.1/mule-axis.xsd http://www.mulesource.org/schema/mule/smtps/2.1 http://www.mulesource.org/schema/mule/smtps/2.1/mule-smtps.xsd http://www.mulesource.org/schema/mule/soap/2.1 http://www.mulesource.org/schema/mule/soap/2.1/mule-soap.xsd http://www.mulesource.org/schema/mule/http/2.1 http://www.mulesource.org/schema/mule/http/2.1/mule-http.xsd "> <description> eagleMule demo which shows how to publish web services over CXF. </description> <model name="eagleMule"> <service name="testMuleService"> <inbound> <axis:inbound-endpoint address="http://localhost:8899/services/testMuleService"> <soap:http-to-soap-request-transformer /> </axis:inbound-endpoint> <cxf:inbound-endpoint address="http://localhost:8898/services/testMuleService"> <soap:http-to-soap-request-transformer /> </cxf:inbound-endpoint> </inbound> <component class="com.eagle.mule.test.imp.MuleServiceImp"> </component> </service> </model> </mule>
@WebService public interface MuleService { public String testMule(@WebParam(name="str")String str); }
@WebService(serviceName="eagleMuleService", endpointInterface="com.eagle.mule.test.MuleService") public class MuleServiceImp implements MuleService { public String testMule(String str) { System.out.println("----service---"); return "hello--"+str; } }
public class EagleMuleMain { public static void main(String[] args) throws ConfigurationException, InitialisationException { try { String configFile = "com/eagle/mule/test/mule_config.xml"; String[] configFileArr = new String[] { configFile }; MuleContextFactory muleContextFactory = new DefaultMuleContextFactory(); MuleContext context = muleContextFactory .createMuleContext(new SpringXmlConfigurationBuilder( configFileArr)); context.start(); } catch (MuleException t) { t.printStackTrace(); } } }
mule src-demo cn.hidetoishandsome.mule.demo EchoService.java IEchoService.java images mule-banner.gif WEB-INF lib mule-echo-config.xml web.xml contents.html echo.jsp header.html index.html welcome.html
package cn.hidetoishandsome.mule.demo;
public interface IEchoService {
String echo(String s);
String haha(String s);
}
package cn.hidetoishandsome.mule.demo;
public class EchoService implements IEchoService {
public String echo(String s) {
return "Hello, " + s + "!";
}
public String haha(String s) {
return "haha";
}
public String hehe(String s) {
return "hehe";
}
}
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>Mule</display-name> <description>Mule Demo</description> <context-param> <param-name>org.mule.config</param-name> <param-value>/WEB-INF/mule-echo-config.xml,</param-value> </context-param> <listener> <listener-class>org.mule.config.builders.MuleXmlBuilderContextListener</listener-class> </listener> <servlet> <servlet-name>muleServlet</servlet-name> <servlet-class>org.mule.providers.http.servlet.MuleReceiverServlet</servlet-class> <load-on-startup/> </servlet> <servlet-mapping> <servlet-name>muleServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mule-configuration PUBLIC "-//MuleSource //DTD mule-configuration XML V1.0//EN" "http://mule.mulesource.org/dtds/mule-configuration.dtd"> <mule-configuration id="Mule_Demo" version="1.0"> <mule-descriptor name="echoService" implementation="cn.hidetoishandsome.mule.demo.EchoService"> <inbound-router> <endpoint address="xfire:http://localhost:8181/services"/> </inbound-router> <properties> <list name="serviceInterfaces"> <entry value="cn.hidetoishandsome.mule.demo.IEchoService"/> </list> </properties> </mule-descriptor> </mule-configuration>
<%@ page import="org.mule.extras.client.MuleClient, org.mule.umo.UMOMessage"%> <%@ page language="java" contentType="text/html; charset=UTF-8" %> <html> <head> <title>Mule Echo Example</title> </head> <body> <% String s = request.getParameter("name"); if(s!=null) { MuleClient client = new MuleClient(); UMOMessage message = client.send("xfire:http://localhost:8181/services/echoService?method=echo", s, null); %> <h3><%=message.getPayload()%></h3> <%}%> Please enter your name: <form method="POST" name="submitEcho" action=""> <table> <tr><td> <input type="text" name="name"/></td><td><input type="submit" name="Go" value=" Go " /> </td></tr> </table> </form> <p/> </body> </html>
UMOMessage message = client.send("xfire:http://localhost:8181/services/echoService?method=haha", s, null);
The WebServiceWrapperComponent class allows you to send the result of a web service call to another endpoint. The web service call is performed within WebServiceWrapperComponent, providing the following advantages:
To use the web service wrapper, you specify the <wrapper-component> configuration element. The following table describes the attributes you can set for this element. These attributes are described in more detail in the examples that follow.
Attribute | Description | Required? |
---|---|---|
address | Specifies the URL of the web service to call | Yes, unless addressFromMessage is set to true |
addressFromMessage (default is false) | Specifies that the URL of the web service will be obtained from the message itself | Not required if address is set |
wrapperProperties | The SOAP document style, expressed as a map of two properties: style, which can be set to RPC (the default), Document, Message, or Wrapped, and use, which can be Encoded or Literal. | No |
<soap-method> | A SOAP method to call (see Configuring SOAP Methods below) | No |
The web service wrapper is generic and can be used with any type of web service stack supported by Mule, including Axis and CXF. The examples below show synchronous use cases, but the web service wrapper can also support an asynchronous use case like the loan broker example.
Consider the following example. The web service wrapper is configured as a Mule component, accepting messages from a VM endpoint. A call must be made to a web service on the URL cxf:http://localhost:65081/services/TestUMO?method=onReceive and the result must be sent to the outbound endpoint vm://testout.
The inbound and outbound endpoints are configured in the usual way. The address is set as an attribute on the component, specifying the web service URL that you want to call.
<cxf:connector name="cxf" defaultFrontend="simple" /> <model name="Sample"> <service name="WebServiceSample"> <inbound> <vm:inbound-endpoint path="testin" /> </inbound> <cxf:wrapper-component address="http://localhost:65081/services/TestUMO?method=onReceive"/> <outbound> <pass-through-router> <outbound-endpoint address="vm://testout"/> </pass-through-router> </outbound> </service>
The "address" property is ideal to use when the web service URL for the web service is known at configuration time. However, if this URL is either not known or else needs to be changed at run-time, the "address" property can be omitted and the "adddressFromMessage" property can be set to true. The following example shows this configuration:
<service name = "WebServiceSample2"> <inbound> <vm:inbound-endpoint path = "testin2"/> </inbound> <cxf:wrapper-component addressFromMessage = "true"/> </service>
The URL must be set on the message with the property name "ws.service.url".
CXF endpoints are fairly easy to configure, whereas Axis needs some further configuration to set SOAP methods. You can set a SOAP method using the <soap-method> element as shown below:
<service name = "WebServiceSample3"> <inbound> <vm:inbound-endpoint path = "queue.in" connector-ref = "VMQueue"/> </inbound> <axis:wrapper-component address = "http://localhost:62088/axis/Calculator?method=add" style = "WRAPPED" use = "LITERAL"> <axis:soap-method method = "qname{add:http://muleumo.org/Calc}"> <axis:soap-parameter parameter = "Number1" type = "int" mode = "IN"/> <axis:soap-parameter parameter = "Number2" type = "int" mode = "IN"/> <axis:soap-return type = "int"/> </axis:soap-method> </axis:wrapper-component> <outbound> <pass-through-router> <vm:outbound-endpoint path = "queue.out" connector-ref = "VMQueue"/> </pass-through-router> </outbound> </service>