XMLOutputter outputter = new XMLOutputter();
Format format = Format.getPrettyFormat(); // 格式化文档
format.setEncoding("GBK"); // 由于默认的编码是utf-8,中文将显示为乱码,所以设为gbk
format.setTextMode(TextMode.PRESERVE);
outputter.setFormat(format);
byte[] data = new byte[1024];
StringBuilder xmlInput = new StringBuilder();
ServletInputStream is = request.getInputStream();
for (int reuslt = 0; reuslt != -1; reuslt = is.read(data)) {
xmlInput.append(new String(data, 0, reuslt));
}
String xmlString = new String(Base64.decode(xmlInput.toString()), "UTF-8"); System.out.println("xml---"+xmlString);
SAXBuilder builder = new SAXBuilder();
Document xmlRequest = builder.build(new StringReader(xmlString));
MORequest moRequest = new MORequest(request);
Element requestElement = document.getRootElement(); // 获取根结�??
// 解析header结点中的参数
Element headerElement = requestElement.getChild("header");
moRequest.setCommand(headerElement.getChildTextTrim("command"));
moRequest.setSessionid(headerElement.getChildTextTrim("sessionid"));
// 解析parameter结点
Element parametersElement = requestElement.getChild("parameters");
List<Element> parameterList = parametersElement.getChildren("parameter");
for (Element parameter : parameterList) {
moRequest.setBaseParameter(parameter.getAttributeValue("name"), parameter.getTextTrim());
}
Format format = Format.getPrettyFormat(); // 格式化文档
format.setEncoding("GBK"); // 由于默认的编码是utf-8,中文将显示为乱码,所以设为gbk
format.setTextMode(TextMode.PRESERVE);
outputter.setFormat(format);
byte[] data = new byte[1024];
StringBuilder xmlInput = new StringBuilder();
ServletInputStream is = request.getInputStream();
for (int reuslt = 0; reuslt != -1; reuslt = is.read(data)) {
xmlInput.append(new String(data, 0, reuslt));
}
String xmlString = new String(Base64.decode(xmlInput.toString()), "UTF-8"); System.out.println("xml---"+xmlString);
SAXBuilder builder = new SAXBuilder();
Document xmlRequest = builder.build(new StringReader(xmlString));
MORequest moRequest = new MORequest(request);
Element requestElement = document.getRootElement(); // 获取根结�??
// 解析header结点中的参数
Element headerElement = requestElement.getChild("header");
moRequest.setCommand(headerElement.getChildTextTrim("command"));
moRequest.setSessionid(headerElement.getChildTextTrim("sessionid"));
// 解析parameter结点
Element parametersElement = requestElement.getChild("parameters");
List<Element> parameterList = parametersElement.getChildren("parameter");
for (Element parameter : parameterList) {
moRequest.setBaseParameter(parameter.getAttributeValue("name"), parameter.getTextTrim());
}