接口中本来是这么写的:
但是真正的业务中,数据量特别大,得有几十万条记录。这样的话, 把dom4j的document转成xml 就会有问题了。 String根本放不下那么长的数据。
Document document = DocumentHelper.createDocument();
Element rootElmt = document.addElement("公共档案","http://xxx/AccountingSoftwareDataInterfaceStandard/2010/PSGA/XMLSchema");
rootElmt.addNamespace("行政事业单位", "http://xxx/AccountingSoftwareDataInterfaceStandard/2010/PSGA/XMLSchema");
rootElmt.addNamespace("xsi", "http://xxx/2001/XMLSchema-instance");
rootElmt.addAttribute("xsi:schemaLocation", "http://xxx/AccountingSoftwareDataInterfaceStandard/2010/PSGA/XMLSchema 公共档案.xsd");
Element accttypeElement = rootElmt.addElement("电子账簿");
accttypeElement.addElement("电子账簿编号").setText(accsystypecode);
accttypeElement.addElement("电子账簿名称").setText(accsystypespec);
accttypeElement.addElement("会计核算单位").setText(hsagencyMap.get("name")+"");
accttypeElement.addElement("组织机构代码").setText(hsagencyMap.get("orgcode")+"");
xml = document.asXML();
。。。。
//封装自定义值报文结构
for (int i = 0; i < CustomValues.size(); i++) {
。。。。
valueElement.addElement("档案值名称").setText(valueMap.get("name")+"");
valueElement.addElement("档案值描述").setText(valueMap.get("name")+"");
。。。。。
valueElement.addElement("档案值级次").setText(valueMap.get("levelno")+"");
}
return xml;
解决:
把xml转成字字节流,然后再把字节流转成base64的格式。
然后再放到Stringbuffer里面。返回去。
ByteArrayInputStream byteinput = new ByteArrayInputStream(document.asXML().getBytes());
StringBuffer buffer = new StringBuffer();
byte[] buff = new byte[1024 * 1024];
int len = 0;
while (-1 != (len = byteinput.read(buff, 0, 1024)))
{
buffer.append(Base64.encode(buff, 0, len));
}
try {
byteinput.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
xml = buffer.toString();
}
return xml;
客户端:解析byte,并生成文件
package gov.mof.fasp.ifmis.acal.common.service;
import java.io.File;
import java.io.FileOutputStream;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.encoding.XMLType;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.codehaus.xfire.util.Base64;
public class ExpXmlTest {
public static String axisToAsset() throws Exception {
String serviceUrl = "http://localhost:7001//services/ExpXmlService";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTimeout(new Integer("10000")); //设置超时
call.setTargetEndpointAddress(new URL(serviceUrl));
String targetNamespace = "http://service.common.acal.ifmis.fasp.mof.gov";
QName qName = new QName(targetNamespace, "expXml");
call.setOperationName(qName);
String message = null;
try {
String flag = "1";
String acctsystypecode = "XZ_M";
String hsagency = "2";
String startterm = "10";
String endterm = "10";
String acctyear="2017";
call.addParameter(new QName(targetNamespace, "flag"),XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter(new QName(targetNamespace, "acctsystypecode"),XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter(new QName(targetNamespace, "hsagency"),XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter(new QName(targetNamespace, "startterm"),XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter(new QName(targetNamespace, "endterm"),XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter(new QName(targetNamespace, "acctyear"),XMLType.XSD_STRING,ParameterMode.IN);
// call.setReturnType(XMLType.XSD_STRING);
Object[] obj = {flag,acctsystypecode, hsagency, startterm,endterm,acctyear};
try {
String ret = (String) call.invoke(obj);
System.out.println("Get result :" + ret);
String fileName = "java6webservice.xml";
File file = new File(fileName);
byte[] bytes = Base64.decode(ret);
System.out.println(bytes.length);
file.createNewFile();
FileOutputStream out = new FileOutputStream(file);
out.write(bytes);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
return message;
}
public static void main(String[] args) throws Exception {
axisToAsset();
}
}