华为、中兴、烽火I2接口接入

xiaoxiao2021-02-28  162

华为、中兴、烽火I2 Webservice接口接入                  无论是华为、中兴、烽火I2接口的接入,其实I2接口就是webservice接口,webservice接口用soapui调用的时候就是http的post请求,那么我们需要厂家提供的是wsdl服务地址,soap报文(入参正确可以返回数据的),还有一份对入参出参说明的接口说明书。那么我们就看一下soapui的http post请求是怎么接入华为、中兴或者烽火的I2接口的吧。 package com.fenghuo.test; import java.io.ByteArrayInputStream; import java.io.InputStream; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.InputStreamRequestEntity; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.RequestEntity; public class FHTest {          /**      * 模拟soapui 调用webservice(I2接口) http post请求代码      * @param xml  报文,可以在soapui上测试通过      * @param url  wsdl地址      * @param soapAction    操作类型,报文里面有      * @return      */     public static String SoapRequest(String xml, String url,String soapAction) {         try {             PostMethod postMethod = new PostMethod(url);             byte[] b = xml.getBytes("utf-8");             InputStream is = new ByteArrayInputStream(b, 0, b.length);             System.out.println("is:" + is);             RequestEntity re = new InputStreamRequestEntity(is, b.length, "application/soap+xml; charset=utf-8");             System.out.println("re:" + re);             postMethod.setRequestHeader("SOAPAction",soapAction);             postMethod.setRequestEntity(re);             HttpClient httpClient = new HttpClient();             httpClient.executeMethod(postMethod);                      xml = postMethod.getResponseBodyAsString();             xml = xml.replaceAll(""", "'");         } catch (Exception e) {             e.printStackTrace();             xml = "error";         }         return xml;     }          public static void main(String[] args) {         StringBuffer sb = new StringBuffer();         String report ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +                 "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\""                  + "xmlns:v1=\"http://www.tmforum.org/mtop/fmw/xsd/hdr/v1\" "                  + "xmlns:v11=\"http://www.tmforum.org/mtop/mri/xsd/mer/v1\" "                  + "xmlns:v12=\"http://www.tmforum.org/mtop/fmw/xsd/nam/v1\">"                  + "<soapenv:Header>"                    + " <v1:header> "                  + "<v1:activityName>getAllManagedElements</v1:activityName>"                  +  "<v1:msgName>getAllManagedElementsRequest</v1:msgName>"                  +  "<v1:msgType>REQUEST</v1:msgType>"                  + "<v1:senderURI>/MTOSI/InventoryOS</v1:senderURI>"                    + "<v1:destinationURI>/MTOSI/EmsOS</v1:destinationURI>"                  + "<v1:security>admin_VARIABLE_admin</v1:security>"                  + "<v1:communicationPattern>SimpleResponse</v1:communicationPattern>"                    + "<v1:communicationStyle>RPC</v1:communicationStyle>"                  + "</v1:header>" +                  "</soapenv:Header>" +                  "<soapenv:Body>" +                  "<v11:getAllManagedElementsRequest>" +                  "<!--Optional:-->" +                  "<v11:mdOrMlsnRef>" +                  "<!--1 or more repetitions:-->" +                  "<v12:rdn>" +                  "<v12:type>MD</v12:type>" +                  "<v12:value>GZ</v12:value>" +                  "</v12:rdn>" +                  "</v11:mdOrMlsnRef>" +                  "</v11:getAllManagedElementsRequest>" +                  "</soapenv:Body>" +                  "</soapenv:Envelope>" ;                  String url = "wsdl地址";                  String soap = SoapRequest(report, url,"getAllManagedElements");                  System.out.println("返回的xml报文是:" + soap);          } } 从报文里面的<v11:getAllManagedElementsRequest>就可以知道操作类型是getAllManagedElements,也可以从<v1:activityName> getAllManagedElements</v1:activityName>获得,执行程序便可以获得数据了,然后你再解析xml,通过正则表达式解析,别用 dom4j(个人认为只适合简单的),在入库就ok了。
转载请注明原文地址: https://www.6miu.com/read-29925.html

最新回复(0)