List of usage examples for java.lang String toString
public String toString()
From source file:info.bonjean.beluga.util.HTTPUtil.java
private static String jsonRequest(String urlStr, String data) throws CommunicationException { try {// w w w. j av a 2s . c o m StringEntity json = new StringEntity(data.toString()); json.setContentType("application/json"); HttpPost post = new HttpPost(urlStr); post.addHeader("Content-Type", "application/json"); post.setEntity(json); return BelugaHTTPClient.getInstance().requestPost(post); } catch (Exception e) { throw new CommunicationException("communicationProblem", e); } }
From source file:cern.c2mon.shared.rule.MultipleReturnValueRuleExpression.java
/** * @return True if the rule is a {@link MultipleReturnValueRuleExpression} * @see http://issues/browse/TIMS-839/*from w ww . ja v a 2 s. c om*/ * * @param rule the rule to be checked */ public static boolean isMultipleReturnValueExpression(final String rule) { final int bracketsCount = StringUtils.countMatches(rule.toString(), "["); return bracketsCount > 1; }
From source file:com.phonty.improved.Balance.java
private static String Parse(String response) { String value = ""; try {// w w w.j a va 2s .c o m JSONObject jsonObject = new JSONObject(response.toString()); value = jsonObject.getString("balance"); } catch (Exception e) { e.printStackTrace(); } return value; }
From source file:com.daveayan.rjson.utils.RjsonUtil.java
public static String reformat(String inputJson) { String outputJson = new String(inputJson); try {// ww w . j av a 2 s . c o m JSONObject jo = new JSONObject(inputJson.toString()); outputJson = jo.toString(2); } catch (JSONException e) { } return outputJson; }
From source file:com.phonty.improved.DirectionCost.java
private static String Parse(String response) { String value = ""; try {/* www . ja v a 2 s . c om*/ JSONObject jsonObject = new JSONObject(response.toString()); value = jsonObject.getString("amount") + " "; value += jsonObject.getString("provider"); value += "(" + jsonObject.getString("country") + ")"; } catch (Exception e) { e.printStackTrace(); } return value; }
From source file:Main.java
public static String initializeService(String data, String serviceName, String serviceUrl) { Log.d("EliademyUtils", "initializeService"); try {/*from w ww . ja va2 s. c o m*/ JSONObject jsObj = new JSONObject(data.toString()); DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(serviceUrl + "/login/token.php"); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("username", jsObj.get("username").toString())); nameValuePairs.add(new BasicNameValuePair("password", jsObj.get("password").toString())); nameValuePairs.add(new BasicNameValuePair("service", serviceName)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); if (entity != null) { StringBuilder jsonStr = new StringBuilder(); InputStream iStream = entity.getContent(); BufferedReader bufferReader = new BufferedReader(new InputStreamReader(iStream)); String jpart; while ((jpart = bufferReader.readLine()) != null) { jsonStr.append(jpart); } iStream.close(); Log.d("Moodle", jsonStr.toString()); JSONObject jsonObj = new JSONObject(jsonStr.toString()); return (String) jsonObj.get("token"); } } catch (Exception e) { Log.e("EliademyUtils", "exception", e); return null; } return null; }
From source file:Main.java
public static <T extends Object> T unmarshalFromString(Class clz, String input) throws JAXBException { JAXBContext context = JAXBContext.newInstance(clz); Unmarshaller unmarshaller = context.createUnmarshaller(); T unobj = (T) unmarshaller.unmarshal(new StreamSource(new StringReader(input.toString()))); return unobj; }
From source file:Main.java
public static void writeOutAttributesForNode(String[][] attributes, Node node) { if (attributes != null) { // Add attributes for (int n = 0; n < attributes.length; n++) { String key = attributes[n][0]; String value = attributes[n][1]; if ((key != null) && (value != null)) { Attr attNode = node.getOwnerDocument().createAttribute(key.toString()); attNode.setNodeValue(value.toString()); node.getAttributes().setNamedItem(attNode); }// ww w. jav a2 s.c o m } } }
From source file:org.wso2.developerstudio.appfactory.core.client.RssClient.java
public static String getDBinfo(String operation, String dsBaseUrl) { String url = dsBaseUrl + "NDataSourceAdmin"; DefaultHttpClient client = new DefaultHttpClient(); client = (DefaultHttpClient) HttpsJaggeryClient.wrapClient(client, url); client.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(Authenticator.getInstance().getCredentials().getUser(), Authenticator.getInstance().getCredentials().getPassword())); // Generate BASIC scheme object and stick it to the execution context BasicScheme basicAuth = new BasicScheme(); BasicHttpContext context = new BasicHttpContext(); context.setAttribute("preemptive-auth", basicAuth); client.addRequestInterceptor(new PreemptiveAuth(), 0); HttpPost post = new HttpPost(url); String sopactionValue = "urn:" + operation; post.addHeader("SOAPAction", sopactionValue); String body = createPayLoad(operation); try {/*from www.j a v a 2s .c o m*/ StringEntity entity = new StringEntity(body.toString(), "text/xml", HTTP.DEFAULT_CONTENT_CHARSET); post.setEntity(entity); HttpResponse response = client.execute(post); if (200 == response.getStatusLine().getStatusCode()) { HttpEntity entityGetAppsOfUser = response.getEntity(); BufferedReader rd = new BufferedReader(new InputStreamReader(entityGetAppsOfUser.getContent())); StringBuilder sb = new StringBuilder(); String line = ""; while ((line = rd.readLine()) != null) { sb.append(line); } String respond = sb.toString(); EntityUtils.consume(entityGetAppsOfUser); return respond; } } catch (Exception e) { // log.error("Jenkins Client err", e); } return null; }
From source file:com.iti.request.NearbyService.java
public static List<Address> getNearby(String x, String y, String r, String type) throws IOException { String url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?v=3&location="; url = url.concat(x);/* www.j ava 2s. co m*/ url = url.concat("%2C"); url = url.concat(y); url = url.concat("&radius="); url = url.concat(r); url = url.concat("&types="); url = url.concat(type); url = url.concat("&key=AIzaSyAmsScw_ynzyQf32_KSGjbGiej7VN2rL7g"); String result = httpGet(url); Object obj = JSONValue.parse(result.toString()); JSONObject jsonObj = (JSONObject) obj; JSONArray resultsArray = (JSONArray) jsonObj.get("results"); Iterator i = resultsArray.iterator(); ArrayList<Address> addresses = new ArrayList<Address>(); while (i.hasNext()) { JSONObject jsonResult = (JSONObject) i.next(); String name = (String) jsonResult.get("name"); String vicinity = (String) jsonResult.get("vicinity"); System.out.println(name); Address address = new Address(); address.setName(name); address.setVicinity(vicinity); addresses.add(address); } return addresses; }