List of usage examples for java.util HashMap toString
public String toString()
From source file:de.fhg.fokus.odp.middleware.unittest.xTestCKANGateway.java
/** * Test the viewMetaDataSets method./*from www. j a v a 2s.co m*/ */ @Test public void testViewMetaDataSets() { // get the meta data sets HashMap<String, HashMap> filteredDataResult = ckanGW.viewDataSets(); log.fine("########## VIEW DATASET #########"); log.fine(filteredDataResult.toString()); assertEquals(true, filteredDataResult.keySet().size() != 0); }
From source file:com.aknowledge.v1.automation.RemoteActivity.java
private void doCommand(String myTag, String command) { final String curCommand = command; final String curTag = myTag; HashMap<String, String> params = new HashMap<String, String>(); params.put("command=", "off"); Log.d("RemoteActivity", "doCommand:" + hostname + "/api/device/" + myTag + " " + params.toString()); JsonObjectRequest req = new JsonObjectRequest(Method.POST, hostname + "/api/device/" + myTag, null, new Response.Listener<JSONObject>() { @Override/* w w w . j a v a 2s . c o m*/ public void onResponse(JSONObject response) { if (dialog != null && dialog.isShowing()) { dialog.dismiss(); } Log.d("RemoteActivity", "doCommand" + response.toString()); for (PytoDevice dev : myDevices) { View myView = remoteFrag.getView().findViewWithTag(curTag); if (dev.getDevID().equalsIgnoreCase(curTag)) { try { String devState = response.getString("state"); dev.setDevState(devState); if (devState.equalsIgnoreCase("on")) { myView.setBackgroundResource(R.drawable.light_bulb_on); } else { if (devState.equalsIgnoreCase("off")) { myView.setBackgroundResource(R.drawable.light_bulb_off); } else { myView.setBackgroundResource(R.drawable.light_bulb_dimmed); } } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } // pDialog.hide(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.d("RemoteActivity", "doCommand Error: " + error.getMessage()); // pDialog.hide(); } }) { @Override public Map<String, String> getHeaders() throws AuthFailureError { HashMap<String, String> headers = new HashMap<String, String>(); String authString = user + ":" + pass; String encodedPass = null; try { encodedPass = Base64.encodeToString(authString.getBytes(), Base64.DEFAULT); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } Log.d("Remote Activity", pass + " " + encodedPass); // headers.put("Content-Type", "application/json"); headers.put("Authorization", "Basic " + encodedPass); return headers; } @Override public byte[] getBody() { // Map<String, String> params = new HashMap<String, String>(); // params.put("command", "on"); // params.put("email", "abc@androidhive.info"); // params.put("password", "password123"); String params = "command=" + curCommand; return params.getBytes(); } }; PyHomeController.getInstance().addToRequestQueue(req, commandTag); }
From source file:com.jvoid.customers.customer.service.CustomerMasterService.java
public int updateCustomer(JSONObject jObj) { int status = 0; Customer customer = null;/* www. j av a2 s.c o m*/ int customerId = 0; try { customerId = jObj.getInt("id"); customer = this.customerService.getcustomerById(customerId); } catch (JSONException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } if (null != customer) { System.out.println("Date:" + Utilities.getCurrentDateTime()); System.out.println("CO:" + customer.toString()); customer.setUpdatedAt(Utilities.getCurrentDateTime()); customer.setCreatedAt(customer.getCreatedAt()); try { customer.setEmail(jObj.getString("email")); customer.setCustomerGroupId(jObj.getInt("customerGroup")); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } this.customerService.updatecustomer(customer); List<Entities> listAttributes = this.entitiesService.listAttributes(); HashMap<Integer, String> attrs = getAttributesList(listAttributes, "Customer"); System.out.println("attrs==>" + attrs.toString()); for (Entry<Integer, String> entry : attrs.entrySet()) { Integer attrId = entry.getKey(); String attrName = entry.getValue(); CustomerEntityValues customerEntityValue = this.customerEntityValuesService .getCustomerEntityValuesByCustomerIdAndAttributeId(customerId, attrId); String attrValue; try { attrValue = jObj.getString(attrName); if (null != attrValue) { CustomerEntityValues custAttrValue = new CustomerEntityValues(); custAttrValue.setCustomerId(customerId); custAttrValue.setLanguage(customerEntityValue.getLanguage()); custAttrValue.setAttributeId(attrId); custAttrValue.setValue(attrValue); custAttrValue.setId(customerEntityValue.getId()); customerEntityValuesService.updateCustomerAttributeValues(custAttrValue); System.out.println("custAttrValue-->" + custAttrValue.toString()); } } catch (JSONException e) { e.printStackTrace(); } } status = 1; } else { status = 0; } return status; }
From source file:st.geekli.api.GeeklistApi.java
private Object internalDoRequest(String url, HashMap<String, Object> params, HttpMethod method, boolean sign) throws GeeklistApiException { HttpRequestBase request = null;//from ww w . ja v a 2 s. c om GeeklistApi.debugOut("Request", method.toString() + " " + url + " " + params.toString() + " | sign=" + sign); switch (method) { case GET: StringBuilder sb = new StringBuilder(); sb.append(url); if (params.size() > 0) { sb.append("?"); for (Iterator<Map.Entry<String, Object>> i = params.entrySet().iterator(); i.hasNext();) { Map.Entry<String, Object> param = i.next(); try { sb.append(param.getKey()); sb.append('='); sb.append(URLEncoder.encode(param.getValue().toString(), "UTF-8")); if (i.hasNext()) sb.append('&'); } catch (UnsupportedEncodingException e) { throw new GeeklistApiException(e); } } } request = new HttpGet(sb.toString()); break; case POST: request = new HttpPost(url); request.setHeader("Content-Type", "application/x-www-form-urlencoded"); ArrayList<BasicNameValuePair> postParams = new ArrayList<BasicNameValuePair>(); if (params.size() > 0) { for (Map.Entry<String, Object> param : params.entrySet()) { postParams.add(new BasicNameValuePair(param.getKey(), param.getValue().toString())); } } UrlEncodedFormEntity urlEncodedFormEntity; try { urlEncodedFormEntity = new UrlEncodedFormEntity(postParams); urlEncodedFormEntity.setContentEncoding(HTTP.UTF_8); ((HttpPost) request).setEntity(urlEncodedFormEntity); } catch (UnsupportedEncodingException e2) { throw new GeeklistApiException(e2); } break; } request.setHeader("User-Agent", mUserAgent); request.setHeader("Accept-Charset", "UTF-8"); if (sign) { try { mOAuthConsumer.sign(request); } catch (OAuthMessageSignerException e1) { throw new GeeklistApiException(e1); } catch (OAuthExpectationFailedException e1) { throw new GeeklistApiException(e1); } catch (OAuthCommunicationException e1) { throw new GeeklistApiException(e1); } } try { HttpResponse response = mClient.execute(request); GeeklistApi.debugOut("Response-Code", Integer.toString(response.getStatusLine().getStatusCode())); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK || response.getStatusLine().getStatusCode() == HttpStatus.SC_FORBIDDEN || response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { JSONObject responseObject = new JSONObject( Utils.inputStreamToString(response.getEntity().getContent())); if (responseObject.optString("status").equals("ok")) { JSONObject obj = responseObject.optJSONObject("data"); if (obj != null) { return obj; } else { return responseObject.optJSONArray("data"); } } else { throw new GeeklistApiException(responseObject.optString("error")); } } else { GeeklistApi.debugOut("Failed body length", "" + response.getEntity().getContentLength()); response.getEntity().consumeContent(); throw new GeeklistApiException(response.getStatusLine().getReasonPhrase()); } } catch (ClientProtocolException e) { throw new GeeklistApiException(e); } catch (IOException e) { throw new GeeklistApiException(e); } catch (IllegalStateException e) { throw new GeeklistApiException(e); } catch (JSONException e) { throw new GeeklistApiException(e); } }
From source file:com.jvoid.customers.customer.service.CustomerMasterService.java
public int addCustomer(JSONObject jObj) { int cid = 0;/*from w w w .ja va 2 s .c o m*/ String emailId = null; Customer customer = new Customer(); customer.setCreatedAt(Utilities.getCurrentDateTime()); customer.setUpdatedAt(Utilities.getCurrentDateTime()); try { customer.setCustomerGroupId(jObj.getInt("customerGroup")); emailId = jObj.getString("email"); System.out.println("EMAIL ID:" + emailId); customer.setEmail(emailId); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (null == emailId) { return cid; } else if (isEmailAlreadyExists(emailId)) { return cid; } customerService.addcustomer(customer); cid = customer.getId(); System.out.println("customer==>" + customer.toString()); List<Entities> listAttributes = this.entitiesService.listAttributes(); HashMap<Integer, String> attrs = getAttributesList(listAttributes, "Customer"); System.out.println("attrs==>" + attrs.toString()); for (Entry<Integer, String> entry : attrs.entrySet()) { Integer attrId = entry.getKey(); String attrName = entry.getValue(); String attrValue = null; try { attrValue = jObj.getString(attrName); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (null != attrValue) { CustomerEntityValues custAttrValue = new CustomerEntityValues(); custAttrValue.setCustomerId(cid); custAttrValue.setLanguage("enUS"); custAttrValue.setAttributeId(attrId); custAttrValue.setValue(attrValue); customerEntityValuesService.addCustomerAttributeValues(custAttrValue); System.out.println("custAttrValue-->" + custAttrValue.toString()); } } return cid; /* //Rest call final String SERVER_URI = "http://localhost:8080/jvoidattributes/listCustomerAttriburtes"; RestTemplate restTemplate = new RestTemplate(); String returnString = restTemplate.getForObject(SERVER_URI, String.class); JSONObject returnJsonObj = null; try { returnJsonObj = new JSONObject(returnString); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("returnJsonObj=>"+returnJsonObj); JSONArray arr = null; try { arr = returnJsonObj.getJSONArray("Attributes"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (int i=0; i<arr.length(); i++) { try { String attrValue = arr.getJSONObject(i).getString("code"); Integer attrId = Integer.parseInt(arr.getJSONObject(i).getString("id")); System.out.println("id = "+attrId+" code = "+attrValue); CustomerAttributeValues custAttrValue = new CustomerAttributeValues(); custAttrValue.setCustomerId(customer.getId());//get it from customer table custAttrValue.setLanguage("enUS"); custAttrValue.setAttributeId(attrId); custAttrValue.setValue(customerMaster.toAttributedHashMap().get(attrValue)); customerAttributeValuesService.addCustomerAttributeValues(custAttrValue); System.out.println("custAttrValue-->"+custAttrValue.toString()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } */ }
From source file:com.telestax.restcomm_olympus.CallActivity.java
private void handleCall(Intent intent) { isVideo = intent.getBooleanExtra(RCDevice.EXTRA_VIDEO_ENABLED, false); if (intent.getAction().equals(RCDevice.OUTGOING_CALL)) { String text;/*from w w w .j a v a 2 s. c o m*/ if (isVideo) { text = "Video Calling "; } else { text = "Audio Calling "; } lblCall.setText(text + intent.getStringExtra(RCDevice.EXTRA_DID).replaceAll(".*?sip:", "").replaceAll("@.*$", "")); lblStatus.setText("Initiating Call..."); connectParams = new HashMap<String, Object>(); connectParams.put(RCConnection.ParameterKeys.CONNECTION_PEER, intent.getStringExtra(RCDevice.EXTRA_DID)); connectParams.put(RCConnection.ParameterKeys.CONNECTION_VIDEO_ENABLED, intent.getBooleanExtra(RCDevice.EXTRA_VIDEO_ENABLED, false)); connectParams.put(RCConnection.ParameterKeys.CONNECTION_LOCAL_VIDEO, findViewById(R.id.local_video_layout)); connectParams.put(RCConnection.ParameterKeys.CONNECTION_REMOTE_VIDEO, findViewById(R.id.remote_video_layout)); // by default we use VP8 for video as it tends to be more adopted, but you can override that and specify VP9 as follows: //connectParams.put(RCConnection.ParameterKeys.CONNECTION_PREFERRED_VIDEO_CODEC, "VP9"); // *** if you want to add custom SIP headers, please uncomment this //HashMap<String, String> sipHeaders = new HashMap<>(); //sipHeaders.put("X-SIP-Header1", "Value1"); //connectParams.put(RCConnection.ParameterKeys.CONNECTION_CUSTOM_SIP_HEADERS, sipHeaders); handlePermissions(isVideo); } if (intent.getAction().equals(RCDevice.INCOMING_CALL)) { String text; if (isVideo) { text = "Video Call from "; } else { text = "Audio Call from "; } lblCall.setText(text + intent.getStringExtra(RCDevice.EXTRA_DID).replaceAll(".*?sip:", "").replaceAll("@.*$", "")); lblStatus.setText("Call Received..."); //callOutgoing = false; pendingConnection = device.getPendingConnection(); pendingConnection.setConnectionListener(this); // the number from which we got the call String incomingCallDid = intent.getStringExtra(RCDevice.EXTRA_DID); HashMap<String, String> customHeaders = (HashMap<String, String>) intent .getSerializableExtra(RCDevice.EXTRA_CUSTOM_HEADERS); if (customHeaders != null) { Log.i(TAG, "Got custom headers in incoming call: " + customHeaders.toString()); } } }
From source file:org.hfoss.posit.android.web.Communicator.java
/** * Get an image from the server using the guid as Key. * /*from ww w . j a v a 2 s. c o m*/ * @param guid * the Find's globally unique Id */ public ArrayList<HashMap<String, String>> getRemoteFindImages(String guid) { ArrayList<HashMap<String, String>> imagesMap = null; // ArrayList<HashMap<String, String>> imagesMap = null; String imageUrl = server + "/api/getPicturesByFind?findId=" + guid + "&authKey=" + authKey; HashMap<String, String> sendMap = new HashMap<String, String>(); Log.i(TAG, "getRemoteFindImages, sendMap=" + sendMap.toString()); sendMap.put(PositDbHelper.FINDS_GUID, guid); addRemoteIdentificationInfo(sendMap); try { String imageResponseString = doHTTPPost(imageUrl, sendMap); Log.i(TAG, "getRemoteFindImages, response=" + imageResponseString); if (!imageResponseString.equals(RESULT_FAIL)) { JSONArray jsonArr = new JSONArray(imageResponseString); imagesMap = new ArrayList<HashMap<String, String>>(); for (int i = 0; i < jsonArr.length(); i++) { JSONObject jsonObj = jsonArr.getJSONObject(i); if (Utils.debug) Log.i(TAG, "JSON Image Response String: " + jsonObj.toString()); Iterator<String> iterKeys = jsonObj.keys(); HashMap<String, String> map = new HashMap<String, String>(); while (iterKeys.hasNext()) { String key = iterKeys.next(); map.put(key, jsonObj.getString(key)); } imagesMap.add(map); } } } catch (Exception e) { Log.i(TAG, e.getMessage()); e.printStackTrace(); } if (imagesMap != null && Utils.debug) Log.i(TAG, "getRemoteFindImages, imagesMap=" + imagesMap.toString()); else Log.i(TAG, "getRemoteFindImages, imagesMap= null"); return imagesMap; }
From source file:org.aprilis.jrest.compile.Compile.java
/** * //from w w w .j a va 2 s . co m * @param jRestKey * @param hmapBeforeMapping * @param apiDefinition * @return */ private boolean loadJsonBeforeTagInfo(String jRestKey, HashMap<String, String> hmapBeforeMapping, Definition apiDefinition) { System.out.println("Here is the Map" + hmapBeforeMapping.toString()); if (hmapBeforeMapping.containsKey(Constants.gsLangDefKeywordClass) && hmapBeforeMapping.containsKey(Constants.gsLangDefKeywordMethod) && hmapBeforeMapping.containsKey(Constants.gsLangDefKeywordConsume)) { String sClassName = hmapBeforeMapping.get(Constants.gsLangDefKeywordClass); String sMethodName = hmapBeforeMapping.get(Constants.gsLangDefKeywordMethod); String sResultUsage = hmapBeforeMapping.get(Constants.gsLangDefKeywordConsume); if (sClassName != null && sMethodName != null && sResultUsage != null) { if (sClassName.length() >= Constants.gshMinFunctionLength) { apiDefinition.setFqcnBefore(sClassName); } else { mLogger.error(Exceptions.gsInvalidFunctionNameGiven); return false; } // if (sClassName.length() >= Constants.gshMinFunctionLength) if (sMethodName.length() >= Constants.gshMinFunctionLength) { apiDefinition.setBeforeMethod(sMethodName); } else { // Method name too small error mLogger.error(Exceptions.gsInvalidMethodNameGiven); return false; } // if (sMethodName.length() >= Constants.gshMinFunctionLength) if (sResultUsage.equals(Constants.gsConsumeBeforeFalse)) { apiDefinition.setBeforeUsagePattern(false); } else if (sResultUsage.equals(Constants.gsConsumeBeforeTrue)) { apiDefinition.setBeforeUsagePattern(true); } else { mLogger.error(Exceptions.gsUnknownConsumeValue); return false; } // if (sResultUsage.equals(Constants.gsConsumeBeforeFalse)) } else { // Empty values supplied for the keywords Method or Consume mLogger.error(String.format(Exceptions.gsMissingMandatoryValuesInBefore, jRestKey)); return false; } // if (sClassName != null && sMethodName != null && sResultUsage != // null) } else { // Syntax error mLogger.error(String.format(Exceptions.gsMissingMandatoryKeywordsInBefore, jRestKey)); return false; } // if (hmapBeforeMapping.containsKey(.... ) return true; }
From source file:com.google.gwt.emultest.java.util.HashMapTest.java
/** * Test method for 'java.util.AbstractMap.toString()'. *//*ww w . j a v a 2 s . c o m*/ public void testToString() { HashMap<String, String> hashMap = new HashMap<String, String>(); checkEmptyHashMapAssumptions(hashMap); hashMap.put(KEY_KEY, VALUE_VAL); String entryString = makeEntryString(KEY_KEY, VALUE_VAL); assertTrue(entryString.equals(hashMap.toString())); }
From source file:com.mojio.mojiosdk.networking.MojioRequest.java
@Override public Map<String, String> getHeaders() throws AuthFailureError { DataStorageHelper oauth = new DataStorageHelper(this.mAppContext); HashMap<String, String> headers = new HashMap<String, String>(); headers.putAll(super.getHeaders()); // Check for auth token // Start with user auth, if that does not exist, check for app auth String mojioAuth = oauth.GetAccessToken(); if (mojioAuth == null) { mojioAuth = oauth.GetAppToken(); }/*w w w.j a v a 2 s . c om*/ if (mojioAuth != null) { headers.put("MojioAPIToken", mojioAuth); } if (imageByteArray != null) { String body = String.format("\"%s\"", this.contentBody); headers.put("Content-Type", "application/json; charset=utf-8"); headers.put("Content-Length", String.valueOf(body.length())); } // TODO may want to init MojioClient WITH access token. This would make the app responsible for storing token data. Log.i("MOJIO", "Adding headers: " + headers.toString()); return headers; }