public void updateGraph(String type, JSONObject node) {
JSONObject jsonObj = new JSONObject();
jsonObj.put(type, node);
//System.out.println(jsonObj.toString());
try {
HttpResponse<String> response = Unirest.post(url + "?operation=updateGraph")
.header("content-type", "application/json")
.header("cache-control", "no-cache")
.body(jsonObj.toString())
.asString();
Integer i = 0;
if (type.equals("ae")) {
this.ECount++;
i = this.ECount;
}
if (type.equals("an")) {
this.VCount++;
i = this.VCount;
}
System.out.println(i + " " + response.getStatus() + " " + response.getStatusText() + " " + response.getBody());
} catch(UnirestException e) {
e.printStackTrace();
}
}
java类com.mashape.unirest.http.Unirest的实例源码
Gephi.java 文件源码
项目:exportJanusGraphToGephi
阅读 21
收藏 0
点赞 0
评论 0
SeRepoTestServerTest.java 文件源码
项目:eadlsync
阅读 20
收藏 0
点赞 0
评论 0
@Test
public void testIsTestRepositoryAvailable() throws IOException, UnirestException {
HttpResponse<RepositoryContainer> response = Unirest.get(seRepoTestServer.LOCALHOST_REPOS)
.asObject(RepositoryContainer.class);
RepositoryContainer repos = response.getBody();
assertTrue(repos.getRepositories().stream().map(Repository::getName).collect(Collectors.toList
()).contains(TestDataProvider.TEST_REPO));
}
HttpClient.java 文件源码
项目:Warzone
阅读 36
收藏 0
点赞 0
评论 0
@Override
public UserProfile login(PlayerLogin playerLogin) {
try {
HttpResponse<UserProfile> userProfileResponse = Unirest.post(config.getBaseUrl() + "/mc/player/login")
.header("x-access-token", config.getAuthToken())
.header("accept", "application/json")
.header("Content-Type", "application/json")
.body(playerLogin)
.asObject(UserProfile.class);
return userProfileResponse.getBody();
} catch (UnirestException e) {
e.printStackTrace();
return null;
}
}
HttpClient.java 文件源码
项目:Warzone
阅读 29
收藏 0
点赞 0
评论 0
@Override
public MapLoadResponse loadmap(Map map) {
try {
HttpResponse<MapLoadResponse> mapLoadResponse = Unirest.post(config.getBaseUrl() + "/mc/map/load")
.header("x-access-token", config.getAuthToken())
.header("accept", "application/json")
.header("Content-Type", "application/json")
.body(map)
.asObject(MapLoadResponse.class);
return mapLoadResponse.getBody();
} catch (UnirestException e) {
e.printStackTrace();
return null;
}
}
HttpClient.java 文件源码
项目:Warzone
阅读 24
收藏 0
点赞 0
评论 0
@Override
public void addKill(Death death) {
try {
HttpResponse<JsonNode> jsonResponse = Unirest.post(config.getBaseUrl() + "/mc/death/new")
.header("x-access-token", config.getAuthToken())
.header("accept", "application/json")
.header("Content-Type", "application/json")
.body(death)
.asJson();
} catch (UnirestException e) {
e.printStackTrace();
}
}
HttpClient.java 文件源码
项目:Warzone
阅读 25
收藏 0
点赞 0
评论 0
@Override
public void finishMatch(MatchFinishPacket matchFinishPacket) {
try {
HttpResponse<JsonNode> jsonResponse = Unirest.post(config.getBaseUrl() + "/mc/match/finish")
.header("x-access-token", config.getAuthToken())
.header("accept", "application/json")
.header("Content-Type", "application/json")
.body(matchFinishPacket)
.asJson();
} catch (UnirestException e) {
e.printStackTrace();
}
}
ChallengeServerClient.java 文件源码
项目:tdl-runner-scala
阅读 20
收藏 0
点赞 0
评论 0
String sendAction(String action) throws
ClientErrorException, ServerErrorException, OtherCommunicationException {
try {
String encodedPath = URLEncoder.encode(this.journeyId, "UTF-8");
String url = String.format("http://%s:%d/action/%s/%s", this.url, port, action, encodedPath);
HttpResponse<String> response = Unirest.post(url)
.header("Accept", this.acceptHeader)
.header("Accept-Charset", "UTF-8")
.asString();
ensureStatusOk(response);
return response.getBody();
} catch (UnirestException | UnsupportedEncodingException e ) {
throw new OtherCommunicationException("Could not perform POST request",e);
}
}
GitHubAPIHttpClient.java 文件源码
项目:kafka-connect-github-source
阅读 23
收藏 0
点赞 0
评论 0
protected HttpResponse<JsonNode> getNextIssuesAPI(Integer page, Instant since) throws UnirestException {
GetRequest unirest = Unirest.get(constructUrl(page, since));
if (!config.getAuthUsername().isEmpty() && !config.getAuthPassword().isEmpty() ){
unirest = unirest.basicAuth(config.getAuthUsername(), config.getAuthPassword());
}
log.debug(String.format("GET %s", unirest.getUrl()));
return unirest.asJson();
}
SystemServiceImpl.java 文件源码
项目:minsx-framework
阅读 27
收藏 0
点赞 0
评论 0
/**
* 该方法用于后台取Token
*/
public Map<String, Object> getToken(HttpServletRequest request) {
Map<String, Object> result = new HashMap<String, Object>();
result.put("isSuccess", false);
String username = request.getParameter("username");
String password = request.getParameter("password");
String accessId = request.getParameter("accessId");
String accessSecret = request.getParameter("accessSecret");
if (username == null || password == null) {
username = accessId;
password = accessSecret;
}
if (username == null || password == null) {
result.put("reason", "Parameter Error");
return result;
}
HttpResponse<String> response;
try {
String url = "http://localhost:8080/loginServer/oauth/token?grant_type=password&username=%s&password=%s";
response = Unirest.post(String.format(url, username, password))
.header("authorization", "Basic Z29vZHNhdmU6Z29vZHNhdmU=")
.header("cache-control", "no-cache")
.asString();
if (response.getStatus() >= 200 && response.getStatus() < 400) {
result.put("isSuccess", true);
result.put("access_token", JSON.parseObject(response.getBody()).get("access_token"));
result.put("token_type", JSON.parseObject(response.getBody()).get("token_type"));
result.put("refresh_token", JSON.parseObject(response.getBody()).get("refresh_token"));
result.put("expires_in", JSON.parseObject(response.getBody()).get("expires_in"));
result.put("scope", JSON.parseObject(response.getBody()).get("scope"));
} else {
result.put("reason", "username or password failed");
}
} catch (UnirestException e) {
e.printStackTrace();
result.put("isSuccess", false);
result.put("reason", "inner error");
}
return result;
}
ChromaClient.java 文件源码
项目:RazerChromaRESTClient
阅读 21
收藏 0
点赞 0
评论 0
/**
* Un-initializes this client
*
* @return {@link Result}
* @throws UnirestException
*/
public Result unInit() throws UnirestException {
checkInitialized();
HttpResponse<ResponseResult> response = Unirest
.delete(this.session.getUri())
.asObject(ResponseResult.class);
this.session = null;
this.heartbeatThread = null;
return Result.forCode(response.getBody().getResult());
}