首页天道酬勤webservice(webservice服务)

webservice(webservice服务)

admin 01-28 18:28 172次浏览

测试工具下载soapui测试http://ws.webxml.com.cn/web服务/weatherws.asmx吗? wdlpackagecom.extra.credit.util; import com.Alibaba.fast JSON.JSON; import com.Alibaba.fast JSON.JSON array; import com.Alibaba.fast JSON.JSON object; importorg.Apache.com mons.io.I outils; importorg.Apache.http.http entity; importorg.Apache.http.client.methods.closeablehttpresponse; importorg.Apache.http.client.methods.http post; importorg.Apache.http.entity.string entity; importorg.Apache.http.impl.client.closeablehttpclient; importorg.Apache.http.impl.client.http客户端构建器; importorg.Apache.http.util.entity utils; import org.dom4j.Document; importorg.dom4j.document exception; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.slf4j.Logger; import org.slf4j.LoggerFactory; importorg.spring framework.stereotype.com ponent; import java.nio.charset.Charset; import java.util.List; /** * pre *工具类: web服务* /pre * * pre * @author nicky ma *修改记录*修改后版本:修改者:修改日期:2021/03/111033 @ componentpublicclasswshttpclientuils { staticloggerlog=logger factory.getlogger (wshttpclientuils.class );/* * * http客户端方式为web服务API br * @ authormazq * @ date 2021/03/1110336014 * @ param [ point,params, methodName] * @return java.lang .强力唇膏/publicstaticstringdopostwebserviceurl (stringpoint,String params, stringsoapactivation//httpclientbuilderhttpclientbuilderhttpclientbuilder=http客户端builder.create (; //httpclientcloseablehttpclientcloseablehttpclient=http客户端构建器. build (; http post http post=new http post (point; try { http post.setheader (' content-type ',' text/xml; charset=UTF-8 '; HTTPpost.setheader('soapAction ',soapaction ); stringentitydata=new string entity (params,charset.forname ) (utf-8 ) ); HTPpost.setentity(data ); closeablehttpresponseresponse=closeablehttpclient.execute (http post ); httpentityhttpentity=response.get entity (; If (http实体!=null (result=entity utils.tostring ) httpentity,' UTF-8 ' );

} } catch (Exception e) { log.error("调用远程WebService接口异常:{}" , e); throw e; }finally { IOUtils.closeQuietly(closeableHttpClient); } return result; } /** * xml转换为JSONObject <br> * @Author nicky ma * @Date 2021/03/11 10:01 * @Param [xmlStr] * @return com.alibaba.fastjson.hldqb/ public static JSONObject xml2Json(String xmlStr) throws DocumentException { Document doc = DocumentHelper.parseText(xmlStr); JSONObject json = new JSONObject(); doParseXmlElements(doc.getRootElement() , json); return json; } /** * xml Document Elements解析 <br> * @Author nicky ma * @Date 2021/03/11 10:01 * @Param [element, json] * @return void */ public static void doParseXmlElements(Element element, JSONObject json) { List<Element> chdEl = element.elements(); for(Element e : chdEl){ if (!e.elements().isEmpty()) { JSONObject chdjson = new JSONObject(); doParseXmlElements(e, chdjson); Object o = json.get(e.getName()); if (o != null) { JSONArray jsona = null; if (o instanceof JSONObject) { JSONObject jsono = (JSONObject) o; json.remove(e.getName()); jsona = new JSONArray(); jsona.add(jsono); jsona.add(chdjson); } if (o instanceof JSONArray) { jsona = (JSONArray) o; jsona.add(chdjson); } json.put(e.getName(), jsona); } else { if (!chdjson.isEmpty()) { json.put(e.getName(), chdjson); } } } else { if (!e.getText().isEmpty()) { json.put(e.getName(), e.getText()); } } } }} protected Map<String , String> obtainTokenByHttp(String paramJson , String url) throws Exception { StringBuffer soapRequestParams = new StringBuffer(); soapRequestParams.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://service.webservice.catalog.infotrust.com\">"); soapRequestParams.append("<soapenv:Header/>"); soapRequestParams.append("<soapenv:Body>"); soapRequestParams.append("<ser:getToken>"); soapRequestParams.append("<ser:in0>"+paramJson+"</ser:in0>"); soapRequestParams.append("</ser:getToken>"); soapRequestParams.append("</soapenv:Body>"); soapRequestParams.append("</soapenv:Envelope>"); logger.warn(String.format("request params:%s", soapRequestParams.toString())); String returnDatabase = WSHttpClientUils.doPostWebServiceURL(url , soapRequestParams.toString(),""); logger.warn(String.format("xml string:%s" , returnDatabase)); com.alibaba.fastjson.JSONObject jsonObject = WSHttpClientUils.xml2Json(returnDatabase); com.alibaba.fastjson.JSONObject body = jsonObject.getJSONObject("Body"); com.alibaba.fastjson.JSONObject getSafeTokenResponse = body.getJSONObject("getSafeTokenResponse"); String out = getSafeTokenResponse.getString("out"); com.alibaba.fastjson.JSONObject outJson = JSON.parseObject(out); String code = outJson.getString("code"); String message = outJson.getString("message"); String token = ""; logger.warn(String.format("webservice api返回数据,code:%s,message:%s",code, message)); if ("200".equals(code)) { token = outJson.getString("token"); } if (logger.isInfoEnabled()) { logger.info(String.format("api token:%s", token)); } Map<String,String> result = new HashMap<String, String>(2); result.put("token",token); return result; }
UGUI实现ScrollView无限滚动效果毕业设计 - 题目:基于stm32的车牌识别系统设计创建PVC 容器云 UK8Sjava实现文本复制功能
调用webservice服务(webservice) webservice调用方式(通过webservice调用接口)
相关内容