@Override
public void onTrigger(ProcessContext processContext, ProcessSession processSession) throws ProcessException {
// Get flowfile
FlowFile flowFile = processSession.get();
if (flowFile == null) {
return;
}
try {
// Get filename of flowFile
String fileName = flowFile.getAttribute(CoreAttributes.FILENAME.key());
// Invoke REST service with filename as parameter (For now parameter is just '1')
String restEndpoint = processContext.getProperty(REST_ENDPOINT).getValue();
JSONObject jsonResult = Unirest.get(restEndpoint)
.header("accept", "application/json")
.asJson()
.getBody()
.getObject();
// Add attributes to flowfile based on REST call
Map<String, String> newAttributes = new HashMap<>();
newAttributes.put(ATT_ACCOUNT_NAME, jsonResult.getString("name"));
newAttributes.put(ATT_ACCOUNT_USERNAME, jsonResult.getString("username"));
FlowFile updatedFlowFile = processSession.putAllAttributes(flowFile, newAttributes);
// Transfer flowfile to success state
processSession.transfer(updatedFlowFile, REL_SUCCESS);
} catch (UnirestException e) {
processSession.transfer(flowFile, REL_FAILURE);
throw new ProcessException(e);
}
}
java类com.mashape.unirest.http.exceptions.UnirestException的实例源码
UpdateAttributeREST.java 文件源码
项目:nifi-dataminded-bundle
阅读 22
收藏 0
点赞 0
评论 0
ChromaClient.java 文件源码
项目:RazerChromaRESTClient
阅读 24
收藏 0
点赞 0
评论 0
/**
* Creates an effect
*
* @param effect the {@link EffectAbstract}
* @return the {@link EffectId} to be used when setting the effect
* @throws UnirestException
*/
public EffectId createEffect(EffectAbstract effect) throws UnirestException {
System.out.println("createEffect POST " + effect.getTarget().getRoute());
System.out.println(new Gson().toJson(effect));
checkInitialized();
HttpResponse<EffectId> response = Unirest
.post(this.session.getUri() + effect.getTarget().getRoute())
.body(effect)
.asObject(EffectId.class);
return response.getBody();
}
SiaUtil.java 文件源码
项目:minebox
阅读 33
收藏 0
点赞 0
评论 0
private HttpResponse<String> siaCommand(SiaCommand command, ImmutableMap<String, Object> params, String... extraCommand) {
try {
final HttpRequest httpRequest = command.unirest(path, extraCommand)
.header("User-Agent", "Sia-Agent")
.queryString(params);
return httpRequest.asString();
} catch (UnirestException e) {
throw new NoConnectException(e);
}
}
Gephi.java 文件源码
项目:exportJanusGraphToGephi
阅读 26
收藏 0
点赞 0
评论 0
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();
}
}
Gephi.java 文件源码
项目:exportJanusGraphToGephi
阅读 23
收藏 0
点赞 0
评论 0
public static void updateGraphTest() {
//System.out.println(jsonObj.toString());
try {
HttpResponse<JsonNode> response = Unirest.post(url + "?operation=updateGraph")
.header("content-type", "application/json")
.header("cache-control", "no-cache")
.body("{\"an\":{\"520248\":{\"id\":520248,\"label\":\"artist\"}}}")
.asJson();
System.out.println(response.getBody());
} catch(UnirestException e) {
e.printStackTrace();
}
}
JPastee.java 文件源码
项目:JPastee
阅读 21
收藏 0
点赞 0
评论 0
/**
* Lists the available syntaxes from the server.
*
* @see <a href="https://pastee.github.io/docs/#list-syntaxes">Pastee Docs: List Syntaxes</a>
* @return the response of the request
*/
public SyntaxesResponse listSyntaxes() {
final String route = "/syntaxes";
try {
return new SyntaxesResponse(get(route).getBody().getObject());
} catch(UnirestException e) {
return new SyntaxesResponse(e);
}
}
PacketHandler.java 文件源码
项目:Pxls
阅读 23
收藏 0
点赞 0
评论 0
private void handleCaptcha(WebSocketChannel channel, User user, ClientCaptcha cc) {
if (!user.isFlaggedForCaptcha()) return;
if (user.isBanned()) return;
Unirest
.post("https://www.google.com/recaptcha/api/siteverify")
.field("secret", App.getConfig().getString("captcha.secret"))
.field("response", cc.getToken())
//.field("remoteip", "null")
.asJsonAsync(new Callback<JsonNode>() {
@Override
public void completed(HttpResponse<JsonNode> response) {
JsonNode body = response.getBody();
String hostname = App.getConfig().getString("host");
boolean success = body.getObject().getBoolean("success") && body.getObject().getString("hostname").equals(hostname);
if (success) {
user.validateCaptcha();
}
server.send(channel, new ServerCaptchaStatus(success));
}
@Override
public void failed(UnirestException e) {
}
@Override
public void cancelled() {
}
});
}
CodeRepo.java 文件源码
项目:eadlsync
阅读 19
收藏 0
点赞 0
评论 0
@Override
public String commit(User user, String message, boolean isForcing) throws EADLSyncException, IOException, UnirestException {
diffManager = initDiff(latestCommitId());
if (!diffManager.hasRemoteDiff() || isForcing) {
if (diffManager.hasLocalDiff()) {
diffManager.applyLocalDiff();
return YStatementSeItemHelper.commitYStatement(user, message, diffManager.getCurrentDecisions(), baseUrl, project);
} else {
throw EADLSyncException.ofState(EADLSyncException.EADLSyncOperationState.SYNCED);
}
} else {
throw EADLSyncException.ofState(EADLSyncException.EADLSyncOperationState.PULL_FIRST);
}
}
JPastee.java 文件源码
项目:JPastee
阅读 18
收藏 0
点赞 0
评论 0
/**
* Submit a paste to the server.
*
* @see <a href="https://pastee.github.io/docs/#submit-a-new-paste">Pastee Docs: Submit a new paste</a>
* @param paste the paste to submit
*
* @return the response of the submit request
*/
public SubmitResponse submit(Paste paste) {
final String route = "/pastes";
JSONObject json = new JSONObject();
json.put("encrypted", paste.isEncrypted());
json.putOpt("description", paste.getDescription());
JSONArray sectionsJson = new JSONArray();
paste.getSections().forEach(section -> {
JSONObject sectionJson = new JSONObject();
sectionJson.putOpt("name", section.getName());
if(section.getSyntax() != null)
sectionJson.putOpt("syntax", section.getSyntax().getShortName());
sectionJson.put("contents", section.getContents());
sectionsJson.put(sectionJson);
});
json.put("sections", sectionsJson);
try {
return new SubmitResponse(post(route, json).getBody().getObject());
} catch(UnirestException e) {
return new SubmitResponse(e);
}
}
CodeRepo.java 文件源码
项目:eadlsync
阅读 19
收藏 0
点赞 0
评论 0
@Override
public String reset(String resetCommitId) throws EADLSyncException, IOException, UnirestException {
diffManager = initDiff(resetCommitId);
diffManager.getLocalDiff().clear();
diffManager.applyRemoteDiff();
writeEadsToDisk();
return resetCommitId;
}