List of usage examples for java.util Map.Entry toString
public String toString()
From source file:org.dbg4j.rest.DebugJerseyFilter.java
private String getResponseHeaders(ClientResponse response) { String result = "Error retrieving response body: "; try {/* w w w . ja v a 2s. c o m*/ StringBuilder b = new StringBuilder(); for (Map.Entry<String, List<String>> e : response.getHeaders().entrySet()) { String header = e.getKey(); for (String value : e.getValue()) { b.append(header).append(": ").append(value).append("\n"); } } b.append("\n"); result = b.toString(); } catch (Exception e) { result += e.toString(); } return result; }
From source file:org.apache.lens.server.session.HiveSessionService.java
/** * {@inheritDoc}// w ww .j a v a 2 s .c o m */ @Override public List<String> getAllSessionParameters(LensSessionHandle sessionid, boolean verbose, String key) throws LensException { List<String> result = new ArrayList<String>(); acquire(sessionid); try { SessionState ss = getSession(sessionid).getSessionState(); if (!StringUtils.isBlank(key)) { result.add(getSessionParam(getSession(sessionid).getSessionConf(), ss, key)); } else { SortedMap<String, String> sortedMap = new TreeMap<String, String>(); sortedMap.put("silent", (ss.getIsSilent() ? "on" : "off")); for (String s : ss.getHiveVariables().keySet()) { sortedMap.put(SystemVariables.HIVEVAR_PREFIX + s, ss.getHiveVariables().get(s)); } for (Map.Entry<String, String> entry : getSession(sessionid).getSessionConf()) { sortedMap.put(entry.getKey(), entry.getValue()); } for (Map.Entry<String, String> entry : sortedMap.entrySet()) { result.add(entry.toString()); } } } finally { release(sessionid); } return result; }
From source file:com.github.tteofili.p2h.Par2HierTest.java
private String asStrings(Map<String, INDArray> pvs, Map<String, INDArray> hvs) { StringBuilder builder = new StringBuilder(); builder.append("doc, depth, Paragraph, PV x, PV y, HV x, HV y\n"); for (Map.Entry<String, INDArray> entry : pvs.entrySet()) { String key = entry.getKey(); String depth = String.valueOf(key.split("\\.").length - 1); String c = String.valueOf(key.charAt(3)); if (Character.isDigit(key.charAt(4))) { c += key.charAt(4);/*from w w w . ja va 2s.co m*/ } String doc = String.valueOf(c); builder.append(doc).append(',').append(depth).append(", ") .append(entry.toString().replace("=[", ",").replace("]", ",")); String s = hvs.get(key).toString(); builder.append(s.replace("[", "").replace("]", "")).append("\n"); } return builder.toString(); }
From source file:org.sonatype.nexus.rest.AbstractResourceStoreContentPlexusResource.java
protected ContentListDescribeRequestResource describeRequest(Context context, Request req, Response res, Variant variant, ResourceStoreRequest request) { ContentListDescribeRequestResource result = new ContentListDescribeRequestResource(); result.setRequestUrl(request.getRequestUrl()); result.setRequestPath(request.getRequestPath()); for (Map.Entry<String, Object> entry : request.getRequestContext().entrySet()) { result.addRequestContext(entry.toString()); }/*from www . j a v a2 s . c om*/ return result; }
From source file:com.algolia.search.saas.APIClient.java
private JSONObject _request(Method m, String url, String json, boolean build) throws AlgoliaException { HttpRequestBase req;/*from ww w.ja v a2 s . c om*/ switch (m) { case DELETE: req = new HttpDelete(); break; case GET: req = new HttpGet(); break; case POST: req = new HttpPost(); break; case PUT: req = new HttpPut(); break; default: throw new IllegalArgumentException("Method " + m + " is not supported"); } HashMap<String, String> errors = new HashMap<String, String>(); List<String> hosts = null; List<Long> enabled = null; if (build) { hosts = this.buildHostsArray; enabled = this.buildHostsEnabled; } else { hosts = this.queryHostsArray; enabled = this.queryHostsEnabled; } // for each host for (int i = 0; i < hosts.size(); ++i) { String host = hosts.get(i); if (enabled.get(i) > System.currentTimeMillis()) continue; JSONObject res = _requestByHost(req, host, url, json, errors); if (res != null) return res; enabled.set(i, System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(30, TimeUnit.SECONDS)); } enabled.set(enabled.size() - 1, 0L); // Keep the last host up; StringBuilder builder = new StringBuilder("Hosts unreachable: "); Boolean first = true; for (Map.Entry<String, String> entry : errors.entrySet()) { if (!first) { builder.append(", "); } builder.append(entry.toString()); first = false; } throw new AlgoliaException(builder.toString()); }
From source file:org.apache.solr.handler.TestSolrConfigHandlerConcurrent.java
@Test public void test() throws Exception { Map editable_prop_map = (Map) Utils.fromJSONResource("EditableSolrConfigAttributes.json"); Map caches = (Map) editable_prop_map.get("query"); setupHarnesses();//from w w w . j a v a2 s .com List<Thread> threads = new ArrayList<>(caches.size()); final List<List> collectErrors = new ArrayList<>(); for (Object o : caches.entrySet()) { final Map.Entry e = (Map.Entry) o; Thread t = new Thread() { @Override public void run() { try { ArrayList errs = new ArrayList(); collectErrors.add(errs); invokeBulkCall((String) e.getKey(), errs, (Map) e.getValue()); } catch (Exception e) { e.printStackTrace(); } } }; threads.add(t); t.start(); } for (Thread thread : threads) thread.join(); boolean success = true; for (List e : collectErrors) { if (!e.isEmpty()) { success = false; log.error(e.toString()); } } assertTrue(collectErrors.toString(), success); }
From source file:org.esbtools.message.admin.common.EsbMessageAdminServiceImpl.java
private Map<String, String> matchCriteria(EsbMessage message, List<VisibilityConfiguration> configurations) { String messageString = message.toString().toLowerCase(); for (VisibilityConfiguration conf : configurations) { boolean matched = true; for (Map.Entry<String, String> matchCondition : conf.getMatchCriteriaMap().entrySet()) { if (!messageString.contains(matchCondition.toString().toLowerCase())) { matched = false;//from www . j a v a2s. c o m break; } } if (matched) { return conf.getConfigurationMap(); } } return null; }
From source file:org.sonatype.nexus.rest.AbstractResourceStoreContentPlexusResource.java
protected ContentListDescribeResponseResource describeResponse(Context context, Request req, Response res, Variant variant, ResourceStoreRequest request, StorageItem item, Throwable e) { ContentListDescribeResponseResource result = new ContentListDescribeResponseResource(); result.getProcessedRepositoriesList().addAll(request.getProcessedRepositories()); // applied mappings for (Map.Entry<String, List<String>> mappingEntry : request.getAppliedMappings().entrySet()) { result.addAppliedMapping(mappingEntry.getKey() + " repository applied " + mappingEntry.getValue()); }/*w w w . j a v a 2s . co m*/ if (item == null) { result.setResponseType("NOT_FOUND"); if (e != null) { result.addNotFoundReasoning(buildNotFoundReasoning(null, e)); } return result; } if (item instanceof StorageFileItem) { result.setResponseType("FILE"); } else if (item instanceof StorageCollectionItem) { result.setResponseType("COLL"); } else if (item instanceof StorageLinkItem) { result.setResponseType("LINK"); } else { result.setResponseType(item.getClass().getName()); } result.setResponseActualClass(item.getClass().getName()); result.setResponsePath(item.getPath()); if (!item.isVirtual()) { result.setResponseUid(item.getRepositoryItemUid().toString()); result.setOriginatingRepositoryId(item.getRepositoryItemUid().getRepository().getId()); result.setOriginatingRepositoryName(item.getRepositoryItemUid().getRepository().getName()); result.setOriginatingRepositoryMainFacet( item.getRepositoryItemUid().getRepository().getRepositoryKind().getMainFacet().getName()); } else { result.setResponseUid("virtual"); } // properties result.addProperty("created=" + item.getCreated()); result.addProperty("modified=" + item.getModified()); result.addProperty("lastRequested=" + item.getLastRequested()); result.addProperty("remoteChecked=" + item.getRemoteChecked()); result.addProperty("remoteUrl=" + item.getRemoteUrl()); result.addProperty("storedLocally=" + item.getStoredLocally()); result.addProperty("isExpired=" + item.isExpired()); result.addProperty("readable=" + item.isReadable()); result.addProperty("writable=" + item.isWritable()); result.addProperty("virtual=" + item.isVirtual()); // attributes final TreeMap<String, String> sortedAttributes = Maps.newTreeMap(); sortedAttributes.putAll(item.getRepositoryItemAttributes().asMap()); for (Map.Entry<String, String> entry : sortedAttributes.entrySet()) { result.addAttribute(entry.toString()); } // sources if (item instanceof StorageCompositeItem) { StorageCompositeItem composite = (StorageCompositeItem) item; for (StorageItem source : composite.getSources()) { if (!source.isVirtual()) { result.addSource(source.getRepositoryItemUid().toString()); } else { result.addSource(source.getPath()); } } } return result; }
From source file:org.dbg4j.rest.DebugJerseyFilter.java
private String getRequestHeaders(@Nonnull ClientRequest request) { String result = "Error retrieving request headers: "; try {//from w w w.j a v a 2 s. c o m StringBuilder b = new StringBuilder(); for (Map.Entry<String, List<Object>> e : request.getHeaders().entrySet()) { List<Object> val = e.getValue(); String header = e.getKey(); if (val.size() == 1) { b.append(header).append(": ").append(ClientRequest.getHeaderValue(val.get(0))).append("\n"); } else { StringBuilder sb = new StringBuilder(); boolean add = false; for (Object o : val) { if (add) { sb.append(','); } add = true; sb.append(ClientRequest.getHeaderValue(o)); } b.append(header).append(": ").append(sb.toString()).append("\n"); } } result = b.toString(); } catch (Exception e) { result += e.toString(); } return result; }
From source file:org.opendatakit.dwc.server.GreetingServiceImpl.java
@Override public String getOauth2UserEmail() throws IllegalArgumentException { // get the auth code... Context ctxt = getStateContext(ctxtKey); String code = (String) ctxt.getContext("code"); {/*from w w w . j a v a 2s . c o m*/ // convert the auth code into an auth token URI nakedUri; try { nakedUri = new URI(tokenUrl); } catch (URISyntaxException e2) { e2.printStackTrace(); logger.error(e2.toString()); return getSelfUrl(); } // DON'T NEED clientId on the toke request... // addCredentials(clientId, clientSecret, nakedUri.getHost()); // setup request interceptor to do preemptive auth // ((DefaultHttpClient) client).addRequestInterceptor(getPreemptiveAuth(), 0); HttpClientFactory factory = new GaeHttpClientFactoryImpl(); HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, SERVICE_TIMEOUT_MILLISECONDS); HttpConnectionParams.setSoTimeout(httpParams, SOCKET_ESTABLISHMENT_TIMEOUT_MILLISECONDS); // support redirecting to handle http: => https: transition HttpClientParams.setRedirecting(httpParams, true); // support authenticating HttpClientParams.setAuthenticating(httpParams, true); httpParams.setParameter(ClientPNames.MAX_REDIRECTS, 1); httpParams.setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true); // setup client HttpClient client = factory.createHttpClient(httpParams); HttpPost httppost = new HttpPost(nakedUri); logger.info(httppost.getURI().toString()); // THESE ARE POST BODY ARGS... List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("grant_type", "authorization_code")); qparams.add(new BasicNameValuePair("client_id", CLIENT_ID)); qparams.add(new BasicNameValuePair("client_secret", CLIENT_SECRET)); qparams.add(new BasicNameValuePair("code", code)); qparams.add(new BasicNameValuePair("redirect_uri", getOauth2CallbackUrl())); UrlEncodedFormEntity postentity; try { postentity = new UrlEncodedFormEntity(qparams, "UTF-8"); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); logger.error(e1.toString()); throw new IllegalArgumentException("Unexpected"); } httppost.setEntity(postentity); HttpResponse response = null; try { response = client.execute(httppost, localContext); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { logger.error("not 200: " + statusCode); return "Error with Oauth2 token request - reason: " + response.getStatusLine().getReasonPhrase() + " status code: " + statusCode; } else { HttpEntity entity = response.getEntity(); if (entity != null && entity.getContentType().getValue().toLowerCase().contains("json")) { ObjectMapper mapper = new ObjectMapper(); BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent())); Map<String, Object> userData = mapper.readValue(reader, Map.class); // stuff the map in the Context... for (Map.Entry<String, Object> e : userData.entrySet()) { ctxt.putContext(e.getKey(), e.getValue()); } } else { logger.error("unexpected body"); return "Error with Oauth2 token request - missing body"; } } } catch (IOException e) { throw new IllegalArgumentException(e.toString()); } } // OK if we got here, we have a valid token. // Issue the request... String email = null; { URI nakedUri; try { nakedUri = new URI(userInfoUrl); } catch (URISyntaxException e2) { e2.printStackTrace(); logger.error(e2.toString()); return getSelfUrl(); } List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("access_token", (String) ctxt.getContext("access_token"))); URI uri; try { uri = URIUtils.createURI(nakedUri.getScheme(), nakedUri.getHost(), nakedUri.getPort(), nakedUri.getPath(), URLEncodedUtils.format(qparams, "UTF-8"), null); } catch (URISyntaxException e1) { e1.printStackTrace(); logger.error(e1.toString()); return getSelfUrl(); } // DON'T NEED clientId on the toke request... // addCredentials(clientId, clientSecret, nakedUri.getHost()); // setup request interceptor to do preemptive auth // ((DefaultHttpClient) client).addRequestInterceptor(getPreemptiveAuth(), 0); HttpClientFactory factory = new GaeHttpClientFactoryImpl(); HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, SERVICE_TIMEOUT_MILLISECONDS); HttpConnectionParams.setSoTimeout(httpParams, SOCKET_ESTABLISHMENT_TIMEOUT_MILLISECONDS); // support redirecting to handle http: => https: transition HttpClientParams.setRedirecting(httpParams, true); // support authenticating HttpClientParams.setAuthenticating(httpParams, true); httpParams.setParameter(ClientPNames.MAX_REDIRECTS, 1); httpParams.setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true); // setup client HttpClient client = factory.createHttpClient(httpParams); HttpGet httpget = new HttpGet(uri); logger.info(httpget.getURI().toString()); HttpResponse response = null; try { response = client.execute(httpget, localContext); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { logger.error("not 200: " + statusCode); return "Error - reason: " + response.getStatusLine().getReasonPhrase() + " status code: " + statusCode; } else { HttpEntity entity = response.getEntity(); if (entity != null && entity.getContentType().getValue().toLowerCase().contains("json")) { ObjectMapper mapper = new ObjectMapper(); BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent())); Map<String, Object> userData = mapper.readValue(reader, Map.class); email = (String) userData.get("email"); } else { logger.error("unexpected body"); return "Error - missing body"; } } } catch (IOException e) { throw new IllegalArgumentException(e.toString()); } } return email; }