use of org.json.simple.JSONObject in project tdi-studio-se by Talend.
the class OAuthClient method getTokenForWizard.
public Token getTokenForWizard(String code) throws Exception {
Token token = new Token();
URL callback_url = new URL("https", callbackHost, callbackPort, "");
String oauth2_authorize_url = baseOAuthURL.endsWith("/") ? baseOAuthURL + OAUTH2_AUTHORIZE : baseOAuthURL + "/" + OAUTH2_AUTHORIZE;
String authorize_url = // &scope=%s
String.format(// &scope=%s
"%s?response_type=%s&client_id=%s&redirect_uri=%s", // &scope=%s
oauth2_authorize_url, "code", clientID, // , "full%20refresh_token"
URLEncoder.encode(callback_url.toString(), UTF8));
String token_url = baseOAuthURL.endsWith("/") ? baseOAuthURL + OAUTH2_TOKEN : baseOAuthURL + "/" + OAUTH2_TOKEN;
URLConnection conn = new URL(token_url).openConnection();
// post
conn.setDoOutput(true);
String query = String.format("grant_type=%s&client_id=%s&client_secret=%s&redirect_uri=%s&code=%s", "authorization_code", clientID, clientSecret, URLEncoder.encode(callback_url.toString(), UTF8), code);
OutputStream output = null;
try {
output = conn.getOutputStream();
output.write(query.getBytes(UTF8));
} finally {
if (output != null) {
try {
output.close();
} catch (IOException ignore) {
}
}
}
InputStream input = conn.getInputStream();
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(input));
JSONParser jsonParser = new JSONParser();
JSONObject json = (JSONObject) jsonParser.parse(reader);
if (json.get("access_token") != null) {
token.setAccess_token(json.get("access_token").toString());
}
if (json.get("refresh_token") != null) {
token.setRefresh_token(json.get("refresh_token").toString());
}
if (json.get("instance_url") != null) {
token.setInstance_url(json.get("instance_url").toString());
}
if (json.get("id") != null) {
token.setId(json.get("id").toString());
}
if (json.get("issued_at") != null) {
token.setIssued_at(Long.parseLong(json.get("issued_at").toString()));
}
if (json.get("signature") != null) {
token.setSignature(json.get("signature").toString());
}
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ignore) {
}
}
}
return token;
}
use of org.json.simple.JSONObject in project tdi-studio-se by Talend.
the class OAuthClient method getSOAPEndpoint.
public static String getSOAPEndpoint(Token token, String version) throws MalformedURLException, IOException, ParseException {
URLConnection idConn = new URL(token.getId()).openConnection();
idConn.setRequestProperty("Authorization", "Bearer " + token.getAccess_token());
String endpointURL = null;
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(idConn.getInputStream()));
JSONParser jsonParser = new JSONParser();
JSONObject json = (JSONObject) jsonParser.parse(reader);
JSONObject urls = (JSONObject) json.get("urls");
endpointURL = urls.get("partner").toString().replace("{version}", version);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ignore) {
}
}
}
return endpointURL;
}
use of org.json.simple.JSONObject in project TotalFreedomMod by TotalFreedom.
the class Module_players method getResponse.
@Override
@SuppressWarnings("unchecked")
public NanoHTTPD.Response getResponse() {
final JSONObject responseObject = new JSONObject();
final JSONArray players = new JSONArray();
final JSONArray superadmins = new JSONArray();
final JSONArray telnetadmins = new JSONArray();
final JSONArray senioradmins = new JSONArray();
final JSONArray developers = new JSONArray();
// All online players
for (Player player : Bukkit.getOnlinePlayers()) {
players.add(player.getName());
}
// Admins
for (Admin admin : plugin.al.getActiveAdmins()) {
final String username = admin.getName();
switch(admin.getRank()) {
case SUPER_ADMIN:
superadmins.add(username);
break;
case TELNET_ADMIN:
telnetadmins.add(username);
break;
case SENIOR_ADMIN:
senioradmins.add(username);
break;
}
}
// Developers
developers.addAll(FUtil.DEVELOPERS);
responseObject.put("players", players);
responseObject.put("superadmins", superadmins);
responseObject.put("telnetadmins", telnetadmins);
responseObject.put("senioradmins", senioradmins);
responseObject.put("developers", developers);
final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_JSON, responseObject.toString());
response.addHeader("Access-Control-Allow-Origin", "*");
return response;
}
use of org.json.simple.JSONObject in project spatial-portal by AtlasOfLivingAustralia.
the class ProgressController method get.
JSONObject get() {
try {
StringBuilder sbProcessUrl = new StringBuilder();
sbProcessUrl.append(CommonData.getSatServer()).append("/ws/job?pid=").append(pid);
LOGGER.debug("checking status every '" + timer.getDelay() + "' sec: " + sbProcessUrl.toString());
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(sbProcessUrl.toString());
get.addRequestHeader(StringConstants.ACCEPT, StringConstants.APPLICATION_JSON);
client.getHttpConnectionManager().getParams().setSoTimeout(timer.getDelay());
int result = client.executeMethod(get);
if (result == 200) {
JSONParser jp = new JSONParser();
return (JSONObject) jp.parse(get.getResponseBodyAsString());
}
} catch (SocketTimeoutException e) {
LOGGER.debug("progress timeout exception, will be trying again.");
} catch (Exception e) {
LOGGER.error("error getting updated job info pid=" + pid, e);
}
return null;
}
use of org.json.simple.JSONObject in project spatial-portal by AtlasOfLivingAustralia.
the class AreaReportController method journalmap.
Map<String, String> journalmap(AreaReportItemDTO model) {
Map<String, String> countData = new HashMap<String, String>();
try {
String area = selectedArea.getWkt();
double lat1 = 0;
double lat2 = 0;
double long1 = 0;
double long2 = 0;
if (area.contains(StringConstants.ENVELOPE) && selectedArea.getMapLayer() != null) {
// use boundingbox
List<Double> bbox = selectedArea.getMapLayer().getMapLayerMetadata().getBbox();
long1 = bbox.get(0);
lat1 = bbox.get(1);
long2 = bbox.get(2);
lat2 = bbox.get(3);
area = "POLYGON((" + long1 + " " + lat1 + "," + long1 + " " + lat2 + "," + long2 + " " + lat2 + "," + long2 + " " + lat1 + "," + long1 + " " + lat1 + "))";
}
List<JSONObject> list = CommonData.filterJournalMapArticles(area);
String journalmapUrl = CommonData.getSettings().getProperty("journalmap.url", null);
StringBuilder sb = new StringBuilder();
sb.append("<ol>");
for (int i = 0; i < list.size(); i++) {
JSONObject o = list.get(i);
sb.append("<li>");
sb.append("<a href=\"").append(journalmapUrl + "articles/" + o.get("id").toString()).append("\" ");
sb.append("target=\"_blank\">");
sb.append(o.get("title"));
sb.append("</li>");
}
sb.append("</ol>");
if (!list.isEmpty()) {
journalmapHtml = sb.toString();
}
countData.put(StringConstants.JOURNAL_MAP, String.valueOf(list.size()));
model.setCount(Integer.toString(list.size()));
if (!list.isEmpty()) {
model.setExtraInfo(new ExtraInfoEnum[] { ExtraInfoEnum.LIST });
model.setListType(ListType.JOURNAL_MAP);
model.addUrlDetails("JournalMap", "https://www.journalmap.org/");
}
} catch (Exception e) {
LOGGER.error("unable to get area info from journalmap", e);
countData.put(StringConstants.JOURNAL_MAP, "unavailable");
model.setCount("Unavailable");
}
return countData;
}
Aggregations