//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
// package com.thc.rcm.common.service; import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.Feature;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.thc.rcm.common.dto.ThcResponse;
import com.thc.rcm.common.interceptor.SessionUtil;
import com.thc.rcm.common.utils.DateUtils;
import com.thc.rcm.common.utils.JsonUtil;
import com.thc.rcm.common.utils.LogUtils;
import com.thc.rcm.common.utils.JsonUtil.JsonObject;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.http.NameValuePair;
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.client.utils.URIBuilder;
import org.apache.http.cookie.Cookie;
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.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.bytesoft.bytetcc.supports.radicate.rpc.RpcResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; @Service
@Lazy(false)
public class HttpService {
private static final Gson gson = (new GsonBuilder()).setDateFormat("yyyy-MM-dd HH:mm:ss").create();
@Autowired
private CloseableHttpClient httpClient;
@Autowired
private RequestConfig requestConfig; public HttpService() {
} public String doGet(String url) throws IOException {
CloseableHttpResponse response = null;
HttpGet httpGet = new HttpGet(url);
httpGet.setConfig(this.requestConfig);
httpGet.addHeader("x-access-token", SessionUtil.getToken()); try {
response = this.httpClient.execute(httpGet);
if (response.getStatusLine().getStatusCode() == 200) {
String var4 = EntityUtils.toString(response.getEntity(), "UTF-8");
return var4;
} LogUtils.printfCallback().info("url>" + url + "return" + response);
} finally {
if (response != null) {
response.close();
} } return null;
} public String doGet(String url, String token) throws IOException {
CloseableHttpResponse response = null;
HttpGet httpGet = new HttpGet(url);
httpGet.setConfig(this.requestConfig);
httpGet.addHeader("x-access-token", token); try {
response = this.httpClient.execute(httpGet);
if (response.getStatusLine().getStatusCode() == 200) {
String var5 = EntityUtils.toString(response.getEntity(), "UTF-8");
return var5;
} LogUtils.printfCallback().info("url>" + url + "return" + response);
} finally {
if (response != null) {
response.close();
} } return null;
} public JsonObject getJson(String url, String token) throws IOException {
String s = this.doGet(url, token);
return JsonUtil.stringTojson(s);
} public JsonObject getJson(String url) throws IOException {
String s = this.doGet(url);
return JsonUtil.stringTojson(s);
} public JsonObject getJson(String url, Map<String, Object> paramMap) throws IOException {
String s = null; try {
s = this.doGet(url, paramMap);
} catch (URISyntaxException var5) {
var5.printStackTrace();
} return JsonUtil.stringTojson(s);
} public String doGet(String url, Map<String, Object> paramMap) throws IOException, URISyntaxException {
URIBuilder builder = new URIBuilder(url);
Iterator var4 = paramMap.keySet().iterator(); while(var4.hasNext()) {
String s = (String)var4.next();
builder.addParameter(s, paramMap.get(s).toString());
} return this.doGet(builder.build().toString());
} public JsonObject getKdSession(String url, String login) throws IOException {
HttpPost httpPost = new HttpPost(url);
httpPost.setConfig(this.requestConfig);
String sessionid = null;
if (login != null) {
StringEntity stringEntity = new StringEntity(login, ContentType.APPLICATION_JSON);
httpPost.setEntity(stringEntity);
} CloseableHttpResponse response = null; HttpResult res;
try {
CookieStore cookieStore = new BasicCookieStore();
this.httpClient = HttpClients.custom().setDefaultCookieStore(cookieStore).build();
response = this.httpClient.execute(httpPost);
List<Cookie> cs = cookieStore.getCookies();
int i = 0; while(true) {
if (i < cs.size()) {
if (!((Cookie)cs.get(i)).getName().equals("kdservice-sessionid")) {
++i;
continue;
} sessionid = ((Cookie)cs.get(i)).getValue();
} res = new HttpResult(response.getStatusLine().getStatusCode(), EntityUtils.toString(response.getEntity(), "UTF-8"));
break;
}
} finally {
if (response != null) {
response.close();
} } JsonObject resJson = JsonUtil.stringTojson(res.getData());
resJson.put("kdservice-sessionid", sessionid);
return resJson;
} public String doKdPost(String url, String json, String session) throws IOException {
HttpPost httpPost = new HttpPost(url);
httpPost.setConfig(this.requestConfig);
httpPost.addHeader("kdservice-sessionid", session);
if (json != null) {
StringEntity stringEntity = new StringEntity(json, ContentType.APPLICATION_JSON);
httpPost.setEntity(stringEntity);
} CloseableHttpResponse response = null; HttpResult res;
try {
response = this.httpClient.execute(httpPost);
res = new HttpResult(response.getStatusLine().getStatusCode(), EntityUtils.toString(response.getEntity(), "UTF-8"));
} finally {
if (response != null) {
response.close();
} } return res.getData();
} public HttpResult doPost(String url, Map<String, String> paramMap) throws IOException {
HttpPost httpPost = new HttpPost(url);
httpPost.setConfig(this.requestConfig);
httpPost.addHeader("x-access-token", SessionUtil.getToken());
if (paramMap != null) {
List<NameValuePair> parameters = new ArrayList();
Iterator var5 = paramMap.keySet().iterator(); while(var5.hasNext()) {
String s = (String)var5.next();
parameters.add(new BasicNameValuePair(s, (String)paramMap.get(s)));
} UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(parameters, Charset.forName("UTF-8"));
httpPost.setEntity(formEntity);
} CloseableHttpResponse response = null; HttpResult var11;
try {
response = this.httpClient.execute(httpPost);
LogUtils.printfCallback().info("url>" + url + "param>" + paramMap + "return>" + response);
var11 = new HttpResult(response.getStatusLine().getStatusCode(), EntityUtils.toString(response.getEntity()));
} finally {
if (response != null) {
response.close();
} } return var11;
} public HttpResult doPost(String url) throws IOException {
return this.doPost(url, (Map)null);
} public JsonObject postResult(String url) throws IOException {
String s = this.doPost(url).getData();
return JsonUtil.stringTojson(s);
} public JsonObject postResult(String url, String json) throws IOException {
long beginTime = System.currentTimeMillis();
String s = null;
s = this.doPostJson(url, json).getData();
long endTime = System.currentTimeMillis();
LogUtils.commonLog().info("请求工程耗时: {} URI:{}", DateUtils.formatDateTime(endTime - beginTime), url);
return s != null && !s.equals("") ? JsonUtil.stringTojson(s) : new JsonObject();
} public JsonObject postResult(String url, String json, String session) throws IOException {
String s = null;
s = this.doPostJson(url, json, session).getData();
return s != null && !s.equals("") ? JsonUtil.stringTojson(s) : new JsonObject();
} public RpcResult postRpcResult(String url, String json) throws IOException {
String s = null;
RpcResult result = new RpcResult();
s = this.doPostJson(url, json).getData();
if (s != null && !s.equals("")) {
result.setValue(s);
return result;
} else {
return result;
}
} public HttpResult doPostJson(String url, String json) throws IOException {
HttpPost httpPost = new HttpPost(url);
httpPost.setConfig(this.requestConfig);
httpPost.addHeader("x-access-token", SessionUtil.getToken());
httpPost.addHeader("Content-Type", "application/json");
if (json != null) {
StringEntity stringEntity = new StringEntity(json, ContentType.APPLICATION_JSON);
httpPost.setEntity(stringEntity);
} CloseableHttpResponse response = null; HttpResult res;
try {
response = this.httpClient.execute(httpPost);
LogUtils.printfCallback().info("url>" + url + "param>" + json + "return>" + response);
res = new HttpResult(response.getStatusLine().getStatusCode(), EntityUtils.toString(response.getEntity(), "UTF-8"));
} finally {
if (response != null) {
response.close();
} } return res;
} public HttpResult doPostJson(String url, String json, String session) throws IOException {
HttpPost httpPost = new HttpPost(url);
httpPost.setConfig(this.requestConfig);
if (session != null) {
httpPost.addHeader("x-access-token", session);
} if (json != null) {
StringEntity stringEntity = new StringEntity(json, ContentType.APPLICATION_JSON);
httpPost.setEntity(stringEntity);
} CloseableHttpResponse response = null; HttpResult var6;
try {
response = this.httpClient.execute(httpPost);
LogUtils.printfCallback().info("url>" + url + "param>" + json + "return>" + response);
var6 = new HttpResult(response.getStatusLine().getStatusCode(), EntityUtils.toString(response.getEntity(), "UTF-8"));
} finally {
if (response != null) {
response.close();
} } return var6;
} public <T> T doPostJson(String url, Object entity, String token, TypeReference<T> type) {
HttpPost httpPost = new HttpPost(url);
httpPost.setConfig(this.requestConfig);
String requestJson = null;
if (token != null) {
httpPost.addHeader("x-access-token", token);
} if (entity != null) {
requestJson = gson.toJson(entity);
StringEntity stringEntity = new StringEntity(requestJson, ContentType.APPLICATION_JSON);
httpPost.setEntity(stringEntity);
} CloseableHttpResponse response = null; Object var9;
try {
response = this.httpClient.execute(httpPost);
if (response.getStatusLine().getStatusCode() != 200) {
throw new RuntimeException(String.format("request url:%s with requestBody %s get response %s", url, requestJson, response));
} ThcResponse<T> thcResponse = (ThcResponse)JSON.parseObject(EntityUtils.toString(response.getEntity(), "UTF-8"), new TypeReference<ThcResponse<T>>() {
}, new Feature[0]);
var9 = JSON.parseObject(JSONUtils.toJSONString(thcResponse.getSuccessData()), type, new Feature[0]);
} catch (IOException var18) {
throw new RuntimeException(String.format("request url:%s with request body %s", url, requestJson), var18);
} finally {
if (response != null) {
try {
response.close();
} catch (IOException var17) {
var17.printStackTrace();
}
} } return var9;
}
}

  

HttpService的更多相关文章

  1. Flex HTTPService json

    import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; import mx.rpc.http.HTTPService; i ...

  2. osgi: HttpService A null service reference is not allowed.

    最近在学习osgi,在练习HttpService的过程中,一直出现“A null service reference is not allowed”这样的报错,代码本身没有问题,在网上也搜了不少地方, ...

  3. Flex httpservice返回值类型和处理 (转)

    这两天在考虑flex与后端java服务交互的问题.在采用BlazeDS的Remote Object方式,还是传统的http service方式之间徘徊了一段时间 采用BlazeDS的Remote Ob ...

  4. Flex之HTTPService组件调用

    1.采用<s:HTTPService>标签来实现: <?xml version="1.0" encoding="utf-8"?>< ...

  5. 基于Flex的HTTPService(GET和POST)

    一.基于GET的HTTPService: <?xml version="1.0" encoding="utf-8"?><mx:Applicat ...

  6. HttpService与WebService的差异

    httpservice通过post和get得到你想要的东西webservice就是使用soap协议得到你想要的东西,相比httpservice能处理些更加复杂的数据类型 当你要调用一个你本服务的内容的 ...

  7. Flex远程访问获取数据--HTTPService

    编写service类: package services { import com.adobe.serialization.json.JSON; import log.LogUtil; import ...

  8. Felx之HTTPService

    获取并显示数据 为了向我们的程序提供数据,Adobe Flex包含特别为与HTTP服务器,网络服务或者是远程对象服务(Java对象)进行交互的而设计的组件.这些组件被称之为远程过程调用(RPC)服务组 ...

  9. Flex与Java通信之HttpService

    flashbuilder4.6.myeclipse10 参考:http://www.cnblogs.com/lovemoon714/archive/2012/05/25/2517684.html 1. ...

随机推荐

  1. THUSC2017题解

    THUSC2017题解 题目都是在LOJ上交的. chocolate LOJ#2977巧克力 这题看着就让人想起了百度之星复赛的\(T5\),就是这题. 因为种类的个数很多,所以把每个种类随意\(ra ...

  2. [luogu2503][HAOI2006]均分数据【模拟退火】

    题目描述 已知N个正整数:A1.A2.--.An .今要将它们分成M组,使得各组数据的数值和最平均,即各组的均方差最小.均方差公式如下: 分析 模拟退火学习笔记:https://www.cnblogs ...

  3. [luogu5253]丢番图【数学】

    传送门 [传送门] 题目大意 求\(\frac{1}{x}+\frac{1}{y}=\frac{1}{n}\)有多少组不同的解. 分析 将式子转化成\((n-x)(n-y)=n^2\)的形式. 那么很 ...

  4. rt-thread之stm32系列BSP制作方法

    @2019-01-24 [小记] bsp制作方法: 官网下载 rt-thread 源码,将路径 bsp/stm32/libraries/templates/ 下的模板文件,Copy至路径 bsp/st ...

  5. 【map】p1184 高手之在一起

    题目背景 高手是可以复活的,这点我们大家都知道. 题目描述 高手列出了一个详尽的日程表,这次他要追求的则是一个心灵纯洁的小萝莉.他和她都是要上课的,但是也会有时间空闲,于是高手决定无时无刻都要跟着她. ...

  6. python服务器文件上传下载+GUI【tkinter】

    大概就是一个通过应用程序来和服务器打交道的这么一个,小东西 1.GUI 用的是tkinter # -*- coding: UTF-8 -*- from tkinter import * import ...

  7. CodeFroces-- 511div2 C. Enlarge GCD

    题目链接:C. Enlarge GCD 给你一个序列 删除一些数看可以让他们之间的gcd变大如果可以输出删除数量最小的个数 先求出共同 gcd 然后除去 找出出现最多的质数 然后减去就可以了 #inc ...

  8. Sublime使用小记

    Jason转换插件: 多行编辑快捷键:Ctrl A全选,再按下 Ctrl Shift L (Command Shift L) 即可同时编辑这些行:鼠标选中文本,反复按 CTRL D (Command ...

  9. C语言进阶--DAY3

    主要讲解数组和指针有关问题 1. 数组名的本质是一个常量指针 2. 内存编址的最小单位是字节,对于变量来说,一个变量可以取1.2.4.8等字节,对变量取地址来说,取的是低位字节的地址,在32位机中其对 ...

  10. Gym 101911E "Painting the Fence"(线段树区间更新+双端队列)

    传送门 题意: 庭院中有 n 个围栏,每个围栏上都被涂上了不同的颜色(数字表示): 有 m 条指令,每条指令给出一个整数 x ,你要做的就是将区间[ x第一次出现的位置 , x最后出现的位置 ]中的围 ...