<properties> <axis2.version>1.6.2</axis2.version> </properties> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2</artifactId> <version>${axis2.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.axis2/axis2-adb --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-adb</artifactId> <version>${axis2.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.axis2/axis2-jaxws --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-jaxws</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-kernel</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-metadata</artifactId> <version>${axis2.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.axis2/axis2-saaj --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-saaj</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-spring</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-transport-http</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-transport-local</artifactId> <version>${axis2.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/commons-httpclient/commons-httpclient --> <dependency> <groupId>commons-httpclient</groupId> <artifactId>commons-httpclient</artifactId> <version>3.1</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.neethi/neethi --> <dependency> <groupId>org.apache.neethi</groupId> <artifactId>neethi</artifactId> <version>3.0.2</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.woden/woden-api --> <dependency> <groupId>org.apache.woden</groupId> <artifactId>woden-api</artifactId> <version>1.0M9</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.woden/woden-impl-commons --> <dependency> <groupId>org.apache.woden</groupId> <artifactId>woden-impl-commons</artifactId> <version>1.0M9</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.woden/woden-impl-commons --> <dependency> <groupId>org.apache.woden</groupId> <artifactId>woden-impl-dom</artifactId> <version>1.0M9</version> </dependency> <!-- https://mvnrepository.com/artifact/wsdl4j/wsdl4j --> <dependency> <groupId>wsdl4j</groupId> <artifactId>wsdl4j</artifactId> <version>1.6.2</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.ws.commons.schema/XmlSchema --> <dependency> <groupId>org.apache.ws.commons.schema</groupId> <artifactId>XmlSchema</artifactId> <version>1.4.7</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.ws.commons.axiom/axiom-api --> <dependency> <groupId>org.apache.ws.commons.axiom</groupId> <artifactId>axiom-api</artifactId> <version>1.2.13</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.ws.commons.axiom/axiom-dom --> <dependency> <groupId>org.apache.ws.commons.axiom</groupId> <artifactId>axiom-dom</artifactId> <version>1.2.13</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.ws.commons.axiom/axiom-impl --> <dependency> <groupId>org.apache.ws.commons.axiom</groupId> <artifactId>axiom-impl</artifactId> <version>1.2.13</version> </dependency>
<?xml version="1.0" encoding="UTF-8"?><service name="ITestWebService"> <description>TestWebService</description> <parameter name="ServiceClass">com.java.webservice.consumer.ITestWebService</parameter> <parameter name="ServiceObjectSupplier">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier</parameter> <!-- org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier --> <parameter name="SpringBeanName">testWebService</parameter> <!--SpringBeanName名字是固定的不能改 testWebService 是spring中注册的实现类的id(这个大家肯定很清楚了) --> <!-- <operation name="doTestWebService"> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> </operation> --> <messageReceivers> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" /> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/> </messageReceivers></service>
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <!-- <bean id="testWebService" class="com.java.webservice.consumer.impl.TestWebServiceImpl"></bean> --> <bean id="testWebServiceTarget" class="com.java.webservice.consumer.impl.TestWebServiceImpl"></bean> <bean id="testWebService" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="proxyInterfaces"> <value>com.java.webservice.consumer.ITestWebService</value> </property> <property name="proxyTargetClass"> <value>false</value> </property> <property name="target"> <ref bean="testWebServiceTarget"/> </property> </bean> <!-- --></beans>
package com.java.webservice.consumer;import java.io.Serializable;/** * Created by zhuangjiesen on 2017/1/15. */public interface ITestWebService extends Serializable { public String doTestWebService(String testParam);}package com.java.webservice.consumer.impl;import com.alibaba.dubbo.config.annotation.Service;import com.java.webservice.consumer.ITestWebService;/** * Created by zhuangjiesen on 2017/1/15. */public class TestWebServiceImpl implements ITestWebService { public String doTestWebService(String testParam) { System.out.println(" TestWebServiceImpl : doTestWebService ! testParam : "+testParam); return "我是庄杰森的 TestWebServiceImpl doTestWebService 方法 "; }}
http://localhost:8080/dragsunTomDubboTest/services/ITestWebService?wsdl
/** Description: 跳转 webservice 测试 <p> @author : zhuangjiesen@ssit-xm.com.cn 庄杰森 2016年4月19日 */ @RequestMapping("/common/indexToWebServiceTest.do") public String indexToWebServiceTest(HttpServletRequest request,HttpServletResponse response,ModelMap model){ WebServiceProducer webServiceProducer=(WebServiceProducer)BeanHelper.getApplicationContext().getBean("webServiceProducer"); try { webServiceProducer.invokeTestWebService_doTestWebService(); } catch (Exception e) { e.printStackTrace(); } model.addAttribute("title","webservice + axis2 测试!!@!!!"); return "/common/index.html"; }
package com.java.webservice.producer;import org.apache.axis2.addressing.EndpointReference;import org.apache.axis2.client.Options;import org.apache.axis2.rpc.client.RPCServiceClient;import javax.xml.namespace.QName;/** * Created by zhuangjiesen on 2017/1/15. */public class WebServiceProducer { public void invokeTestWebService_doTestWebService() throws Exception { //call web service by RPC method RPCServiceClient serviceClient = new RPCServiceClient(); Options options = serviceClient.getOptions(); //specify URL for invoking //wsdl接口 EndpointReference targetEPR = new EndpointReference("http://localhost:8080/dragsunTomDubboTest/services/ITestWebService?wsdl"); options.setTo(targetEPR); //参数数组 Object[] opAddEntryArgs = new Object[]{"超人--庄杰森!! "}; //返回值 Class[] classes = new Class[]{String.class}; //wsdl接口中 targetNamespace 与方法名 QName opAddEntry = new QName("http://consumer.webservice.java.com","doTestWebService"); //opAddEntry.equals(objectToTest); Object[] objs=serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes); System.out.println(" WebServiceProducer !!! doTestWebService : "+objs[0]); }}
联系客服