List of usage examples for java.lang System getenv
public static java.util.Map<String, String> getenv()
From source file:org.workspace7.moviestore.controller.HomeController.java
@GetMapping("/") public ModelAndView home(ModelAndView modelAndView, HttpServletRequest request) { final String hostname = System.getenv().getOrDefault("HOSTNAME", "unknown"); log.info("Request served by HOST {} ", hostname); HttpSession session = request.getSession(false); List<Movie> movies = movieDBHelper.getAll(); List<MovieCartItem> movieList = movies.stream() .map((Movie movie) -> MovieCartItem.builder().movie(movie).quantity(1).total(0).build()) .collect(Collectors.toList()); if (session != null) { AdvancedCache<String, Object> sessionCache = (AdvancedCache<String, Object>) cacheManager .getCache("moviestore-sessions-cache").getNativeCache(); Optional<MapSession> mapSession = Optional.ofNullable((MapSession) sessionCache.get(session.getId())); log.info("Session already exists, retrieving values from session {}", mapSession); int cartCount = 0; if (mapSession.isPresent()) { MovieCart movieCart = mapSession.get().getAttribute(ShoppingCartController.SESSION_ATTR_MOVIE_CART); if (movieCart != null) { log.info("Movie Cart:{} for session id:{}", movieCart, session.getId()); final Map<String, Integer> movieItems = movieCart.getMovieItems(); movieList = movieList.stream().map(movieCartItem -> { Movie movie = movieCartItem.getMovie(); String movieId = movie.getId(); if (movieItems.containsKey(movieId)) { int quantity = movieItems.get(movieId); movieCartItem.setQuantity(quantity); } else { movieCartItem.setQuantity(1); }//from w w w . j a v a 2 s.c o m return movieCartItem; }).collect(Collectors.toList()); cartCount = movieItems.size(); } } modelAndView.addObject("cartCount", cartCount); modelAndView.addObject("movies", movieList); } else { log.info("New Session"); modelAndView.addObject("movies", movieList); } modelAndView.setViewName("home"); modelAndView.addObject("hostname", hostname); return modelAndView; }
From source file:com.google.mr4c.hadoop.HadoopUtils.java
/** * @param varMap apply environment variable values from this map * @param vars apply existing values of these environment variables *//* w ww . jav a 2 s .co m*/ public static void applyEnvironmentVariables(JobConf conf, Map<String, String> varMap, List<String> vars) { Map<String, String> allMap = new HashMap<String, String>(System.getenv()); allMap.keySet().retainAll(vars); // only the env we wanted allMap.putAll(varMap); List<String> assigns = new ArrayList<String>(); for (String var : allMap.keySet()) { String val = allMap.get(var); if (!StringUtils.isEmpty(val)) { assigns.add(var + "=" + val); } } String value = StringUtils.join(assigns, ", "); conf.set(JobConf.MAPRED_MAP_TASK_ENV, value); conf.set(JobConf.MAPRED_REDUCE_TASK_ENV, value); }
From source file:com.cloudera.sqoop.util.Executor.java
/** * @return An array formatted correctly for use as an envp based on the * current environment for this program. *//*from w w w .j a v a2s . c o m*/ public static List<String> getCurEnvpStrings() { Map<String, String> curEnv = System.getenv(); ArrayList<String> array = new ArrayList<String>(); if (null == curEnv) { return null; } for (Map.Entry<String, String> entry : curEnv.entrySet()) { array.add(entry.getKey() + "=" + entry.getValue()); } return array; }
From source file:com.github.fedorchuck.webstore.config.DataConfig.java
@Autowired public void setResourceLoader(ResourceLoader resourceLoader) { this.resourceLoader = resourceLoader; Map<String, String> env = System.getenv(); if (env.get("DATABASE_URL") != null) { getConfigEnv(env);// w ww .ja va 2s .co m } else { getConfig(); readConfig(); } }
From source file:org.example.SimpleRestClientTestCase.java
@Deployment(testable = false) public static WebArchive create() { boolean isNotJBoss = !"jbossas7".equals(System.getenv().get("arquillian.target")); if (isNotJBoss) { return ShrinkWrap.create(WebArchive.class).addAsLibraries(resolveDependencies()) .addClasses(Customer.class, CustomerResource.class, CustomerResourceImpl.class, JaxRsActivator.class) .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml").setWebXML("in-container-web.xml"); } else {/*from w ww . java 2 s.c om*/ return ShrinkWrap .create(WebArchive.class).addClasses(Customer.class, CustomerResource.class, CustomerResourceImpl.class, JaxRsActivator.class) .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); } }
From source file:com.redhat.developers.msa.ola.OlaController.java
@CrossOrigin @RequestMapping(method = RequestMethod.GET, value = "/ola", produces = "text/plain") @ApiOperation("Returns the greeting in Portuguese") public String ola() { String hostname = System.getenv().getOrDefault("HOSTNAME", "Unknown"); return String.format("Ol de %s", hostname); }
From source file:org.focusns.service.env.impl.EnvironmentServiceImpl.java
protected Environment lookupJava() { if (envJava == null) { Properties props = System.getProperties(); Map<String, String> env = System.getenv(); ///* w w w .j ava 2 s . c o m*/ envJava = new EnvironmentJava(); envJava.setJavaVendor(props.getProperty("java.vendor")); envJava.setJavaVersion(props.getProperty("java.version")); envJava.setJavaHome(env.get("JAVA_HOME")); envJava.setJavaOptions(env.get("JAVA_OPTS")); envJava.setJavaClassPath(props.getProperty("java.class.path")); envJava.setJavaLibraryPath(props.getProperty("java.library.path")); envJava.setJavaRuntimeName(props.getProperty("java.runtime.name")); envJava.setJavaRuntimeVersion(props.getProperty("java.runtime.version")); // envJava.setJavaVMName(props.getProperty("java.vm.name")); envJava.setJavaVMVendor(props.getProperty("java.vm.vendor")); envJava.setJavaVMVersion(props.getProperty("java.vm.version")); envJava.setJavaVMInfo(props.getProperty("java.vm.info")); } // return envJava; }
From source file:net.lmxm.ute.configuration.ConfigurationInterpolator.java
/** * Generate property maps.//w ww. ja v a 2 s .c o m * * @param configuration the configuration * @return the map */ private static Map<PropertyType, String[]> generatePropertyMaps(final Configuration configuration) { final String prefix = "generatePropertyMaps() :"; LOGGER.debug("{} entered, configuration={}", prefix, configuration); final List<String> propertyNames = new ArrayList<String>(); final List<String> propertyValues = new ArrayList<String>(); for (final Preference preference : configuration.getPreferences()) { propertyNames.add("${pref." + preference.getId() + "}"); propertyValues.add(StringUtils.trimToEmpty(preference.getValue())); } for (final Property property : configuration.getProperties()) { propertyNames.add("${" + property.getId() + "}"); propertyValues.add(StringUtils.trimToEmpty(property.getValue())); } for (final Entry<String, String> entry : System.getenv().entrySet()) { propertyNames.add("${env." + entry.getKey() + "}"); propertyValues.add(StringUtils.trimToEmpty(entry.getValue())); } final Map<PropertyType, String[]> propertyMaps = new HashMap<PropertyType, String[]>(); propertyMaps.put(PropertyType.NAME, propertyNames.toArray(new String[0])); propertyMaps.put(PropertyType.VALUE, propertyValues.toArray(new String[0])); LOGGER.debug("{} returning {}", prefix, propertyMaps); return propertyMaps; }
From source file:org.sonar.runner.Main.java
public static void main(String[] args) { //Jenkins' user build vars plugin must be set. String buildUserId = (String) System.getenv().get("BUILD_USER_ID"); if (buildUserId == null || buildUserId.length() == 0) { buildUserId = DEFAULT_BUILD_USERID; }//www . jav a 2 s . com System.setProperty("build.user.id", buildUserId); Cli cli = new Cli().parse(args); Main main = new Main(new Exit(), cli, new Conf(cli), new RunnerFactory()); main.execute(); }
From source file:org.smigo.config.WebAppInitializer.java
@Override protected void beforeSpringSecurityFilterChain(ServletContext servletContext) { super.beforeSpringSecurityFilterChain(servletContext); log.info("Starting servlet context"); log.info("contextName: " + servletContext.getServletContextName()); log.info("contextPath:" + servletContext.getContextPath()); log.info("effectiveMajorVersion:" + servletContext.getEffectiveMajorVersion()); log.info("effectiveMinorVersion:" + servletContext.getEffectiveMinorVersion()); log.info("majorVersion:" + servletContext.getMajorVersion()); log.info("minorVersion:" + servletContext.getMinorVersion()); log.info("serverInfo:" + servletContext.getServerInfo()); // ", virtualServerName:" + servletContext.getVirtualServerName() + log.info("toString:" + servletContext.toString()); for (Enumeration<String> e = servletContext.getAttributeNames(); e.hasMoreElements();) { log.info("Attribute:" + e.nextElement()); }//from ww w . ja v a 2 s.c o m for (Map.Entry<String, String> env : System.getenv().entrySet()) { log.info("System env:" + env.toString()); } for (Map.Entry<Object, Object> prop : System.getProperties().entrySet()) { log.info("System prop:" + prop.toString()); } final String profile = System.getProperty("smigoProfile", EnvironmentProfile.PRODUCTION); log.info("Starting with profile " + profile); WebApplicationContext context = new AnnotationConfigWebApplicationContext() { { register(WebConfiguration.class); setDisplayName("SomeRandomName"); getEnvironment().setActiveProfiles(profile); } }; FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("CharacterEncodingFilter", new CharacterEncodingFilter()); characterEncodingFilter.setInitParameter("encoding", "UTF-8"); characterEncodingFilter.setInitParameter("forceEncoding", "true"); characterEncodingFilter.addMappingForUrlPatterns(null, false, "/*"); servletContext.addListener(new RequestContextListener()); servletContext.addListener(new ContextLoaderListener(context)); //http://stackoverflow.com/questions/4811877/share-session-data-between-2-subdomains // servletContext.getSessionCookieConfig().setDomain(getDomain()); DispatcherServlet dispatcherServlet = new DispatcherServlet(context); dispatcherServlet.setThrowExceptionIfNoHandlerFound(false); servletContext.addServlet("dispatcher", dispatcherServlet).addMapping("/"); }