|
@@ -0,0 +1,460 @@
|
|
|
|
|
+package com.fdkankan.modeldemo.utils;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
|
|
+import org.apache.commons.logging.Log;
|
|
|
|
|
+import org.apache.commons.logging.LogFactory;
|
|
|
|
|
+import org.apache.http.HttpEntity;
|
|
|
|
|
+import org.apache.http.HttpResponse;
|
|
|
|
|
+import org.apache.http.NameValuePair;
|
|
|
|
|
+import org.apache.http.client.ClientProtocolException;
|
|
|
|
|
+import org.apache.http.client.CookieStore;
|
|
|
|
|
+import org.apache.http.client.config.RequestConfig;
|
|
|
|
|
+import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
|
|
+import org.apache.http.client.methods.HttpGet;
|
|
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
|
|
+import org.apache.http.entity.ContentType;
|
|
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
|
|
+import org.apache.http.impl.client.BasicCookieStore;
|
|
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
|
|
+import org.apache.http.impl.client.HttpClientBuilder;
|
|
|
|
|
+import org.apache.http.impl.cookie.BasicClientCookie;
|
|
|
|
|
+import org.apache.http.message.BasicNameValuePair;
|
|
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
|
|
+
|
|
|
|
|
+import java.io.DataOutputStream;
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.io.InputStream;
|
|
|
|
|
+import java.net.HttpURLConnection;
|
|
|
|
|
+import java.net.URL;
|
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ *
|
|
|
|
|
+ * Http工具类
|
|
|
|
|
+ *
|
|
|
|
|
+ * <pre>
|
|
|
|
|
+ * 非证书请求
|
|
|
|
|
+ * </pre>
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author: 张志宏
|
|
|
|
|
+ * @email: it_javasun@yeah.net
|
|
|
|
|
+ * @date:2015年7月3日 下午4:20:48
|
|
|
|
|
+ * @since 1.0.0
|
|
|
|
|
+ */
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@SuppressWarnings("all")
|
|
|
|
|
+public class HttpClientUtil {
|
|
|
|
|
+ private final static transient Log logger = LogFactory.getLog(HttpClientUtil.class);
|
|
|
|
|
+
|
|
|
|
|
+ public static final String CHARSET = "UTF-8";
|
|
|
|
|
+ public static final int CONNECT_TIMEOUT = 10 * 10000;
|
|
|
|
|
+
|
|
|
|
|
+ private static CloseableHttpClient httpClient;
|
|
|
|
|
+
|
|
|
|
|
+ static {
|
|
|
|
|
+ RequestConfig config = RequestConfig.custom()
|
|
|
|
|
+ .setConnectionRequestTimeout(CONNECT_TIMEOUT)
|
|
|
|
|
+ .setConnectTimeout(CONNECT_TIMEOUT)
|
|
|
|
|
+ .setSocketTimeout(CONNECT_TIMEOUT).build();
|
|
|
|
|
+ httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * 外部调用的GET方法
|
|
|
|
|
+ * </p>
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param url
|
|
|
|
|
+ * 请求地址
|
|
|
|
|
+ * @param params
|
|
|
|
|
+ * 请求参数
|
|
|
|
|
+ * @return String 返回请求串
|
|
|
|
|
+ * @author: 张志宏
|
|
|
|
|
+ * @date:2015年7月3日 下午12:01:13
|
|
|
|
|
+ * @since 1.0.0
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String doGet(String url, Map<String, String> params) {
|
|
|
|
|
+ return doGet(url, params, CHARSET);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * 外部调用的POST方法
|
|
|
|
|
+ * </p>
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param url
|
|
|
|
|
+ * 请求地址
|
|
|
|
|
+ * @param params
|
|
|
|
|
+ * 请求参数
|
|
|
|
|
+ * @return String 返回请求串
|
|
|
|
|
+ * @author: 张志宏
|
|
|
|
|
+ * @date:2015年7月3日 下午12:02:03
|
|
|
|
|
+ * @since 1.0.0
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String doPost(String url, Map<String, String> params) {
|
|
|
|
|
+ return doPost(url, params, CHARSET);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * HTTP Get 获取内容
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param url
|
|
|
|
|
+ * 请求的url地址 ?之前的地址
|
|
|
|
|
+ * @param params
|
|
|
|
|
+ * 请求的参数
|
|
|
|
|
+ * @param charset
|
|
|
|
|
+ * 编码格式
|
|
|
|
|
+ * @return 页面内容
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String doGet(String url, Map<String, String> params,
|
|
|
|
|
+ String charset) {
|
|
|
|
|
+ if (StringUtils.isBlank(url)) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (params != null && !params.isEmpty()) {
|
|
|
|
|
+ List<NameValuePair> pairs = new ArrayList<NameValuePair>(
|
|
|
|
|
+ params.size());
|
|
|
|
|
+ for (Map.Entry<String, String> entry : params.entrySet()) {
|
|
|
|
|
+ String value = entry.getValue();
|
|
|
|
|
+ if (value != null) {
|
|
|
|
|
+ pairs.add(new BasicNameValuePair(entry.getKey(), value));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ url += "?"
|
|
|
|
|
+ + EntityUtils.toString(new UrlEncodedFormEntity(pairs,
|
|
|
|
|
+ charset));
|
|
|
|
|
+ }
|
|
|
|
|
+ HttpGet httpGet = new HttpGet(url);
|
|
|
|
|
+ CloseableHttpResponse response = httpClient.execute(httpGet);
|
|
|
|
|
+ int statusCode = response.getStatusLine().getStatusCode();
|
|
|
|
|
+ if (statusCode != 200) {
|
|
|
|
|
+ httpGet.abort();
|
|
|
|
|
+ throw new RuntimeException("HttpClient,error status code :"
|
|
|
|
|
+ + statusCode);
|
|
|
|
|
+ }
|
|
|
|
|
+ HttpEntity entity = response.getEntity();
|
|
|
|
|
+ String result = null;
|
|
|
|
|
+ if (entity != null) {
|
|
|
|
|
+ result = EntityUtils.toString(entity, "utf-8");
|
|
|
|
|
+ }
|
|
|
|
|
+ EntityUtils.consume(entity);
|
|
|
|
|
+ response.close();
|
|
|
|
|
+ return result;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error(e.getMessage(),e);
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * HTTP Post 获取内容
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param url
|
|
|
|
|
+ * 请求的url地址 ?之前的地址
|
|
|
|
|
+ * @param params
|
|
|
|
|
+ * 请求的参数
|
|
|
|
|
+ * @param charset
|
|
|
|
|
+ * 编码格式
|
|
|
|
|
+ * @return 页面内容
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String doPost(String url, Map<String, String> params,
|
|
|
|
|
+ String charset) {
|
|
|
|
|
+ if (StringUtils.isBlank(url)) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ List<NameValuePair> pairs = null;
|
|
|
|
|
+ if (params != null && !params.isEmpty()) {
|
|
|
|
|
+ pairs = new ArrayList<NameValuePair>(params.size());
|
|
|
|
|
+ for (Map.Entry<String, String> entry : params.entrySet()) {
|
|
|
|
|
+ String value = entry.getValue();
|
|
|
|
|
+ if (value != null) {
|
|
|
|
|
+ pairs.add(new BasicNameValuePair(entry.getKey(), value));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ HttpPost httpPost = new HttpPost(url);
|
|
|
|
|
+
|
|
|
|
|
+ if (pairs != null && pairs.size() > 0) {
|
|
|
|
|
+ httpPost.setEntity(new UrlEncodedFormEntity(pairs, CHARSET));
|
|
|
|
|
+ }
|
|
|
|
|
+ CloseableHttpResponse response = httpClient.execute(httpPost);
|
|
|
|
|
+ String jsessionId = getJsessionId(response);
|
|
|
|
|
+ int statusCode = response.getStatusLine().getStatusCode();
|
|
|
|
|
+ if (statusCode != 200) {
|
|
|
|
|
+ if(statusCode==302){
|
|
|
|
|
+ return "{\"JSESSIONID\":\""+jsessionId+"\"}";
|
|
|
|
|
+ }
|
|
|
|
|
+ httpPost.abort();
|
|
|
|
|
+ throw new RuntimeException("HttpClient,error status code :"
|
|
|
|
|
+ + statusCode);
|
|
|
|
|
+ }
|
|
|
|
|
+ HttpEntity entity = response.getEntity();
|
|
|
|
|
+ String result = null;
|
|
|
|
|
+ if (entity != null) {
|
|
|
|
|
+ result = EntityUtils.toString(entity, "utf-8");
|
|
|
|
|
+ }
|
|
|
|
|
+ EntityUtils.consume(entity);
|
|
|
|
|
+ response.close();
|
|
|
|
|
+ return result;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("HttpClientUtil.doPost error, url:" + url + ", errorMsg:" + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 发送 POST 请求
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param path
|
|
|
|
|
+ * 请求路径
|
|
|
|
|
+ * @param map
|
|
|
|
|
+ * 参数
|
|
|
|
|
+ * @return 如果为空设置 GET 请求
|
|
|
|
|
+ * @throws Exception
|
|
|
|
|
+ */
|
|
|
|
|
+ public static InputStream sendPostRequest(String path,
|
|
|
|
|
+ Map<String, Object> map) throws Exception {
|
|
|
|
|
+
|
|
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
|
|
+ for (Map.Entry<String, Object> entry : map.entrySet()) {
|
|
|
|
|
+
|
|
|
|
|
+ if (entry.getValue() instanceof String) {
|
|
|
|
|
+ sb.append(entry.getKey())
|
|
|
|
|
+ .append("=")
|
|
|
|
|
+ .append(URLEncoder.encode(entry.getValue().toString(),
|
|
|
|
|
+ "UTF-8"));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ sb.append(entry.getKey()).append("=").append(entry.getValue());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // sb.append(entry.getKey()).append("=").append(entry.getValue());
|
|
|
|
|
+ sb.append('&');
|
|
|
|
|
+ }
|
|
|
|
|
+ sb.deleteCharAt(sb.length() - 1);
|
|
|
|
|
+ if (path.indexOf("?") != -1) {
|
|
|
|
|
+ logger.info("path:" + path + "&" + sb);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ logger.info("path:" + path + "?" + sb);
|
|
|
|
|
+ }
|
|
|
|
|
+ byte[] data = sb.toString().getBytes();
|
|
|
|
|
+ URL url = new URL(path);
|
|
|
|
|
+ HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
|
|
|
|
+ con.setRequestMethod("POST");
|
|
|
|
|
+ con.setConnectTimeout(6 * 1000);
|
|
|
|
|
+ con.setDoOutput(true);// 发送 POST 请求必须设置允许输出
|
|
|
|
|
+ con.setUseCaches(false);// 不设置 cache
|
|
|
|
|
+ con.setRequestProperty("Connection", "Keep-Alive");// 维持长链接
|
|
|
|
|
+ con.setRequestProperty("Charset", "UTF-8");
|
|
|
|
|
+ con.setRequestProperty("Content-Length", String.valueOf(data.length));
|
|
|
|
|
+ con.setRequestProperty("Content-Type",
|
|
|
|
|
+ "application/x-www-form-urlencoded");
|
|
|
|
|
+ DataOutputStream dataOutputStream = new DataOutputStream(
|
|
|
|
|
+ con.getOutputStream());
|
|
|
|
|
+ dataOutputStream.write(data);
|
|
|
|
|
+ dataOutputStream.flush();
|
|
|
|
|
+ dataOutputStream.close();
|
|
|
|
|
+ if (con.getResponseCode() == 200) {
|
|
|
|
|
+ return con.getInputStream();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static String doPostThrowException(String url, Map<String, String> params) throws Exception {
|
|
|
|
|
+ return doPostThrowException(url, params, CHARSET);
|
|
|
|
|
+ }
|
|
|
|
|
+ public static String doPostThrowException(String url, Map<String, String> params,
|
|
|
|
|
+ String charset) throws Exception {
|
|
|
|
|
+ List<NameValuePair> pairs = null;
|
|
|
|
|
+ if (params != null && !params.isEmpty()) {
|
|
|
|
|
+ pairs = new ArrayList<NameValuePair>(params.size());
|
|
|
|
|
+ for (Map.Entry<String, String> entry : params.entrySet()) {
|
|
|
|
|
+ String value = entry.getValue();
|
|
|
|
|
+ if (value != null) {
|
|
|
|
|
+ pairs.add(new BasicNameValuePair(entry.getKey(), value));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ HttpPost httpPost = new HttpPost(url);
|
|
|
|
|
+ if (pairs != null && pairs.size() > 0) {
|
|
|
|
|
+ httpPost.setEntity(new UrlEncodedFormEntity(pairs, CHARSET));
|
|
|
|
|
+ }
|
|
|
|
|
+ CloseableHttpResponse response = httpClient.execute(httpPost);
|
|
|
|
|
+ int statusCode = response.getStatusLine().getStatusCode();
|
|
|
|
|
+ if (statusCode != 200) {
|
|
|
|
|
+ httpPost.abort();
|
|
|
|
|
+ throw new RuntimeException("HttpClient,error status code :"
|
|
|
|
|
+ + statusCode);
|
|
|
|
|
+ }
|
|
|
|
|
+ HttpEntity entity = response.getEntity();
|
|
|
|
|
+ String result = null;
|
|
|
|
|
+ if (entity != null) {
|
|
|
|
|
+ result = EntityUtils.toString(entity, "utf-8");
|
|
|
|
|
+ }
|
|
|
|
|
+ EntityUtils.consume(entity);
|
|
|
|
|
+ response.close();
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param
|
|
|
|
|
+ * @return
|
|
|
|
|
+ * @author wangtaida
|
|
|
|
|
+ * @Date: 11:06 2018/12/17
|
|
|
|
|
+ * @Description: 取出cookie的JSESSIONID
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String getJsessionId(HttpResponse httpResponse){
|
|
|
|
|
+ log.info("JsessionId的值:{}",httpResponse.toString());
|
|
|
|
|
+ String JSESSIONID="";
|
|
|
|
|
+ if(null!=httpResponse.getFirstHeader("Set-Cookie")){
|
|
|
|
|
+ String setCookie = httpResponse.getFirstHeader("Set-Cookie").getValue();
|
|
|
|
|
+ JSESSIONID = setCookie.substring("JSESSIONID=".length(),setCookie.indexOf(";"));
|
|
|
|
|
+ return JSESSIONID;
|
|
|
|
|
+ }
|
|
|
|
|
+ return JSESSIONID;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param
|
|
|
|
|
+ * @return
|
|
|
|
|
+ * @author wangtaida
|
|
|
|
|
+ * @Date: 16:41 2018/12/17
|
|
|
|
|
+ * @Description: 在请求头里追加cookie
|
|
|
|
|
+ */
|
|
|
|
|
+ public static CookieStore addCookieStore(String JSESSIONID){
|
|
|
|
|
+ CookieStore cookieStore = new BasicCookieStore();
|
|
|
|
|
+ BasicClientCookie cookie = new BasicClientCookie("JSESSIONID",JSESSIONID);
|
|
|
|
|
+ cookie.setVersion(0);
|
|
|
|
|
+ cookie.setDomain(".123.126.34.6");
|
|
|
|
|
+ cookie.setPath("/");
|
|
|
|
|
+ cookieStore.addCookie(cookie);
|
|
|
|
|
+ return cookieStore;
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param
|
|
|
|
|
+ * @return
|
|
|
|
|
+ * @author wangtaida
|
|
|
|
|
+ * @Date: 16:52 2018/12/17
|
|
|
|
|
+ * @Description: 发送post请求 入参是请求地址和json字符串
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String doPostJson(String url, String json) throws ClientProtocolException, IOException {
|
|
|
|
|
+ // 创建HttpClientBuilder
|
|
|
|
|
+ // HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
|
|
|
|
|
+ //JSONObject jsonObject = JSONObject.parseObject(json, JSONObject.class);
|
|
|
|
|
+ // String JSESSIONID = jsonObject.getString("JSESSIONID");
|
|
|
|
|
+ //CookieStore cookieStore = addCookieStore(JSESSIONID);
|
|
|
|
|
+ //httpClient = httpClientBuilder.setDefaultCookieStore(cookieStore).build();
|
|
|
|
|
+ // 创建http POST请求
|
|
|
|
|
+ HttpPost httpPost = new HttpPost(url);
|
|
|
|
|
+ if (json != null) {
|
|
|
|
|
+ // 构造一个form表单式的实体
|
|
|
|
|
+ StringEntity stringEntity = new StringEntity(json, ContentType.APPLICATION_JSON);
|
|
|
|
|
+ // 将请求实体设置到httpPost对象中
|
|
|
|
|
+ httpPost.setEntity(stringEntity);
|
|
|
|
|
+ }
|
|
|
|
|
+ CloseableHttpResponse response = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 执行请求
|
|
|
|
|
+ response = httpClient.execute(httpPost);
|
|
|
|
|
+ log.info("POST 访问url:" + url + " 状态为: " + response.getStatusLine().getStatusCode());
|
|
|
|
|
+ String re = EntityUtils.toString(response.getEntity(), "UTF-8");
|
|
|
|
|
+ log.info("返回结果为: "+re);
|
|
|
|
|
+ return re;
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ if (response != null) {
|
|
|
|
|
+ response.close();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 测试直接获取 目标文件
|
|
|
|
|
+ */
|
|
|
|
|
+ public static void testGet(){
|
|
|
|
|
+ String result = doGet("http://10.180.22.41:8761/group2/M05/37/43/CrQWK2SFuzOELc4KAAAAABI4ceU987.txt",null);
|
|
|
|
|
+ System.out.println(result);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+ public static void testGetStatPageInfo(){
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // String URL = "http://10.180.41.35:10017/app/station/info/45060201000102";
|
|
|
|
|
+ String URL = "http://10.180.41.35:10019/app/station/lower/resource/page";
|
|
|
|
|
+// Map<String, List<Map<String, String>>> mapParames = new HashMap<String, List<Map<String, String>>>();
|
|
|
|
|
+// List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
|
|
|
|
|
+// Map<String, String> map = new HashMap<String, String>();
|
|
|
|
|
+// map.put("keyword", "20096095");
|
|
|
|
|
+// map.put("keywordType", "salesZO");
|
|
|
|
|
+// map.put("operator", "SZOASE");
|
|
|
|
|
+// map.put("value", "SZOASE");
|
|
|
|
|
+// Map<String, String> mapTwo = new HashMap<String, String>();
|
|
|
|
|
+// map.put("beEvaluatorId", "20096095");
|
|
|
|
|
+// map.put("beEvaluatorType", "salesZO");
|
|
|
|
|
+// map.put("questionType", "SZOASE");
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// String getData = doGet(URL, map);
|
|
|
|
|
+// System.out.println(getData);
|
|
|
|
|
+ //System.out.println("----------------------分割线-----------------------");
|
|
|
|
|
+ //String postData = doPost(URL, map);
|
|
|
|
|
+ // System.out.println(postData);
|
|
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
|
|
+ JSONArray paramArr = new JSONArray();
|
|
|
|
|
+ JSONObject stationCodes = new JSONObject();
|
|
|
|
|
+ stationCodes.put("keyword","STATION_CODE");
|
|
|
|
|
+ stationCodes.put("keywordType","input");
|
|
|
|
|
+ stationCodes.put("operator","=");
|
|
|
|
|
+ stationCodes.put("value",new String[]{"45060201000102"});
|
|
|
|
|
+ paramArr.add(stationCodes);
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject entityNames = new JSONObject();
|
|
|
|
|
+ entityNames.put("keyword","ENTITY_NAME");
|
|
|
|
|
+ entityNames.put("keywordType","input");
|
|
|
|
|
+ entityNames.put("operator","=");
|
|
|
|
|
+ entityNames.put("value",new String[]{"防城港港口区金海湾小区C1-9栋联通LTE/-003"});
|
|
|
|
|
+// entityNames.put("value",new String[]{"防城港港口联通LTE/-003"});
|
|
|
|
|
+ paramArr.add(entityNames);
|
|
|
|
|
+// String[] testPram = new String[]{stationCodes.toJSONString(),entityNames.toJSONString()};
|
|
|
|
|
+ params.put("params",paramArr.toString());
|
|
|
|
|
+ System.out.println(params);
|
|
|
|
|
+
|
|
|
|
|
+// String jsonP = "{\"params\":\"[{\\\"keywordType\\\":\\\"input\\\",\\\"keyword\\\":\\\"STATION_CODE\\\",\\\"value\\\":[\\\"45060201000102\\\"],\\\"operator\\\":\\\"=\\\"},{\\\"keywordType\\\":\\\"input\\\",\\\"keyword\\\":\\\"ENTITY_NAME\\\",\\\"value\\\":[\\\"防城港港口区金海湾小区C1-9栋联通LTE/-003\\\"],\\\"operator\\\":\\\"=\\\"}]\"}";
|
|
|
|
|
+// System.out.println(jsonP);
|
|
|
|
|
+ try {
|
|
|
|
|
+ //System.out.println(jsonP);
|
|
|
|
|
+ String result = doPostJson(URL,params.toString());
|
|
|
|
|
+ System.out.println("the Result="+result);
|
|
|
|
|
+ Map<String, Object> parse = JSON.parseObject(result);
|
|
|
|
|
+ JSONArray retnDate = JSON.parseArray(parse.get("data").toString());
|
|
|
|
|
+ if(retnDate.size()==0){
|
|
|
|
|
+ logger.error("站址编码、机房实物名称 获取结果为空!");
|
|
|
|
|
+ }else if(retnDate.size()>1){
|
|
|
|
|
+ logger.error("站址编码、机房实物名称 获取结果有多个记录,匹配异常.");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject currObj = (JSONObject)retnDate.get(0);
|
|
|
|
|
+ System.out.println(currObj.get("ENTITY_ID"));
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ //测试入口
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
|
+ testGet();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|