List of usage examples for java.util Map remove
V remove(Object key);
From source file:org.wso2.carbon.apimgt.gateway.handlers.Utils.java
public static void sendFault(MessageContext messageContext, int status) { org.apache.axis2.context.MessageContext axis2MC = ((Axis2MessageContext) messageContext) .getAxis2MessageContext(); axis2MC.setProperty(NhttpConstants.HTTP_SC, status); messageContext.setResponse(true);// w ww . jav a2s . co m messageContext.setProperty("RESPONSE", "true"); messageContext.setTo(null); axis2MC.removeProperty("NO_ENTITY_BODY"); // Always remove the ContentType - Let the formatter do its thing axis2MC.removeProperty(Constants.Configuration.CONTENT_TYPE); Map headers = (Map) axis2MC.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); if (headers != null) { headers.remove(HttpHeaders.AUTHORIZATION); headers.remove(HttpHeaders.AUTHORIZATION); headers.remove(HttpHeaders.HOST); } Axis2Sender.sendBack(messageContext); }
From source file:com.yahoo.sql4dclient.BeanGenUtil.java
public static void generateBean(String cmd, String beanClassName) { Matcher joinSqlMatcher = joinSqlPattern.matcher(cmd); if (joinSqlMatcher.matches()) { Map<String, String> firstSet = getFields(joinSqlMatcher.group(1)); Map<String, String> secondSet = null; Matcher sqlMatcher = sqlPattern.matcher(joinSqlMatcher.group(4)); if (sqlMatcher.matches()) { secondSet = getFields(sqlMatcher.group(1)); String joinField = joinSqlMatcher.group(5); secondSet.remove(joinField); firstSet.putAll(secondSet);/*from ww w. ja va 2s .c o m*/ } generate(firstSet, beanClassName); } else { Matcher sqlMatcher = sqlPattern.matcher(cmd); if (sqlMatcher.matches()) { generate(getFields(sqlMatcher.group(1)), beanClassName); } } }
From source file:azkaban.project.FlowLoaderUtils.java
/** * Helper method to recursively find the node to override props. * * @param nodeBean the node bean/*from ww w . j av a2 s .co m*/ * @param pathList the path list * @param idx the idx * @param prop the props to override * @return the boolean */ private static boolean overridePropsInNodeBean(final NodeBean nodeBean, final String[] pathList, final int idx, final Props prop) { if (idx < pathList.length && nodeBean.getName().equals(pathList[idx])) { if (idx == pathList.length - 1) { if (prop.containsKey(Constants.NODE_TYPE)) { nodeBean.setType(prop.get(Constants.NODE_TYPE)); } final Map<String, String> config = prop.getFlattened(); config.remove(Constants.NODE_TYPE); nodeBean.setConfig(config); return true; } for (final NodeBean bean : nodeBean.getNodes()) { if (overridePropsInNodeBean(bean, pathList, idx + 1, prop)) { return true; } } } return false; }
From source file:com.interopbridges.tools.windowsazure.JSONHelper.java
protected static String setCache(String encodedCaches, String name, String newCache) throws WindowsAzureInvalidProjectOperationException { try {/*from w ww. j a v a2 s. c o m*/ Map<String, String> cacheMap = getCaches(encodedCaches); if (newCache.isEmpty()) { // remove the cache from arraylist and map cacheMap.remove(name); } else { cacheMap.put(name, newCache); } String decodedCache = decodeHTML(encodedCaches); JSONObject oriCacheObj = new JSONObject(decodedCache); JSONArray cachesArr = new JSONArray(); Set<Entry<String, String>> set = cacheMap.entrySet(); for (Entry<String, String> entry : set) { cachesArr.put(new JSONObject(decodeHTML(entry.getValue()))); } oriCacheObj.put("caches", cachesArr); return oriCacheObj.toString(); } catch (Exception ex) { throw new WindowsAzureInvalidProjectOperationException(WindowsAzureConstants.EXCP, ex); } }
From source file:com.good.example.contributor.jhawkins.gdruntime.RuntimeDispatcher.java
public static Map<String, Object> getApplicationConfigWithoutDeprecations() { Map<String, Object> map = new HashMap<String, Object>(GDAndroid.getInstance().getApplicationConfig()); map.remove("appHost"); map.remove("appPort"); return map;/*from w ww . j a v a 2 s . co m*/ }
From source file:jef.testbase.JefTester.java
private static Entry<Integer, Integer> getSmall(Map<Integer, Integer> data) { int min = Integer.MAX_VALUE; Integer key = null;//from w w w. j a va 2 s .com for (Integer i : data.keySet()) { if (data.get(i) < min) { key = i; min = data.get(i); } } return new Entry<Integer, Integer>(key, data.remove(key)); }
From source file:com.ctriposs.r2.message.rest.QueryTunnelUtil.java
/** * Takes a Request object that has been encoded for tunnelling as a POST with an X-HTTP-Override-Method header and * creates a new request that represents the intended original request * * @param request the request to be decoded * * @return a decoded RestRequest/*w w w. j a va 2s. co m*/ */ public static RestRequest decode(final RestRequest request) throws MessagingException, IOException, URISyntaxException { if (request.getHeader(HEADER_METHOD_OVERRIDE) == null) { // Not a tunnelled request, just pass thru return request; } String query = null; byte[] entity = new byte[0]; // All encoded requests must have a content type. If the header is missing, ContentType throws an exception ContentType contentType = new ContentType(request.getHeader(HEADER_CONTENT_TYPE)); RestRequestBuilder requestBuilder = request.builder(); // Get copy of headers and remove the override Map<String, String> h = new HashMap<String, String>(request.getHeaders()); h.remove(HEADER_METHOD_OVERRIDE); // Simple case, just extract query params from entity, append to query, and clear entity if (contentType.getBaseType().equals(FORM_URL_ENCODED)) { query = request.getEntity().asString(Data.UTF_8_CHARSET); h.remove(HEADER_CONTENT_TYPE); h.remove(CONTENT_LENGTH); } else if (contentType.getBaseType().equals(MULTIPART)) { // Clear these in case there is no body part h.remove(HEADER_CONTENT_TYPE); h.remove(CONTENT_LENGTH); MimeMultipart multi = new MimeMultipart(new DataSource() { @Override public InputStream getInputStream() throws IOException { return request.getEntity().asInputStream(); } @Override public OutputStream getOutputStream() throws IOException { return null; } @Override public String getContentType() { return request.getHeader(HEADER_CONTENT_TYPE); } @Override public String getName() { return null; } }); for (int i = 0; i < multi.getCount(); i++) { MimeBodyPart part = (MimeBodyPart) multi.getBodyPart(i); if (part.isMimeType(FORM_URL_ENCODED) && query == null) { // Assume the first segment we come to that is urlencoded is the tunneled query params query = IOUtils.toString((InputStream) part.getContent(), UTF8); } else if (entity.length <= 0) { // Assume the first non-urlencoded content we come to is the intended entity. entity = IOUtils.toByteArray((InputStream) part.getContent()); h.put(CONTENT_LENGTH, Integer.toString(entity.length)); h.put(HEADER_CONTENT_TYPE, part.getContentType()); } else { // If it's not form-urlencoded and we've already found another section, // this has to be be an extra body section, which we have no way to handle. // Proceed with the request as if the 1st part we found was the expected body, // but log a warning in case some client is constructing a request that doesn't // follow the rules. String unexpectedContentType = part.getContentType(); LOG.warn("Unexpected body part in X-HTTP-Method-Override request, type=" + unexpectedContentType); } } } // Based on what we've found, construct the modified request. It's possible that someone has // modified the request URI, adding extra query params for debugging, tracking, etc, so // we have to check and append the original query correctly. if (query != null && query.length() > 0) { String separator = "&"; String existingQuery = request.getURI().getRawQuery(); if (existingQuery == null) { separator = "?"; } else if (existingQuery.isEmpty()) { // This would mean someone has appended a "?" with no args to the url underneath us separator = ""; } requestBuilder.setURI(new URI(request.getURI().toString() + separator + query)); } requestBuilder.setEntity(entity); requestBuilder.setHeaders(h); requestBuilder.setMethod(request.getHeader(HEADER_METHOD_OVERRIDE)); return requestBuilder.build(); }
From source file:com.evolveum.openicf.lotus.util.DominoUtils.java
public static <T> T getAttributeValue(Map<String, Attribute> attrs, DominoAttribute attr, Class<T> type, T defaultValue, boolean removeFromMap) { Attribute attribute = removeFromMap ? attrs.remove(attr.getName()) : attrs.get(attr.getName()); return getAttributeValue(attribute, type, defaultValue); }
From source file:com.bitbreeds.webrtc.stun.StunMessage.java
/** * @param type {@link StunRequestTypeEnum} * @param cookie see rfc5389//from ww w . j a v a 2 s .com * @param transactionId see rfc5389 * @param attr {@Link StunAttributeTypeEnum} * @return StunMessage to operate on. */ public static StunMessage fromData(StunRequestTypeEnum type, byte[] cookie, byte[] transactionId, Map<StunAttributeTypeEnum, StunAttribute> attr, boolean withIntegrity, boolean withFingerprint, String username, String password) { //attr.add(new StunAttribute(StunAttributeTypeEnum.PASSWORD, password.getBytes())); attr.remove(StunAttributeTypeEnum.MESSAGE_INTEGRITY); attr.remove(StunAttributeTypeEnum.FINGERPRINT); attr.remove(StunAttributeTypeEnum.ICE_CONTROLLING); attr.remove(StunAttributeTypeEnum.USE_CANDIDATE); attr.remove(StunAttributeTypeEnum.PRIORITY); attr.remove(StunAttributeTypeEnum.USERNAME); int lgt = attr.values().stream().map(i -> SignalUtil.multipleOfFour(4 + i.getLength())) //Lengths to multiple of 4 + 4 for lgt and type .reduce(0, Integer::sum); //Sum integers return new StunMessage(new StunHeader(type, lgt, cookie, transactionId), attr, withIntegrity, withFingerprint, username, password); }
From source file:Main.java
private static Manifest getCompositeManifest(Map compositeManifest) { Manifest manifest = new Manifest(); Attributes attributes = manifest.getMainAttributes(); attributes.putValue("Manifest-Version", "1.0"); //$NON-NLS-1$//$NON-NLS-2$ // get the common headers Bundle-ManifestVersion, Bundle-SymbolicName and Bundle-Version // get the manifest version from the map String manifestVersion = (String) compositeManifest.remove(Constants.BUNDLE_MANIFESTVERSION); // here we assume the validation got the correct version for us attributes.putValue(Constants.BUNDLE_MANIFESTVERSION, manifestVersion); // Ignore the Equinox composite bundle header compositeManifest.remove(BaseStorageHook.COMPOSITE_HEADER); attributes.putValue(BaseStorageHook.COMPOSITE_HEADER, BaseStorageHook.COMPOSITE_BUNDLE); for (Iterator entries = compositeManifest.entrySet().iterator(); entries.hasNext();) { Map.Entry entry = (Entry) entries.next(); if (entry.getKey() instanceof String && entry.getValue() instanceof String) attributes.putValue((String) entry.getKey(), (String) entry.getValue()); }//from w ww . j a va 2s. c o m return manifest; }