|
|
@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import org.apache.http.HttpResponse;
|
|
|
import org.apache.http.HttpStatus;
|
|
|
import org.apache.http.ParseException;
|
|
|
-import org.apache.http.client.ClientProtocolException;
|
|
|
import org.apache.http.client.HttpClient;
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
@@ -14,6 +13,7 @@ import org.apache.http.impl.client.HttpClientBuilder;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.net.UnknownHostException;
|
|
|
import java.nio.charset.Charset;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
@@ -70,26 +70,25 @@ public class HttpUtils {
|
|
|
HttpResponse response = null;
|
|
|
try {
|
|
|
response = httpClient.execute(httpPost);
|
|
|
- if (null == response || response.getStatusLine() == null) {
|
|
|
- throw new Exception("Post Request For Url[{}] is not ok. Response is null");
|
|
|
- } else if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
|
|
|
- throw new Exception("Post Request For Url[{}] is not ok. Response Status Code is {"+response.getStatusLine().getStatusCode()+"}");
|
|
|
- }
|
|
|
- } catch (ClientProtocolException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ if (null == response || response.getStatusLine() == null) {
|
|
|
+ throw new Exception("Post Request For Url[{}] is not ok. Response is null");
|
|
|
+ } else if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
|
|
|
+ throw new Exception("Post Request For Url[{}] is not ok. Response Status Code is {"+response.getStatusLine().getStatusCode()+"}");
|
|
|
+ }
|
|
|
+ } catch (UnknownHostException uhe) {
|
|
|
+ LoggerUtils.error(HttpUtils.class,uhe.getMessage());
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
String resultString=null;
|
|
|
try {
|
|
|
- resultString = EntityUtils.toString(response.getEntity());
|
|
|
- } catch (ParseException | IOException e) {
|
|
|
+ if (response != null) {
|
|
|
+ resultString = EntityUtils.toString(response.getEntity());
|
|
|
+ }
|
|
|
+ } catch (ParseException | IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- JSONObject jsonObj = JSONObject.parseObject(resultString);
|
|
|
- return jsonObj;
|
|
|
+ return JSONObject.parseObject(resultString);
|
|
|
}
|
|
|
|
|
|
private static String ParamMap(Map<String, Object> map) {
|