List of usage examples for java.util Properties get
@Override
public Object get(Object key)
From source file:com.halseyburgund.roundware.server.RWHttpManager.java
public static String doPost(String page, Properties props) throws Exception { HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, CONNECTION_TIMEOUT_MSEC); HttpConnectionParams.setSoTimeout(httpParams, CONNECTION_TIMEOUT_MSEC); HttpClient httpClient = new DefaultHttpClient(httpParams); HttpPost request = new HttpPost(page); HttpResponse response = null;//from ww w. j a v a2s . co m HttpEntity entity = null; StringBuffer sbResponse = new StringBuffer(); Enumeration<Object> enumProps = props.keys(); String key, value = null; List<NameValuePair> nvps = new ArrayList<NameValuePair>(); while (enumProps.hasMoreElements()) { key = (String) enumProps.nextElement(); value = (String) props.get(key); nvps.add(new BasicNameValuePair(key, value)); } UrlEncodedFormEntity uf = new UrlEncodedFormEntity(nvps, HTTP.UTF_8); request.setEntity(uf); request.setHeader("Content-Type", POST_MIME_TYPE); // Post, check and show the result (not really spectacular, but works): response = httpClient.execute(request); entity = response.getEntity(); int status = response.getStatusLine().getStatusCode(); // we assume that the response body contains the error message if (status != HttpStatus.SC_OK) { ByteArrayOutputStream ostream = new ByteArrayOutputStream(); entity.writeTo(ostream); RWHtmlLog.e(TAG, "Error status code = " + status, null); RWHtmlLog.e(TAG, ostream.toString(), null); throw new Exception(HTTP_POST_FAILED + status); } else { InputStream content = response.getEntity().getContent(); // <consume response> BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) sbResponse.append(line); content.close(); // this will also close the connection return sbResponse.toString(); } }
From source file:com.halseyburgund.rwframework.core.RWHttpManager.java
public static String doPost(String page, Properties props, int timeOutSec) throws Exception { HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, timeOutSec * 1000); HttpConnectionParams.setSoTimeout(httpParams, timeOutSec * 1000); HttpClient httpClient = new DefaultHttpClient(httpParams); HttpPost request = new HttpPost(page); HttpResponse response = null;/*from www .j ava 2 s . c o m*/ HttpEntity entity = null; StringBuffer sbResponse = new StringBuffer(); Enumeration<Object> enumProps = props.keys(); String key, value = null; List<NameValuePair> nvps = new ArrayList<NameValuePair>(); while (enumProps.hasMoreElements()) { key = (String) enumProps.nextElement(); value = (String) props.get(key); nvps.add(new BasicNameValuePair(key, value)); } UrlEncodedFormEntity uf = new UrlEncodedFormEntity(nvps, HTTP.UTF_8); request.setEntity(uf); request.setHeader("Content-Type", POST_MIME_TYPE); // Post, check and show the result (not really spectacular, but works): response = httpClient.execute(request); entity = response.getEntity(); int status = response.getStatusLine().getStatusCode(); // we assume that the response body contains the error message if (status != HttpStatus.SC_OK) { ByteArrayOutputStream ostream = new ByteArrayOutputStream(); entity.writeTo(ostream); Log.e(TAG, "Error status code = " + status, null); Log.e(TAG, ostream.toString(), null); throw new HttpException(String.valueOf(status)); } else { InputStream content = response.getEntity().getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) { sbResponse.append(line); } content.close(); // this will also close the connection return sbResponse.toString(); } }
From source file:org.cloudfoundry.identity.uaa.config.EnvironmentPropertiesFactoryBeanTests.java
@Test public void testDefaultProperties() throws Exception { EnvironmentPropertiesFactoryBean factory = new EnvironmentPropertiesFactoryBean(); factory.setDefaultProperties(getProperties("foo=foo")); Properties properties = factory.getObject(); assertEquals("foo", properties.get("foo")); }
From source file:org.cloudfoundry.identity.uaa.config.EnvironmentPropertiesFactoryBeanTests.java
@Test public void testNullProperties() throws Exception { EnvironmentPropertiesFactoryBean factory = new EnvironmentPropertiesFactoryBean(); StandardEnvironment environment = new StandardEnvironment(); environment.getPropertySources()//from ww w . ja v a 2s . c o m .addFirst(new MapPropertySource("foo", Collections.singletonMap("foo", null))); factory.setEnvironment(environment); Properties properties = factory.getObject(); assertEquals("", properties.get("foo")); }
From source file:burlov.ultracipher.swing.SwingGuiApplication.java
/** * Methode sammelt Informationen ueber Systemumgebung * * @return/*from www .j a va 2 s. co m*/ */ static public StringBuilder createSystemInfo() { StringBuilder sb = new StringBuilder(); Properties p = System.getProperties(); for (Object key : p.keySet()) { if (key.toString().endsWith("path")) { continue;//Zu lange Werte werden nicht gebraucht } String value = (String) p.get(key); sb.append(key); sb.append(": "); sb.append(value); sb.append('\n'); } return sb; }
From source file:org.grycap.vmrc.service.ConfigurationService.java
public void createRequiredUsers(Properties p) throws ServiceException { try {/*w w w . ja v a 2s. co m*/ String adminPass = p.get("admin_password") != null ? (String) p.get("admin_password") : "passwd1"; createOrUpdateUser("admin", adminPass, ACL.ADMIN_USER); createOrUpdateUser("anonymous", "", ACL.ANONYMOUS_USER); } catch (Exception e) { throw new ServiceException(e); } }
From source file:com.sonymobile.backlogtool.ApplicationVersion.java
@Autowired public ApplicationVersion(ServletContext context) throws IOException { InputStream in = context.getResourceAsStream("META-INF/maven/com.sonymobile/backlogtool/pom.properties"); Properties props = new Properties(); props.load(in);// ww w . jav a 2 s . co m version = (String) props.get("version"); }
From source file:iristk.util.Record.java
/** * Converts a Properties object into a Record object. * @param prop Properties file with Record data * @return Record/*from w w w .j a va 2 s.c o m*/ */ public static Record fromProperties(Properties prop) { Record rec = new Record(); for (Object key : prop.keySet()) { rec.put(key.toString().replace(".", ":"), prop.get(key)); } return rec; }
From source file:com.cloud.utils.PropertiesUtilsTest.java
@Test public void loadPropertiesFromFile() throws IOException { File file = File.createTempFile("test", ".properties"); FileUtils.writeStringToFile(file, "a=b\nc=d\n"); Properties properties = PropertiesUtil.loadFromFile(file); Assert.assertEquals("b", properties.get("a")); }
From source file:ru.org.linux.auth.SecurityFilter.java
private void CSRFManipulation(HttpServletRequest request, HttpServletResponse response) { Properties cookies = LorHttpUtils.getCookies(request.getCookies()); if (cookies.get(CSRFProtectionService.CSRF_COOKIE) == null) { CSRFProtectionService.generateCSRFCookie(request, response); } else {/* ww w .j a v a 2 s . c om*/ request.setAttribute(CSRFProtectionService.CSRF_ATTRIBUTE, cookies.getProperty(CSRFProtectionService.CSRF_COOKIE).trim()); } response.addHeader("Cache-Control", "private"); }