客户端使用AXIS的CALL调用
来源:互联网 发布:java tar.gz 安装 编辑:程序博客网 时间:2024/05/16 12:46
一、客户端使用AXIS的CALL调用
- package com.common;
- import java.net.URL;
- import java.util.ArrayList;
- import java.util.List;
- import javax.xml.namespace.QName;
- import javax.xml.rpc.ParameterMode;
- import org.apache.axiom.om.OMAbstractFactory;
- import org.apache.axiom.om.OMElement;
- import org.apache.axiom.om.OMFactory;
- import org.apache.axiom.om.OMNamespace;
- import org.apache.axis.client.Call;
- import org.apache.axis.client.Service;
- import org.apache.axis.encoding.XMLType;
- import org.apache.axis.message.MessageElement;
- import org.apache.axis.types.Schema;
- import org.apache.axis2.databinding.utils.BeanUtil;
- import com.shun.ebs.model.Senddividendstrategy;
- public class Test3 {
- public final static String bipEndpoint = "http://192.168.10.227/ebsService/services/ebsService?wsdl";
- public final static String bipNamespace = "http://service.ebs.shun.com";
- public static void main(String[] args) {
- // queryAvailableAmt();
- // cancelDividendStratery();
- senddividendstrategy();
- }
- public static void senddividendstrategy() {
- try {
- Service service = new Service();
- Call call = (Call) service.createCall();
- call.setTargetEndpointAddress(new URL(bipEndpoint));
- call.setOperationName(new QName(bipNamespace, "senddividendstrategy"));
- call.addParameter("in", XMLType.XSD_STRING, ParameterMode.IN);
- call.setEncodingStyle("UTF-8");
- call.setReturnType(XMLType.XSD_SCHEMA);
- OMElement ome = getOMFactory();
- String beanXml = ome.toStringWithConsume();
- System.out.println("客户端发送:"+beanXml);
- Object o = call.invoke(new Object[] { beanXml });
- Schema schema = (Schema) o;
- MessageElement[] messageElements = schema.get_any();
- StringBuffer str = new StringBuffer("");
- for (MessageElement m : messageElements) {
- str.append(m.toString());
- }
- System.out.println("客户端接受:"+str);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void cancelDividendStratery() {
- try {
- Service service = new Service();
- Call call = (Call) service.createCall();
- call.setTargetEndpointAddress(new URL(bipEndpoint));
- call.setOperationName(new QName(bipNamespace, "cancelDividendStratery"));
- call.addParameter("p_company_code", XMLType.XSD_STRING, ParameterMode.IN);
- call.addParameter("p_dividend_date", XMLType.XSD_STRING, ParameterMode.IN);
- call.addParameter("p_equity_note_number", XMLType.XSD_STRING, ParameterMode.IN);
- call.setEncodingStyle("UTF-8");
- call.setReturnType(XMLType.XSD_SCHEMA);
- Object o = call.invoke(new Object[] { "801000", "2013-01-04", "" });
- Schema schema = (Schema) o;
- MessageElement[] messageElements = schema.get_any();
- StringBuffer str = new StringBuffer("");
- for (MessageElement m : messageElements) {
- str.append(m.toString());
- }
- System.out.println(str);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void queryAvailableAmt() {
- try {
- Service service = new Service();
- Call call = (Call) service.createCall();
- call.setTargetEndpointAddress(new URL(bipEndpoint));
- call.setOperationName(new QName(bipNamespace, "queryAvailableAmt"));
- call.addParameter("p_dividend_date", XMLType.XSD_STRING, ParameterMode.IN);
- call.addParameter("p_company_code", XMLType.XSD_STRING, ParameterMode.IN);
- call.addParameter("p_user_name", XMLType.XSD_STRING, ParameterMode.IN);
- call.addParameter("p_password", XMLType.XSD_STRING, ParameterMode.IN);
- call.setEncodingStyle("UTF-8");
- call.setReturnType(XMLType.XSD_SCHEMA);
- Object o = call.invoke(new Object[] { "2013-01-04", "801000", "", "" });
- Schema schema = (Schema) o;
- MessageElement[] messageElements = schema.get_any();
- StringBuffer str = new StringBuffer("");
- for (MessageElement m : messageElements) {
- str.append(m.toString());
- }
- System.out.println(str);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static OMElement getOMFactory() {
- OMFactory fac = OMAbstractFactory.getOMFactory();
- // OMNamespace指定此SOAP文档名称空间
- OMNamespace om = fac.createOMNamespace("http://service.eee.shun.com", "client");
- // 创建元素,并指定其在om指代的名称空间中,元素名必须跟services.xml重大operation的name相同
- OMElement method = fac.createOMElement("senddividendstrategy", om);
- OMElement root;
- OMElement svsListOmElement;
- List<Senddividendstrategy> svsList = new ArrayList<Senddividendstrategy>();
- try {
- Senddividendstrategy s = null;
- for (int i = 0; i < 10; i++) {
- s = new Senddividendstrategy();
- s.setDividend_date("2013-01-04");
- s.setCompany_code("2");
- s.setEquity_note_number("3");
- s.setDividend_line_number(Long.valueOf(4));
- s.setAssign_type_code("5");
- s.setAssign_source("6");
- s.setSegment3("7");
- s.setAmount(Long.valueOf(8));
- s.setCash_amount(Long.valueOf(9));
- s.setCash_proportion(Long.valueOf(10));
- s.setCash_person_proportion(Long.valueOf(11));
- s.setCapital_source("12");
- s.setCapital_amount(Long.valueOf(13));
- s.setCapital_proportion(Long.valueOf(14));
- s.setCapital_person_proportion(Long.valueOf(15));
- s.setEquity_category("16");
- s.setEquity_properties("17");
- s.setReduce_tax_amount(Long.valueOf(18));
- s.setStart_date("2013-01-04");
- s.setManager_type("20");
- s.setProcess_startus("21");
- s.setData_status("22");
- svsList.add(s);
- }
- root = fac.createOMElement("root", null);
- svsListOmElement = BeanUtil.getOMElement(new QName("sparams"), svsList.toArray(), new QName("sparam"), false, null);
- root.addChild(svsListOmElement);
- method.addChild(root);
- return method;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- }
二、遇到问题
客户端传送String类型的XML内容的时候服务器段接受会遇到需要处理(目的是要传送XML格式的数据)
- public static OMElement checkDataByOMElement(OMElement element) throws AxisFault, Exception {
- String str = element.toStringWithConsume();
- str = str.replace("<", "<")
- .replace(">", ">")
- .replace("<in xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"xsd:string\">", "")
- .replace("</in>", "")
- .replace("<client:senddividendstrategy xmlns:client=\"http://service.ebs.shun.com\">", "")
- .replace("</client:senddividendstrategy>", "");
- element = new StAXOMBuilder(new ByteArrayInputStream(str.getBytes("UTF-8"))).getDocumentElement();
- System.out.println("服务端接受:"+element.toString());
- System.out.println("服务端接受str:"+str);
- .....
二、xml、OMElement、java对象之间转换
- import java.io.ByteArrayInputStream;
- import org.apache.axiom.om.OMElement;
- import org.apache.axiom.om.impl.builder.StAXOMBuilder;
- import org.apache.axis2.databinding.utils.BeanUtil;
- import org.apache.axis2.engine.DefaultObjectSupplier;
- import org.dom4j.Document;
- import org.dom4j.DocumentHelper;
- public class XMLUtil
- {
- @SuppressWarnings("unchecked")
- public static T xmlToBean(String xml, Class cls)
- {
- T object = null;
- try
- {
- OMElement omElement = new StAXOMBuilder(new ByteArrayInputStream(
- xml.getBytes("UTF-8"))).getDocumentElement();
- object = (T) BeanUtil.processObject(omElement, cls, null, true,
- new DefaultObjectSupplier());
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- return object;
- }
- @SuppressWarnings("unchecked")
- public static T xmlToBean(String xml, String elementName, Class cls)
- {
- T object = null;
- try
- {
- Document document = DocumentHelper.parseText(xml);
- String beanXml = document.getRootElement().element("Body").element(
- elementName).asXML();
- OMElement omElement = new StAXOMBuilder(new ByteArrayInputStream(
- beanXml.getBytes("UTF-8"))).getDocumentElement();
- object = (T) BeanUtil.processObject(omElement, cls, null, true,
- new DefaultObjectSupplier());
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- return object;
- }
- }
- 客户端使用AXIS的CALL调用
- 客户端使用AXIS的CALL调用
- 使用AXIS的CALL调用服务接口
- axis 的客户端使用
- 使用axis编写客户端代码调用webservice的一些问题
- 使用Axis生成调用webservice的客户端stub类
- 客户端使用axis调用webService服务端
- axis 的客户端使用[转]
- axis 调用webservice (客户端)
- Axis 客户端调用
- Axis客户端调用Webservice_hanCSDN_20130225
- 在Websphere上,使用axis做成的客户端调用Webservice需要进行的配置
- 使用Axis2开发webservice服务端接口+axis开发的客户端调用
- 客户端调用Webservice例子(Axis)
- Axis客户端生成及调用
- 用axis自动生成webService调用的客户端
- WebService的axis客户端调用时出错解决方法
- WebService:Axis客户端调用需要身份验证的CXF服务
- Poj 3321 Apple Tree(树变序列+时间戳+树状数组)
- 用GDB调试程序(四)
- postfix实现邮件发送的简单配置
- Vim配置与gcc常用命令
- 用GDB调试程序(五)
- 客户端使用AXIS的CALL调用
- 程序员的四种类型
- c3p0配置
- Linux学习文档
- 用GDB调试程序(六)
- E: Unable to lock the administration directory (/var/lib/dpkg/), is another
- C++虚函数动态绑定
- C++ map的基本操作和使用
- 用GDB调试程序(七)