List of usage examples for org.apache.commons.collections EnumerationUtils toList
public static List toList(Enumeration enumeration)
From source file:org.mule.module.http.functional.requester.AbstractHttpRequestTestCase.java
protected void extractHeadersFromBaseRequest(Request baseRequest) { for (String headerName : (List<String>) EnumerationUtils.toList(baseRequest.getHeaderNames())) { Enumeration<String> headerValues = baseRequest.getHeaders(headerName); while (headerValues.hasMoreElements()) { headers.put(headerName, headerValues.nextElement()); }//from w w w.j ava2 s. c o m } }
From source file:org.mule.transport.servlet.ServletMuleMessageFactory.java
protected void copyHeaders(HttpServletRequest request, Map<String, Object> messageProperties) { for (Enumeration<?> e = request.getHeaderNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); String realKey = key;//from w ww . j a v a2 s . co m if (key.startsWith(HttpConstants.X_PROPERTY_PREFIX)) { realKey = key.substring(2); } // Workaround for containers that strip the port from the Host header. // This is needed so Mule components can figure out what port they're on. if (HttpConstants.HEADER_HOST.equalsIgnoreCase(key)) { realKey = HttpConstants.HEADER_HOST; String value = request.getHeader(key); int port = request.getLocalPort(); if (!value.contains(":") && port != 80 && port != 443) { value = value + ":" + port; } messageProperties.put(realKey, value); } else { Enumeration<?> valueEnum = request.getHeaders(key); List<?> values = EnumerationUtils.toList(valueEnum); if (values.size() > 1) { messageProperties.put(realKey, values.toArray()); } else { messageProperties.put(realKey, values.get(0)); } } } }
From source file:org.omnaest.utils.web.HttpSessionFacadeFactoryTest.java
@SuppressWarnings("unchecked") @Test//from ww w . jav a 2 s. com public void testNewHttpSessionFacade() { // assertNotNull(this.httpSessionFacadeExample); assertNull(this.httpSessionFacadeExample.getFieldDouble()); assertNull(this.httpSessionFacadeExample.getFieldString()); // this.httpSessionFacadeExample.setFieldDouble(1.345d); this.httpSessionFacadeExample.setFieldString("testValue"); this.httpSessionFacadeExample.setOtherField("a value"); // assertNotNull(this.httpSessionFacadeExample.getFieldDouble()); assertNotNull(this.httpSessionFacadeExample.getFieldString()); assertNotNull(this.httpSessionFacadeExample.getOtherField()); assertEquals(1.345d, this.httpSessionFacadeExample.getFieldDouble(), 0.01); assertEquals("testValue", this.httpSessionFacadeExample.getFieldString()); assertEquals("a value", this.httpSessionFacadeExample.getOtherField()); // assertEquals(new ArrayList<String>(Arrays.asList("fieldDouble", "fieldString", "OTHERFIELD")), new ArrayList<String>(EnumerationUtils.toList(this.httpSession.getAttributeNames()))); }
From source file:org.omnaest.utils.web.HttpSessionToMapAdapter.java
@SuppressWarnings("unchecked") @Override//from w w w . j av a 2 s . c o m public Set<String> keySet() { return new LinkedHashSet<String>(EnumerationUtils.toList(this.httpSession.getAttributeNames())); }
From source file:org.openengsb.core.test.AbstractOsgiMockServiceTest.java
private <T> ServiceReference<T> putService(T service, Dictionary<String, Object> props) { @SuppressWarnings("unchecked") ServiceReference<T> serviceReference = mock(ServiceReference.class); long serviceId = --this.serviceId; LOGGER.info("registering service with ID: " + serviceId); props.put(Constants.SERVICE_ID, serviceId); services.put(serviceReference, service); synchronized (serviceReferences) { serviceReferences.put(serviceReference, props); }/* w ww.ja v a2 s. co m*/ when(serviceReference.getProperty(anyString())).thenAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { return serviceReferences.get(invocation.getMock()).get(invocation.getArguments()[0]); } }); when(serviceReference.getBundle()).thenReturn(bundle); when(serviceReference.getPropertyKeys()).thenAnswer(new Answer<String[]>() { @Override public String[] answer(InvocationOnMock invocation) throws Throwable { Dictionary<String, Object> dictionary = serviceReferences.get(invocation.getMock()); List<?> list = EnumerationUtils.toList(dictionary.keys()); @SuppressWarnings("unchecked") Collection<String> typedCollection = CollectionUtils.typedCollection(list, String.class); return typedCollection.toArray(new String[0]); } }); return serviceReference; }
From source file:org.openengsb.core.util.DictonaryUtilTest.java
@Test public void wrapMapToDictionary_shouldWrapMapAsDictionary() throws Exception { Map<String, String> testMap = new HashMap<String, String>(); testMap.put("test", "42"); testMap.put("foo", "bar"); Dictionary<String, String> dict = MapAsDictionary.wrap(testMap); @SuppressWarnings("unchecked") List<String> list = EnumerationUtils.toList(dict.elements()); assertThat(list, hasItems("42", "bar")); }
From source file:org.samlsnort.util.KeyStoreTool.java
@SuppressWarnings("unchecked") public static List<String> getAliases() { LOGGER.entering(KeyStoreTool.class.getName(), "getAliases"); List<String> result = new LinkedList<String>(); try {//from w w w . j av a 2 s.c o m result.addAll(EnumerationUtils.toList(keyStore.aliases())); } catch (Exception e) { LOGGER.log(Level.WARNING, "Error while reading aliases.", e); } LOGGER.exiting(KeyStoreTool.class.getName(), "getAliases", result); return result; }
From source file:org.siphon.jssp.JsspSession.java
public int size() { return EnumerationUtils.toList(session.getAttributeNames()).size(); }
From source file:org.springframework.faces.mvc.servlet.FacesHandlerAdapterTests.java
public void testDelegatingServletConfig() throws Exception { Properties initParameters = new Properties(); initParameters.setProperty("testkey", "testvalue"); ServletContext servletContext = (ServletContext) EasyMock.createMock(ServletContext.class); adapter.setInitParameters(initParameters); adapter.setServletContext(servletContext); adapter.setOverrideInitParameters(false); adapter.setFacesServletClass(MockServlet.class); adapter.afterPropertiesSet();/*from w w w . ja va 2s.c om*/ MockServlet servlet = (MockServlet) adapter.getFacesServlet(); ServletConfig config = servlet.getServletConfig(); assertTrue(EnumerationUtils.toList(config.getInitParameterNames()).contains("testkey")); assertEquals("testvalue", config.getInitParameter("testkey")); assertEquals("testAdapterBean", config.getServletName()); assertSame(servletContext, config.getServletContext()); }
From source file:org.xwiki.localization.jar.internal.RootClassLoaderTranslationBundle.java
/** * @param locale the locale to search for * @return the content of all the resources files associated to the provided locale *//* w ww . ja va 2 s . c o m*/ private Properties getResourceProperties(Locale locale) { String resourceName = "ApplicationResources"; if (!locale.equals(Locale.ROOT)) { resourceName += "_" + locale; } resourceName += ".properties"; Enumeration<URL> urls; try { urls = getClass().getClassLoader().getResources(resourceName); } catch (IOException e) { this.logger.error("Failed to get resource URLs from class loader for name [{}]", resourceName, e); return null; } if (!urls.hasMoreElements()) { return null; } List<URL> urlList = EnumerationUtils.toList(urls); Properties properties = new Properties(); // Load resources in reverse order to give priority to first found resources (follow ClassLoader#getResource // behavior) for (ListIterator<URL> it = urlList.listIterator(urlList.size()); it.hasPrevious();) { URL url = it.previous(); try { InputStream componentListStream = url.openStream(); try { properties.load(componentListStream); } finally { componentListStream.close(); } } catch (IOException e) { this.logger.error("Failed to parse resource [{}] as translation budle", url, e); } } return properties; }