民航接口
来源:互联网 发布:mac mysql 密码修改 编辑:程序博客网 时间:2024/05/01 13:26
民航接口调用过程
1、读取配置文件UtilTools 类读取xml为String
public static String readFile(String file) { file=UtilTools.class.getClassLoader().getResource(file).getFile(); String xml=""; BufferedReader br = null; try { File inFile = new File(file); InputStream in = new FileInputStream(inFile); br = new BufferedReader(new InputStreamReader(in)); String buffer = new String(); String line = ""; while ((line = br.readLine()) != null) { buffer+=line; } xml = buffer.toString(); } catch (Exception e) { System.out.println("读取失败"); } finally { if (br != null) { try { br.close(); } catch (IOException e1) { // TODO 自动生成 catch 块 e1.printStackTrace(); } } } return xml; } public static byte[] readInputStream(InputStream inStream) throws Exception { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = inStream.read(buffer)) != -1) { outStream.write(buffer, 0, len); } byte[] data = outStream.toByteArray(); // 网页的二进制数据 outStream.close(); inStream.close(); return data; }
2. CAEBase类
public class CAEBase { private static String xml = UtilTools.readFile(Constants.DEFINEFILE_CAE); public static void main(String[] args) { try { List l = CAEBase.queryCAEInfo("CAE376446119"); System.out.println(((List) l.get(0)).get(0)); for (int i = 0; i < l.size(); i++) { ((List) (l.get(i))).get(0); } } catch (Exception e) { // TODO 自动生成 catch 块 e.printStackTrace(); } } public static List queryCAEInfo(String caeCode) throws Exception { if ("".matches(caeCode)) { return null; } List list = null; //System.out.println(xml.replaceAll("CAECode", caeCode)); //设置代理 Properties prop = System.getProperties(); prop.put("proxySet", "false"); prop.remove("http.proxyUser"); prop.remove("http.proxyPassword"); prop.setProperty("http.proxyHost", Constants.PROXYHOST); prop.setProperty("http.proxyPort", Constants.PORT); byte[] buf = xml.replaceAll("CAECode", caeCode).getBytes("utf-8"); String urlString = "http://211.103.158.178:8008/Service1.asmx"; String soapActionString = "http://CAEServicesForGE.com/xmlMailTrace"; URL url = new URL(urlString); HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); httpConn.setRequestProperty( "Content-Length", String.valueOf(buf.length)); httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8"); httpConn.setRequestProperty("soapActionString", soapActionString); httpConn.setRequestMethod("POST"); httpConn.setDoOutput(true); httpConn.setDoInput(true); // proxy user and pass httpConn.setRequestProperty( "Proxy-Authorization", "Basic " + new sun.misc.BASE64Encoder().encode( (Constants.USERNAME + ":" + Constants.PASSWORD) .getBytes())); OutputStream out = httpConn.getOutputStream(); out.write(buf); out.close(); httpConn.connect(); byte[] datas = UtilTools.readInputStream(httpConn.getInputStream()); prop.setProperty("http.proxyHost", ""); prop.setProperty("http.proxyPort", ""); prop.setProperty("http.proxyUser", ""); prop.setProperty("http.proxyPassword", ""); String result = new String(datas, "utf-8").replaceAll("<", "<").replaceAll( ">", ">");StringReader read = new StringReader(result); InputSource source = new InputSource(read); SAXBuilder sb = new SAXBuilder(); ByteArrayInputStream bia = new ByteArrayInputStream(result.getBytes("utf-8"));
org.jdom.Document myDocument = sb.build(bia);
Element rootElement = myDocument.getRootElement(); // 取的根元素
//System.out.println(rootElement.getName()); // 输出根元素的名称(测试)
// 获取Body节点 List jd = ( (Element) ( (Element) ((Element) ((Element) rootElement .getChildren() .get(0)) .getChildren() .get(0)) .getChildren() .get(0)) .getChildren() .get(0)) .getChildren(); // 输出根元素的名称(测试) if(jd.size()!=0){ list=new ArrayList(); } for (int i = 0; i < jd.size(); i++) { Element e = (Element) jd.get(i); ArrayList temp = new ArrayList(); temp.add(((Element) e.getChildren().get(0)).getText()); //操作时间 temp.add(((Element) e.getChildren().get(1)).getText()); //营业点 temp.add(((Element) e.getChildren().get(2)).getText()); //所在机构 temp.add(((Element) e.getChildren().get(3)).getText()); //事件 temp.add(((Element) e.getChildren().get(4)).getText()); //详细说明 list.add(temp); } return list; }
}
若数据缺失遍历方式则:
ByteArrayInputStream bia =new ByteArrayInputStream(result.getBytes("utf-8"));org.jdom.Document myDocument = sb.build(bia);Element rootElement = myDocument.getRootElement(); // 取的根元素//System.out.println(rootElement.getName()); // 输出根元素的名称(测试)// 获取Body节点List jd =((Element)((Element) ((Element) ((Element) rootElement.getChildren().get(0)).getChildren().get(0)).getChildren().get(0)).getChildren().get(0)).getChildren();// 输出根元素的名称(测试)if(jd.size()!=0){list=new ArrayList();}for (int i = 0; i < jd.size(); i++) {ArrayList temp = new ArrayList(); //保存每行需要的字符串 顺序为:操作时间,营业点,所在机构,事件,详细说明temp.add("");temp.add("");temp.add("");temp.add("");temp.add("");//只有“操作时间”和“所在机构”是必填数据项
List e = ((Element)jd.get(i)).getChildren();//取出每行数据转为Element进行获取数据 防止数据缺失异常for(int j = 0 ; j < e.size() ; j++) {Element tempNode =(Element) e.get(j);if("操作时间".equals(tempNode.getName().trim())){temp.set(0, tempNode.getTextTrim());}else if("营业点".equals(tempNode.getName().trim())){temp.set(1, tempNode.getTextTrim());}else if("所在机构".equals(tempNode.getName().trim())){temp.set(2, tempNode.getTextTrim());}else if("事件".equals(tempNode.getName().trim())){temp.set(3, tempNode.getTextTrim());}else if("详细说明".equals(tempNode.getName().trim())){temp.set(4, tempNode.getTextTrim());}}list.add(temp);}return list;}
3、cae.xml 可以直接从http://211.103.158.178:8008/Service1.asmx?op=xmlMailTrace读取
<_strKDDH>CAECode</_strKDDH>
<_strUsername>C*****</_strUsername>
<_strPassword>C****</_strPassword>
- 民航接口
- 民航是
- 民航名词解释
- 课程设计~民航管理系统
- 民航业务笔记
- 民航安保项目
- 民航学概论学习小结
- 看看行不,民航订票
- 程序员的职业规划民航客机
- 真的厌倦民航学院了吗?
- 转载---民航学院的同学如何找工作
- 民航飞机因何频繁遭遇乱流?
- eTerm指令、民航指令大全、黑屏指令
- eTerm指令、民航指令大全、黑屏指令
- 中南民航如何利用K2BPM构建业务流程?
- 中美民航协议促快递市场裂变 EMS垄断难保
- 从民航服务业务抽象出服务行业的系统需求
- 浙大玉泉校区->武林门民航售票处->萧山机场
- 设计模式C++实现(2)——策略模式
- OI经典问题与基本模型
- Echop - 数据库表结构
- 题目1209:最小邮票数
- 云监控资料收集
- 民航接口
- Java操作XML文件
- Spring Security教程(3)---- 自定义登录页面
- perl对中文的处理
- 记住登录状态的安全做法
- 第七章 软件编码
- LayoutInflater的inflate函数用法详解
- CATransition 的初级应用及type属性
- 初步体验libsvm用法