NC接口外部交换平台xml文件导入代码

//传入拼接好的xml字符串
public String addOrUpdateBill(String xml){
	Logger.error("输入参数xml:" + xml);
	String result = null;
	String url = getUrl("datasource");//获取需要的参数
	Logger.error("url:" + url);
	if (url == null) {
		Logger.error("获取url地址错误");
		url = "http://127.0.0.1:99/service/XChangeServlet?account=develop&groupcode=01";//根据实际需求修改
	}
	URL realURL;
	try {
		realURL = new URL(url);
		HttpURLConnection connection = (HttpURLConnection) realURL.openConnection();
		connection.setDoOutput(true);
		connection.setRequestProperty("content-type", "dept/xml");
		connection.setRequestMethod("POST");
		StringReader sr = new StringReader(xml);
		InputSource is = new InputSource(sr);
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		DocumentBuilder builder = factory.newDocumentBuilder();
		Document doc = builder.parse(is);
		// 设定格式
		XMLOutputter out = new XMLOutputter();
		Logger.error("processing completed,ready to send data to url:"+ url);
		out.output(new DOMBuilder().build(doc),connection.getOutputStream());
		Logger.error("send success");
		// 从连接的输入流中取得回执信息
		InputStream inputStream = connection.getInputStream();
		result = IOUtils.toString(inputStream, "UTF-8");
		Logger.error("result:" + result);
}

result就是xml发送之后的回执信息,可以通过判断其标签的值来判断xml是否发送成功,如果为1则表示成功

	String res = (result.split("<resultcode>")[1].split("<"))[0];
	if(res.equals("1")){
		//...成功之后的逻辑
	}else{
		//...失败之后的逻辑
	}
//传入的参数code为需要的配置文件的对应的值
private String getUrl(String code) {
		FileInputStream input = null;
		String result = null;
		Properties properties = new Properties();
		//获取配置文件URL.properties的路径,HXBillImpl是和配置文件同级目录的实现类
		String parth = HXBillImpl.class.getResource("").getPath();
		Logger.error("HXBillImpl.parth:" + parth);
		File fileB = new File(parth);
		try {
			String newparth = fileB + File.separator + "URL.properties";
			Logger.error("newparth:" + newparth);
			input = new FileInputStream(newparth);
			properties.load(input);
			result = properties.getProperty(code);
		} catch (Exception e) {
			e.printStackTrace();
			Logger.error("error message:" + e.getMessage());
		} finally {
			if (input != null) {
				try {
					input.close();
				} catch (Exception e) {
					e.printStackTrace();
					Logger.error("finally error message:" + e.getMessage());
					Logger.error("result:" + result);
				}
			}
		}
		return result;
	}

在这里插入图片描述
配置文件内容:
在这里插入图片描述
url为NC客户端的手动加载界面的目标url地址
在这里插入图片描述

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值