/*     */ package com.picc.grab.util;
/*     */ 
/*     */ import java.io.UnsupportedEncodingException;
/*     */ import java.net.URLEncoder;
/*     */ import java.security.KeyManagementException;
/*     */ import java.security.NoSuchAlgorithmException;
/*     */ import java.security.cert.X509Certificate;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.net.ssl.SSLContext;
/*     */ import javax.net.ssl.TrustManager;
/*     */ import javax.net.ssl.X509TrustManager;
/*     */ import org.apache.commons.lang.StringUtils;
/*     */ import org.apache.http.HttpEntity;
/*     */ import org.apache.http.HttpResponse;
/*     */ import org.apache.http.NameValuePair;
/*     */ import org.apache.http.client.HttpClient;
/*     */ import org.apache.http.client.entity.UrlEncodedFormEntity;
/*     */ import org.apache.http.client.methods.HttpDelete;
/*     */ import org.apache.http.client.methods.HttpGet;
/*     */ import org.apache.http.client.methods.HttpPost;
/*     */ import org.apache.http.client.methods.HttpPut;
/*     */ import org.apache.http.client.methods.HttpUriRequest;
/*     */ import org.apache.http.conn.ClientConnectionManager;
/*     */ import org.apache.http.conn.scheme.Scheme;
/*     */ import org.apache.http.conn.scheme.SchemeRegistry;
/*     */ import org.apache.http.conn.scheme.SchemeSocketFactory;
/*     */ import org.apache.http.conn.ssl.SSLSocketFactory;
/*     */ import org.apache.http.entity.ByteArrayEntity;
/*     */ import org.apache.http.entity.StringEntity;
/*     */ import org.apache.http.impl.client.DefaultHttpClient;
/*     */ import org.apache.http.message.BasicNameValuePair;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class AliVinHttpUtils
/*     */ {
/*     */   public static HttpResponse doGet(String host, String path, String method, Map<String, String> headers, Map<String, String> querys) throws Exception {
/*  52 */     HttpClient httpClient = wrapClient(host);
/*     */     
/*  54 */     HttpGet request = new HttpGet(buildUrl(host, path, querys));
/*  55 */     for (Map.Entry<String, String> e : headers.entrySet()) {
/*  56 */       request.addHeader(e.getKey(), e.getValue());
/*     */     }
/*     */     
/*  59 */     return httpClient.execute((HttpUriRequest)request);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static HttpResponse doPost(String host, String path, String method, Map<String, String> headers, Map<String, String> querys, Map<String, String> bodys) throws Exception {
/*  79 */     HttpClient httpClient = wrapClient(host);
/*     */     
/*  81 */     HttpPost request = new HttpPost(buildUrl(host, path, querys));
/*  82 */     for (Map.Entry<String, String> e : headers.entrySet()) {
/*  83 */       request.addHeader(e.getKey(), e.getValue());
/*     */     }
/*     */     
/*  86 */     if (bodys != null) {
/*  87 */       List<NameValuePair> nameValuePairList = new ArrayList<>();
/*     */       
/*  89 */       for (String key : bodys.keySet()) {
/*  90 */         nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
/*     */       }
/*  92 */       UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
/*  93 */       formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
/*  94 */       request.setEntity((HttpEntity)formEntity);
/*     */     } 
/*     */     
/*  97 */     return httpClient.execute((HttpUriRequest)request);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static HttpResponse doPost(String host, String path, String method, Map<String, String> headers, Map<String, String> querys, String body) throws Exception {
/* 117 */     HttpClient httpClient = wrapClient(host);
/*     */     
/* 119 */     HttpPost request = new HttpPost(buildUrl(host, path, querys));
/* 120 */     for (Map.Entry<String, String> e : headers.entrySet()) {
/* 121 */       request.addHeader(e.getKey(), e.getValue());
/*     */     }
/*     */     
/* 124 */     if (StringUtils.isNotBlank(body)) {
/* 125 */       request.setEntity((HttpEntity)new StringEntity(body, "utf-8"));
/*     */     }
/*     */     
/* 128 */     return httpClient.execute((HttpUriRequest)request);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static HttpResponse doPost(String host, String path, String method, Map<String, String> headers, Map<String, String> querys, byte[] body) throws Exception {
/* 148 */     HttpClient httpClient = wrapClient(host);
/*     */     
/* 150 */     HttpPost request = new HttpPost(buildUrl(host, path, querys));
/* 151 */     for (Map.Entry<String, String> e : headers.entrySet()) {
/* 152 */       request.addHeader(e.getKey(), e.getValue());
/*     */     }
/*     */     
/* 155 */     if (body != null) {
/* 156 */       request.setEntity((HttpEntity)new ByteArrayEntity(body));
/*     */     }
/*     */     
/* 159 */     return httpClient.execute((HttpUriRequest)request);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static HttpResponse doPut(String host, String path, String method, Map<String, String> headers, Map<String, String> querys, String body) throws Exception {
/* 178 */     HttpClient httpClient = wrapClient(host);
/*     */     
/* 180 */     HttpPut request = new HttpPut(buildUrl(host, path, querys));
/* 181 */     for (Map.Entry<String, String> e : headers.entrySet()) {
/* 182 */       request.addHeader(e.getKey(), e.getValue());
/*     */     }
/*     */     
/* 185 */     if (StringUtils.isNotBlank(body)) {
/* 186 */       request.setEntity((HttpEntity)new StringEntity(body, "utf-8"));
/*     */     }
/*     */     
/* 189 */     return httpClient.execute((HttpUriRequest)request);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static HttpResponse doPut(String host, String path, String method, Map<String, String> headers, Map<String, String> querys, byte[] body) throws Exception {
/* 208 */     HttpClient httpClient = wrapClient(host);
/*     */     
/* 210 */     HttpPut request = new HttpPut(buildUrl(host, path, querys));
/* 211 */     for (Map.Entry<String, String> e : headers.entrySet()) {
/* 212 */       request.addHeader(e.getKey(), e.getValue());
/*     */     }
/*     */     
/* 215 */     if (body != null) {
/* 216 */       request.setEntity((HttpEntity)new ByteArrayEntity(body));
/*     */     }
/*     */     
/* 219 */     return httpClient.execute((HttpUriRequest)request);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static HttpResponse doDelete(String host, String path, String method, Map<String, String> headers, Map<String, String> querys) throws Exception {
/* 237 */     HttpClient httpClient = wrapClient(host);
/*     */     
/* 239 */     HttpDelete request = new HttpDelete(buildUrl(host, path, querys));
/* 240 */     for (Map.Entry<String, String> e : headers.entrySet()) {
/* 241 */       request.addHeader(e.getKey(), e.getValue());
/*     */     }
/*     */     
/* 244 */     return httpClient.execute((HttpUriRequest)request);
/*     */   }
/*     */   
/*     */   private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException {
/* 248 */     StringBuilder sbUrl = new StringBuilder();
/* 249 */     sbUrl.append(host);
/* 250 */     if (!StringUtils.isBlank(path)) {
/* 251 */       sbUrl.append(path);
/*     */     }
/* 253 */     if (null != querys) {
/* 254 */       StringBuilder sbQuery = new StringBuilder();
/* 255 */       for (Map.Entry<String, String> query : querys.entrySet()) {
/* 256 */         if (0 < sbQuery.length()) {
/* 257 */           sbQuery.append("&");
/*     */         }
/* 259 */         if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) {
/* 260 */           sbQuery.append(query.getValue());
/*     */         }
/* 262 */         if (!StringUtils.isBlank(query.getKey())) {
/* 263 */           sbQuery.append(query.getKey());
/* 264 */           if (!StringUtils.isBlank(query.getValue())) {
/* 265 */             sbQuery.append("=");
/* 266 */             sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8"));
/*     */           } 
/*     */         } 
/*     */       } 
/* 270 */       if (0 < sbQuery.length()) {
/* 271 */         sbUrl.append("?").append(sbQuery);
/*     */       }
/*     */     } 
/*     */     
/* 275 */     return sbUrl.toString();
/*     */   }
/*     */   
/*     */   private static HttpClient wrapClient(String host) {
/* 279 */     DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
/* 280 */     if (host.startsWith("https://")) {
/* 281 */       sslClient((HttpClient)defaultHttpClient);
/*     */     }
/*     */     
/* 284 */     return (HttpClient)defaultHttpClient;
/*     */   }
/*     */   
/*     */   private static void sslClient(HttpClient httpClient) {
/*     */     try {
/* 289 */       SSLContext ctx = SSLContext.getInstance("TLS");
/* 290 */       X509TrustManager tm = new X509TrustManager() {
/*     */           public X509Certificate[] getAcceptedIssuers() {
/* 292 */             return null;
/*     */           }
/*     */ 
/*     */           
/*     */           public void checkClientTrusted(X509Certificate[] xcs, String str) {}
/*     */ 
/*     */           
/*     */           public void checkServerTrusted(X509Certificate[] xcs, String str) {}
/*     */         };
/* 301 */       ctx.init(null, new TrustManager[] { tm }, null);
/* 302 */       SSLSocketFactory ssf = new SSLSocketFactory(ctx);
/* 303 */       ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
/* 304 */       ClientConnectionManager ccm = httpClient.getConnectionManager();
/* 305 */       SchemeRegistry registry = ccm.getSchemeRegistry();
/* 306 */       registry.register(new Scheme("https", 443, (SchemeSocketFactory)ssf));
/* 307 */     } catch (KeyManagementException ex) {
/* 308 */       throw new RuntimeException(ex);
/* 309 */     } catch (NoSuchAlgorithmException ex) {
/* 310 */       throw new RuntimeException(ex);
/*     */     } 
/*     */   }
/*     */ }


/* Location:              C:\Users\Administrator\Desktop\ROOT\WEB-INF\classes\!\com\picc\gra\\util\AliVinHttpUtils.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */