use of cn.hutool.http.HttpRequest in project xiushang-boot by shijingsh.
the class OceanEngineResource method request.
public static String request(HttpMethod httpMethod, String apiUrl, String payLoad, String token) throws OceanEngineRestException {
try {
JSONObject jsonObject = JSONObject.parseObject(payLoad);
Method method = Method.GET;
if (httpMethod == HttpMethod.POST) {
method = Method.POST;
}
HttpRequest request = HttpUtil.createRequest(method, apiUrl).contentType("application/json").header("Api-Version", "0.1").header("User-Agent", "OceanEngine Marketing-api Java SDK");
if (StringUtils.isNotBlank(token)) {
request.header("Access-Token", token);
}
String responseString = // 表单内容
request.form(jsonObject).timeout(// 超时,毫秒
20000).execute().body();
;
return responseString;
} catch (Exception e) {
throw new OceanEngineRestException("api request io error, url=" + apiUrl, e);
}
}
use of cn.hutool.http.HttpRequest in project Jpom by dromara.
the class AgentExtConfigBean method createServerRequest.
/**
* 创建请求对象
*
* @param openApi url
* @return HttpRequest
* @see ServerOpenApi
*/
public HttpRequest createServerRequest(String openApi) {
if (StrUtil.isEmpty(getServerUrl())) {
throw new JpomRuntimeException("请先配置server端url");
}
if (StrUtil.isEmpty(getServerToken())) {
throw new JpomRuntimeException("请先配置server端Token");
}
// 加密
String md5 = SecureUtil.md5(getServerToken());
md5 = SecureUtil.sha1(md5 + ServerOpenApi.HEAD);
HttpRequest httpRequest = HttpUtil.createPost(String.format("%s%s", serverUrl, openApi));
httpRequest.header(ServerOpenApi.HEAD, md5);
return httpRequest;
}
use of cn.hutool.http.HttpRequest in project Jpom by dromara.
the class TomcatManageService method tomcatCmd.
/**
* 访问tomcat Url
*
* @param tomcatInfoModel tomcat信息
* @param cmd 命令
* @return 访问结果
*/
private String tomcatCmd(TomcatInfoModel tomcatInfoModel, String cmd) {
String url = String.format("http://127.0.0.1:%d/jpomAgent/%s", tomcatInfoModel.getPort(), cmd);
HttpRequest httpRequest = new HttpRequest(url);
// 设置超时时间为3秒
httpRequest.setConnectionTimeout(3000);
String body = "";
try {
HttpResponse httpResponse = httpRequest.execute();
if (httpResponse.isOk()) {
body = httpResponse.body();
}
if (httpResponse.getStatus() == HttpStatus.HTTP_NOT_FOUND) {
// 没有插件
tomcatInfoModel.initTomcat();
throw new JpomRuntimeException("tomcat 未初始化,已经重新初始化请稍后再试");
}
} catch (JpomRuntimeException jpom) {
throw jpom;
} catch (Exception ignored) {
}
return body;
}
use of cn.hutool.http.HttpRequest in project Jpom by dromara.
the class TomcatManageService method getTomcatStatus.
/**
* 查询tomcat状态
*
* @param id tomcat的id
* @return tomcat状态0表示未运行,1表示运行中
*/
public int getTomcatStatus(String id) {
int result = 0;
TomcatInfoModel tomcatInfoModel = tomcatEditService.getItem(id);
String url = String.format("http://127.0.0.1:%d/", tomcatInfoModel.getPort());
HttpRequest httpRequest = new HttpRequest(url);
// 设置超时时间为3秒
httpRequest.setConnectionTimeout(3000);
try {
HttpResponse httpResponse = httpRequest.execute();
result = 1;
} catch (Exception ignored) {
}
return result;
}
use of cn.hutool.http.HttpRequest in project Jpom by dromara.
the class RemoteVersion method loadTransitUrl.
/**
* 获取第一层信息,用于中转
*
* @return 中转URL
*/
private static String loadTransitUrl() {
String body = StrUtil.EMPTY;
try {
HttpRequest request = HttpUtil.createGet(URL);
body = request.execute().body();
//
JSONObject jsonObject = JSONObject.parseObject(body);
return jsonObject.getString("url");
} catch (Exception e) {
DefaultSystemLog.getLog().warn("获取远程版本信息失败:{} {}", e.getMessage(), body);
return null;
}
}
Aggregations