List of usage examples for java.util Map isEmpty
boolean isEmpty();
From source file:com.ning.metrics.collector.processing.db.model.FeedEvent.java
@JsonIgnore public static Predicate<FeedEvent> isAnyKeyValuMatching(final Map<String, Object> filterMap) { Predicate<FeedEvent> feedEventPredicate = new Predicate<FeedEvent>() { @Override//from w w w. j av a 2 s .c o m public boolean apply(FeedEvent input) { if (filterMap == null || filterMap.isEmpty()) { return true; } return !Maps.difference(filterMap, input.getEvent().getData()).entriesInCommon().isEmpty(); } }; return feedEventPredicate; }
From source file:com.amazonaws.services.sqs.MessageMD5ChecksumHandler.java
/** * Throw an exception if the MD5 checksums returned in the SendMessageResult * do not match the client-side calculation based on the original message in * the SendMessageRequest./*from w w w .j ava 2 s . com*/ */ private static void sendMessageOperationMd5Check(SendMessageRequest sendMessageRequest, SendMessageResult sendMessageResult) { String messageBodySent = sendMessageRequest.getMessageBody(); String bodyMd5Returned = sendMessageResult.getMD5OfMessageBody(); String clientSideBodyMd5 = calculateMessageBodyMd5(messageBodySent); if (!clientSideBodyMd5.equals(bodyMd5Returned)) { throw new AmazonClientException( String.format(MD5_MISMATCH_ERROR_MESSAGE, MESSAGE_BODY, clientSideBodyMd5, bodyMd5Returned)); } Map<String, MessageAttributeValue> messageAttrSent = sendMessageRequest.getMessageAttributes(); if (messageAttrSent != null && !messageAttrSent.isEmpty()) { String clientSideAttrMd5 = calculateMessageAttributesMd5(messageAttrSent); String attrMd5Returned = sendMessageResult.getMD5OfMessageAttributes(); if (!clientSideAttrMd5.equals(attrMd5Returned)) { throw new AmazonClientException(String.format(MD5_MISMATCH_ERROR_MESSAGE, MESSAGE_ATTRIBUTES, clientSideAttrMd5, attrMd5Returned)); } } }
From source file:com.amazonaws.services.sqs.MessageMD5ChecksumHandler.java
/** * Throw an exception if the MD5 checksums included in the * ReceiveMessageResult do not match the client-side calculation on the * received messages./*from ww w.jav a2s . c om*/ */ private static void receiveMessageResultMd5Check(ReceiveMessageResult receiveMessageResult) { if (receiveMessageResult.getMessages() != null) { for (Message messageReceived : receiveMessageResult.getMessages()) { String messageBody = messageReceived.getBody(); String bodyMd5Returned = messageReceived.getMD5OfBody(); String clientSideBodyMd5 = calculateMessageBodyMd5(messageBody); if (!clientSideBodyMd5.equals(bodyMd5Returned)) { throw new AmazonClientException(String.format(MD5_MISMATCH_ERROR_MESSAGE, MESSAGE_BODY, clientSideBodyMd5, bodyMd5Returned)); } Map<String, MessageAttributeValue> messageAttr = messageReceived.getMessageAttributes(); if (messageAttr != null && !messageAttr.isEmpty()) { String attrMd5Returned = messageReceived.getMD5OfMessageAttributes(); String clientSideAttrMd5 = calculateMessageAttributesMd5(messageAttr); if (!clientSideAttrMd5.equals(attrMd5Returned)) { throw new AmazonClientException(String.format(MD5_MISMATCH_ERROR_MESSAGE, MESSAGE_ATTRIBUTES, clientSideAttrMd5, attrMd5Returned)); } } } } }
From source file:com.adnature.framework.util.Struts2Utils.java
/** * ??Request//from w w w. j a va2 s . co m * @param prefix ?? */ public static void fillSearchParams(String prefix) { if (StringUtils.isBlank(prefix)) { return; } HttpServletRequest request = getRequest(); Map<String, Object> parmMap = new HashMap<String, Object>(); // request??????,?????Map Map<String, Object> filterParamMap = WebUtils.getParametersStartingWith(request, prefix + "#filter_"); if (filterParamMap != null && !filterParamMap.isEmpty()) { for (Entry<String, Object> entry : filterParamMap.entrySet()) { String filterName = entry.getKey(); String value = ((String) entry.getValue()).trim().replaceAll("\"", """); value = value.replaceAll("<", "<"); value = value.replaceAll(">", ">"); // value,filter. boolean omit = StringUtils.isBlank(value); if (!omit) { request.setAttribute("filter_" + filterName, value); parmMap.put("filter_" + filterName, value); } } request.setAttribute(SEARCH_KEY, parmMap); request.setAttribute(prefix, parmMap); } }
From source file:de.innovationgate.wgpublisher.bi.BiBase.java
public static String getPassword(javax.servlet.jsp.PageContext pageContext, String dbKey) throws WGException { Map hm = WGACore.getSessionLogins(pageContext.getSession()); WGDatabase db = getDB(pageContext, dbKey); String domain = (String) db.getAttribute(WGACore.DBATTRIB_DOMAIN); if (hm == null) return ""; if (hm.isEmpty()) return ""; DBLoginInfo li = (DBLoginInfo) hm.get(domain); return li.getPassword(); }
From source file:it.user.RealmAuthenticationTest.java
@CheckForNull private static String format(Map<String, String> map) { if (map.isEmpty()) { return null; }/* w w w . java 2 s . co m*/ StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> entry : map.entrySet()) { sb.append(entry.getKey()).append('=').append(entry.getValue()).append('\n'); } return sb.toString(); }
From source file:com.rsa.redchallenge.standaloneapp.utils.RestInteractor.java
private static Object[] getObjectParams(Map<String, Object> params) { //RestTemplate considers curly braces {...} in the given URL as a placeholder for URI variables and tries to replace them based on their name //hence passing the values as it gets replaced by {} if (params != null && !params.isEmpty()) { return params.values().toArray(); }/*from w ww. j a v a 2s . co m*/ return new Object[0]; }
From source file:com.wavemaker.runtime.ws.HTTPBindingSupport.java
@SuppressWarnings("unchecked") private static <T extends Object> T getResponse(QName serviceQName, QName portQName, String endpointAddress, HTTPRequestMethod method, T postSource, BindingProperties bindingProperties, Class<T> type, Map<String, Object> headerParams) throws WebServiceException { Service service = Service.create(serviceQName); URI endpointURI;/*from w w w . j a v a2s . com*/ try { if (bindingProperties != null) { // if BindingProperties had endpointAddress defined, then use // it instead of the endpointAddress passed in from arguments. String endAddress = bindingProperties.getEndpointAddress(); if (endAddress != null) { endpointAddress = endAddress; } } endpointURI = new URI(endpointAddress); } catch (URISyntaxException e) { throw new WebServiceException(e); } String endpointPath = null; String endpointQueryString = null; if (endpointURI != null) { endpointPath = endpointURI.getRawPath(); endpointQueryString = endpointURI.getRawQuery(); } service.addPort(portQName, HTTPBinding.HTTP_BINDING, endpointAddress); Dispatch<T> d = service.createDispatch(portQName, type, Service.Mode.MESSAGE); Map<String, Object> requestContext = d.getRequestContext(); requestContext.put(MessageContext.HTTP_REQUEST_METHOD, method.toString()); requestContext.put(MessageContext.QUERY_STRING, endpointQueryString); requestContext.put(MessageContext.PATH_INFO, endpointPath); Map<String, List<String>> reqHeaders = null; if (bindingProperties != null) { String httpBasicAuthUsername = bindingProperties.getHttpBasicAuthUsername(); if (httpBasicAuthUsername != null) { requestContext.put(BindingProvider.USERNAME_PROPERTY, httpBasicAuthUsername); String httpBasicAuthPassword = bindingProperties.getHttpBasicAuthPassword(); requestContext.put(BindingProvider.PASSWORD_PROPERTY, httpBasicAuthPassword); } int connectionTimeout = bindingProperties.getConnectionTimeout(); requestContext.put(JAXWSProperties.CONNECT_TIMEOUT, Integer.valueOf(connectionTimeout)); int requestTimeout = bindingProperties.getRequestTimeout(); requestContext.put(JAXWSProperties.REQUEST_TIMEOUT, Integer.valueOf(requestTimeout)); Map<String, List<String>> httpHeaders = bindingProperties.getHttpHeaders(); if (httpHeaders != null && !httpHeaders.isEmpty()) { reqHeaders = (Map<String, List<String>>) requestContext.get(MessageContext.HTTP_REQUEST_HEADERS); if (reqHeaders == null) { reqHeaders = new HashMap<String, List<String>>(); requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, reqHeaders); } for (Entry<String, List<String>> entry : httpHeaders.entrySet()) { reqHeaders.put(entry.getKey(), entry.getValue()); } } } // Parameters to pass in http header if (headerParams != null && headerParams.size() > 0) { if (null == reqHeaders) { reqHeaders = new HashMap<String, List<String>>(); } Set<Entry<String, Object>> entries = headerParams.entrySet(); for (Map.Entry<String, Object> entry : entries) { List<String> valList = new ArrayList<String>(); valList.add((String) entry.getValue()); reqHeaders.put(entry.getKey(), valList); requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, reqHeaders); } } logger.info("Invoking HTTP '" + method + "' request with URL: " + endpointAddress); T result = d.invoke(postSource); return result; }
From source file:de.adorsys.oauth.server.FixedServletUtils.java
/** * Creates a new HTTP request from the specified HTTP servlet request. * * @param servletRequest The servlet request. Must not be * {@code null}.// ww w.j a va 2s . c om * @param maxEntityLength The maximum entity length to accept, -1 for * no limit. * * @return The HTTP request. * * @throws IllegalArgumentException The the servlet request method is * not GET, POST, PUT or DELETE or the * content type header value couldn't * be parsed. * @throws IOException For a POST or PUT body that * couldn't be read due to an I/O * exception. */ public static HTTPRequest createHTTPRequest(final HttpServletRequest servletRequest, final long maxEntityLength) throws IOException { HTTPRequest.Method method = HTTPRequest.Method.valueOf(servletRequest.getMethod().toUpperCase()); String urlString = reconstructRequestURLString(servletRequest); URL url; try { url = new URL(urlString); } catch (MalformedURLException e) { throw new IllegalArgumentException("Invalid request URL: " + e.getMessage() + ": " + urlString, e); } HTTPRequest request = new HTTPRequest(method, url); try { request.setContentType(servletRequest.getContentType()); } catch (ParseException e) { throw new IllegalArgumentException("Invalid Content-Type header value: " + e.getMessage(), e); } Enumeration<String> headerNames = servletRequest.getHeaderNames(); while (headerNames.hasMoreElements()) { final String headerName = headerNames.nextElement(); request.setHeader(headerName, servletRequest.getHeader(headerName)); } if (method.equals(HTTPRequest.Method.GET) || method.equals(HTTPRequest.Method.DELETE)) { request.setQuery(servletRequest.getQueryString()); } else if (method.equals(HTTPRequest.Method.POST) || method.equals(HTTPRequest.Method.PUT)) { if (maxEntityLength > 0 && servletRequest.getContentLength() > maxEntityLength) { throw new IOException("Request entity body is too large, limit is " + maxEntityLength + " chars"); } Map<String, String[]> parameterMap = servletRequest.getParameterMap(); StringBuilder builder = new StringBuilder(); if (!parameterMap.isEmpty()) { for (Entry<String, String[]> entry : parameterMap.entrySet()) { String key = entry.getKey(); String[] value = entry.getValue(); if (value.length > 0 && value[0] != null) { String encoded = URLEncoder.encode(value[0], "UTF-8"); builder = builder.append(key).append('=').append(encoded).append('&'); } } String queryString = StringUtils.substringBeforeLast(builder.toString(), "&"); request.setQuery(queryString); } else { // read body StringBuilder body = new StringBuilder(256); BufferedReader reader = servletRequest.getReader(); reader.reset(); char[] cbuf = new char[256]; int readChars; while ((readChars = reader.read(cbuf)) != -1) { body.append(cbuf, 0, readChars); if (maxEntityLength > 0 && body.length() > maxEntityLength) { throw new IOException( "Request entity body is too large, limit is " + maxEntityLength + " chars"); } } reader.reset(); // reader.close(); request.setQuery(body.toString()); } } return request; }
From source file:org.bigtester.ate.GlobalUtils.java
/** * Find test case bean./*w ww. j a v a2s.c o m*/ * * @param appCtx * the app ctx * @return the xml test case * @throws NoSuchBeanDefinitionException * the no such bean definition exception */ public static TestCase findTestCaseBean(ApplicationContext appCtx) throws NoSuchBeanDefinitionException { Map<String, TestCase> testcases = appCtx.getBeansOfType(TestCase.class); if (testcases.isEmpty()) { throw new NoSuchBeanDefinitionException(TestCase.class); } else { TestCase retVal = testcases.values().iterator().next(); if (null == retVal) { throw new NoSuchBeanDefinitionException(TestCase.class); } else { return retVal; } } }