天翎MyApps技术社区 - 低代码平台 | 流程管理系统 | BPM软件

 找回密码
 注册成为天翎用户
查看: 896|回复: 1

[已解决] 如何通过在java中调用webservice接口得到数据

[复制链接]
吴思敏 发表于 2021-7-1 10:14:15 | 显示全部楼层 |阅读模式
【myApps/OBPM版本号】:v4.4- sp XX
【浏览器类型】:Chrome/其他
【联系方式-QQ】:请留下您的QQ号码
【联系电话】:    请留下您的联系电话,以便技术同事更好解决您的问题
【问题描述】:









1、问题描述最好图文并茂,如有视频/脚本可直接放出,这样技术同事在处理该问题时效率更加高效哦~
2、如果该问题已得到解决,请在该帖子下回复\"已解决可结帖\"
 楼主| 吴思敏 发表于 2021-7-1 10:15:17 | 显示全部楼层
Q:如何通过在java中调用平台webservice接口得到数据?
A:请参考以下脚本:
  1. package webService;

  2. public class SyncTest {

  3.         public static void main(String[] args) {
  4.                 //部门同步
  5.                 String url="http://localhost:8080/obpm/services/DepartmentService";
  6.                 String pk ="11e6-4314-767bf282-a2bd-77e1f101bc4d";
  7.                 String xmlStr = "<cn.myapps.webservice.model.SimpleDepartment>/n"
  8.                                 + " <domainName>万佳信息工程公司</domainName>/n"
  9.                                 + " <id></id>/n"
  10.                                 + " <level></level>/n"
  11.                         + " <name>部门111111111</name>/n"
  12.                         + " <superiorName>Xml格式部门</superiorName>/n"
  13.                         + " </cn.myapps.webservice.model.SimpleDepartment>/n";
  14.                 XfireClient xfireClient=new XfireClient();
  15.                 xfireClient.createDepartment(url, xmlStr);
  16.                 //xfireClient.getDepartment(url, pk);
  17.                 //xfireClient.updateDepartment(url, xmlStr);
  18.                 //xfireClient.deleteDepartment(url, pk);               

  19.         }

  20. }

  21. package webService;

  22. import java.net.MalformedURLException;

  23. import org.codehaus.xfire.client.XFireProxyFactory;
  24. import org.codehaus.xfire.service.Service;
  25. import org.codehaus.xfire.service.binding.ObjectServiceFactory;

  26. import test.IAnyName;

  27. /**
  28. * 这是xfire客户端
  29. * 创建
  30. * @author Administrator
  31. *
  32. */
  33. public class XfireClient {
  34.       
  35.         public XfireClient(){
  36.         }
  37.       
  38.         public String createDepartment(String url,String xmlStr){
  39.                 try {
  40.                         Service service = new ObjectServiceFactory().create(TLInterface.class) ;  
  41.                 XFireProxyFactory factory = new XFireProxyFactory() ;
  42.                         TLInterface tlInterface = (TLInterface) factory.create(service,url) ;
  43.             String result=tlInterface.createDepartmentFromXML(xmlStr);
  44.         } catch (Exception e) {  
  45.             e.printStackTrace();  
  46.         }
  47.                 return null;  
  48.         }
  49. }


  50. package webService;

  51. public interface TLInterface {
  52.       
  53.         public int createDepartmentFromXML(String xmlStr);
  54.         public int updateDepartmentFromXML(String xmlStr);
  55.         public String findDepartmentFormat2XML(String pk);
  56.         public int deleteDepartment(String pk);
  57.         }
复制代码

本版积分规则

QQ|手机版|天翎MyApps技术社区 ( 粤ICP备11093750号 )

GMT+8, 2026-8-12 19:15

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表