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;
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 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.";
}
package mule.webservice.service.impl;
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>
<?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 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) {
} catch (muleexception e) {
}
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"));