前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Webservice实现与调用(基于spring的多种方式)

Webservice实现与调用(基于spring的多种方式)

作者头像
XING辋
发布2019-03-26 11:28:16
2.1K0
发布2019-03-26 11:28:16
举报
文章被收录于专栏:M莫的博客

一、Webservice实现

实现方式分类

1. spring实现

  • bean配置

123

<bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter"> <property name="baseAddress" value="http://localhost:8088/"/> </bean>

  • service

12345678910

@Component @WebService(serviceName="sapPushExpenseWebservice") public class SapPushExpenseWebservice { private static Logger logger = LoggerFactory.getLogger(SapPushExpenseWebservice.class); @WebMethod public Result<Object> pushExpense(@WebParam(name="expenseDTOSet") Set<String> expenseDTOSet) { logger.info(JSON.toJSONString(expenseDTOSet)); return null; } }

2. spring boot实现

  • Cxf boot配置

12345678910

<dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>3.1.6</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http</artifactId> <version>3.1.6</version> </dependency>

123456789101112131415161718192021222324

@Configuration public class SapCxfConfig { @Bean public ServletRegistrationBean dispatcherServlet() { return new ServletRegistrationBean(new CXFServlet(), "/sap/soap/*"); } @Bean(name = Bus.DEFAULT_BUS_ID) public SpringBus springBus() { return new SpringBus(); } @Bean public ISapPushExpenseWebservice sapPushExpenseWebservice() { return new SapPushExpenseWebservice(); } @Bean public Endpoint endpoint() { EndpointImpl endpoint = new EndpointImpl(springBus(), sapPushExpenseWebservice()); endpoint.publish("/push"); return endpoint; } }

  • service实现

12345678910111213141516171819202122

@WebService public interface ISapPushExpenseWebservice { @WebMethod Result<Object> pushExpense(@WebParam(name="expenseDTOSet")Set<SapExpenseDTO> expenseDTOSet); } public class SapPushExpenseWebservice implements ISapPushExpenseWebservice { private static Logger logger = LoggerFactory.getLogger(SapPushExpenseWebservice.class); @Autowired private ISapExpenseService sapExpenseService; @Override public Result<Object> pushExpense(Set<SapExpenseDTO> expenseDTOSet) { logger.info(JSON.toJSONString(expenseDTOSet)); return sapExpenseService.pushExpense(expenseDTOSet); } }

3. dubbo实现

1

* http://blog.csdn.net/u012129031/article/details/53259877

二、Webservice调用

cxf客户端生产代码

  • 下载地址

1

http://cxf.apache.org/

  • 生成代码

1234567891011

远程生成 ./wsdl2java -d /Users/moxingwang/Desktop/soap -client http://localhost:8080/sap/soap/user?wsdl 本地生成 ./wsdl2java -p com.chinaredstar.bill.integration.demo.test -d /Users/moxingwang/Desktop/soap /Users/moxingwang/Desktop/ss.xml 带密码的 11.txt文件内容 http://3RDSOAP2PI:[email protected]:50000/dir/wsdl?p=sa/a3102884ecae325ca312de6d9720e2fb 生产指令 wsimport -d /Users/moxingwang/Desktop/soap1 -keep -verbose -Xauthfile /Users/moxingwang/Desktop/sap/11.txt ‘http://172.16.3.21:50000/dir/wsdl?p=sa/a3102884ecae325ca312de6d9720e2fb’

使用代理调用

  • 依赖jar

1234567891011

<!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-rt-frontend-jaxws --> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>3.1.9</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http</artifactId> <version>3.1.9</version> </dependency>

  • 调用代码

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556

1.第一种方式调用 public class Test { public static void main(String[] args) { JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); Client client = dcf.createClient("http://192.168.224.182:8088/sapPushExpenseWebservice?wsdl"); try { List<String> list = new ArrayList<>(); list.add("测试"); Object[] objects = client.invoke("pushExpense", list); System.out.println(JSON.toJSONString(objects[0])); }catch (Exception e){ e.printStackTrace(); } } } 2.第二种方式调用 JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(SIZFIFMECSRECEIVEOS.class); factory.setUsername("ZWS_ECS"); factory.setPassword("abcd1234"); factory.setAddress("http://172.16.3.21:50000/XISOAPAdapter/MessageServlet?senderParty=&senderService=BC_NREM&receiverParty=&receiverService=&interface=SI_ZREI_BAPI_RE_CN_OVER_OS&interfaceNamespace=http%3A%2F%2Fchinaredstar.com%2Fecc2oms"); SIZFIFMECSRECEIVEOS port = (SIZFIFMECSRECEIVEOS) factory.create(); ZFIFMECSRECEIVE zfifmecsreceive = new ZFIFMECSRECEIVE(); zfifmecsreceive.setICBUTYNUM("121221"); TABLEOFZMMFIFMCOMONOUTNEW tableofzmmfifmcomonoutnew = new TABLEOFZMMFIFMCOMONOUTNEW(); zfifmecsreceive.setETBELNR(tableofzmmfifmcomonoutnew); ZFIFMECSRECEIVEResponse a = port.siZFIFMECSRECEIVEOS(zfifmecsreceive); 第三种方式调用 ZFMRECPBAPIRECNCREATE zfmrecpbapirecncreate = new ZFMRECPBAPIRECNCREATE(); java.net.Authenticator myAuth = new java.net.Authenticator() { @Override protected java.net.PasswordAuthentication getPasswordAuthentication() { return new java.net.PasswordAuthentication("dengwj", "1qaz2wsx".toCharArray()); } }; java.net.Authenticator.setDefault(myAuth); URL url = null; try { url = new URL("http://172.16.3.33:50000/dir/wsdl?p=sa/a862bcbfb95838b382e23a7a49252f1c"); } catch (MalformedURLException e) { System.out.println(e.getMessage()); e.printStackTrace(); } SIZFMRECPBAPIRECNCREATEOutService service = new SIZFMRECPBAPIRECNCREATEOutService(url);

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-08-24,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、Webservice实现
    • 实现方式分类
      • 1. spring实现
      • 2. spring boot实现
      • 3. dubbo实现
  • 二、Webservice调用
    • cxf客户端生产代码
      • 使用代理调用
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档