Example usage for java.lang System getenv

List of usage examples for java.lang System getenv

Introduction

In this page you can find the example usage for java.lang System getenv.

Prototype

public static String getenv(String name) 

Source Link

Document

Gets the value of the specified environment variable.

Usage

From source file:org.jtheque.movies.services.impl.FFMpegServiceTest.java

@Before
public void setUp() {
    BeanUtils.set(moviesModule, "config", new MovieConfiguration());
    BeanUtils.set(core, "application", new MoviesModuleTest.EmptyApplication());

    moviesModule.getConfig().setFFmpegLocation(System.getenv("FFMPEG_HOME"));
    testFolder = System.getenv("JTHEQUE_TESTS");
}

From source file:com.github.moscaville.contactsdb.controller.BaseController.java

public BaseController() {
    restTemplate = new RestTemplate();
    interceptors = new ArrayList<>();
    String envValue = System.getenv("AIRTABLE_ENDPOINT_URL");
    AIRTABLE_ENDPOINT_URL = envValue + (envValue != null && envValue.endsWith("/") ? "" : "/");
}

From source file:com.mycompany.barbershop.Appointment.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from w ww .  j a v a  2 s  .c  o  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    String DB_URL = null;

    // Detect if we are on openshift or local environment.
    String db_host = System.getenv("OPENSHIFT_MYSQL_DB_HOST");
    if (db_host != null) {
        String db_port = System.getenv("OPENSHIFT_MYSQL_DB_PORT");
        DB_URL = "jdbc:mysql://" + db_host + ":" + db_port + "/barbershop";
    } else {
        DB_URL = "jdbc:mysql://127.0.0.1/barbershop";
    }

    String USER = "admint7Jze9t";
    String PASS = "5kkJlvZVANR9";

    Connection conn = null;
    Statement stmt = null;

    try {
        //STEP 2: Register JDBC driver
        Class.forName("com.mysql.jdbc.Driver");

        //STEP 3: Open a connection
        conn = DriverManager.getConnection(DB_URL, USER, PASS);

        //STEP 4: Execute a query
        stmt = conn.createStatement();

        //Query to get barber id
        int barber_id = 0;
        String barber_name = (String) request.getParameter("barber");
        String sql = "SELECT * FROM barber_table WHERE name = '" + barber_name + "';";
        ResultSet rs = stmt.executeQuery(sql);
        while (rs.next()) {
            barber_id = rs.getInt("barber_id");
        }

        String day = (String) request.getParameter("day");
        String time = (String) request.getParameter("time");
        String type = (String) request.getParameter("type");
        String user_id = (String) request.getSession().getAttribute("user_id");

        //Check to see if an appointent is already made for that barber at that time
        sql = "select * from appointment_table where barber_id ='" + barber_id + "' and start_time ='" + time
                + "' and date ='" + day + "';";
        rs = stmt.executeQuery(sql);

        if (rs.next()) {
            request.setAttribute("appointmentError", "Scheduling conflict. Please schedule another time");
            request.getRequestDispatcher("/home.jsp").forward(request, response);

        } else {
            sql = "INSERT INTO appointment_table(barber_id, user_id, start_time, date)" + "VALUES (" + barber_id
                    + ", " + user_id + ", '" + time + "', '" + day + "')";
        }

        stmt.executeUpdate(sql);

        HttpSession session = request.getSession(false);
        String name = (String) session.getAttribute("name");
        request.setAttribute("appointmentMessage", "Appointment successfully created for " + name + " with "
                + barber_name + " for a " + type + " at " + time + " on " + day);

        //TEXTING API
        //            String firstName = (String) request.getSession().getAttribute("name");
        //           request.setAttribute("appointmentMessage", "Appointment successfully created for " + firstName + " with " + barber_name + " for a " + type + " at " + time + " on " + day);
        //           
        //           
        //           String phonenum = "";
        //           sql = "SELECT * FROM user_table WHERE firstName='" + firstName + "';";
        //           rs = stmt.executeQuery(sql);
        //           while (rs.next()) {
        //               phonenum = rs.getString("phone");
        //           }
        //           
        //           TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
        //
        //           // Build a filter for the MessageList
        //           List<NameValuePair> params = new ArrayList<>();
        //           params.add(new BasicNameValuePair("Body", "Thank you for choosing Graffitti! "
        //                   + "Your next appointment will be on " + day + " at " + time + "."));
        //           params.add(new BasicNameValuePair("To", "+1" + phonenum));
        //           params.add(new BasicNameValuePair("From", "+19784345321"));
        //
        //           MessageFactory messageFactory = client.getAccount().getMessageFactory();
        //           Message message = messageFactory.create(params);
        request.getRequestDispatcher("/home.jsp").forward(request, response);

    } catch (SQLException se) {
        //Handle errors for JDBC
        se.printStackTrace();
    } catch (Exception e) {
        //Handle errors for Class.forName
        e.printStackTrace();
    } finally {
        //finally block used to close resources
        try {
            if (stmt != null) {
                conn.close();
            }
        } catch (SQLException se) {
        } // do nothing
        try {
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException se) {
            se.printStackTrace();
        } //end finally try
    } //end try
}

From source file:com.spectralogic.ds3cli.ClientFactory.java

private static String getOptionOrEnv(final Arguments arguments, final Option option, final String envName)
        throws MissingOptionException {
    String value = arguments.getOptionValue(option.getOpt());
    if (Guard.isStringNullOrEmpty(value)) {
        value = System.getenv(envName);
        if (Guard.isStringNullOrEmpty(value)) {
            throw new MissingOptionException(
                    "Missing Endpoint: define " + envName + "or use " + option.getOpt());
        }/*from  ww  w .  j  a  va 2s.  c o m*/
    }
    return value;
}

From source file:edu.duke.cabig.c3pr.web.admin.StudySubjectXMLFileUploadController.java

@Override
protected ModelAndView onSubmit(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
        Object command, BindException errors) throws Exception {
    // save it to session
    FileBean xMLFile = (FileBean) command;
    String filePath = System.getenv("CATALINA_HOME") + System.getProperty("file.separator") + "conf"
            + System.getProperty("file.separator") + "c3pr";
    File outputXMLDir = new File(filePath);
    outputXMLDir.mkdirs();//from   w  ww.ja v a2 s .co m
    String fileName = "importRegistration-output-" + new Date().getTime() + ".xml";
    File outputXMLFile = new File(filePath + System.getProperty("file.separator") + fileName);
    outputXMLFile.createNewFile();
    try {
        Collection<StudySubject> studySubjects = studySubjectXMLImporterService
                .importStudySubjects(xMLFile.getInputStream(), outputXMLFile);
        Object viewData = studySubjectXMLFileAjaxFacade.getTable(null, httpServletRequest, studySubjects);
        httpServletRequest.setAttribute("registrations", viewData);
        httpServletRequest.setAttribute("filePath", fileName);
    } catch (C3PRCodedException e1) {
        e1.printStackTrace();
        log.debug("Uploaded file contains invalid registration");
        errors.reject("Could not import registrations " + e1.getCodedExceptionMesssage());
    } catch (Exception e1) {
        e1.printStackTrace();
        log.debug("Uploaded file contains invalid registration");
        errors.reject("Could not import registrations " + e1.getMessage());
    }

    return new ModelAndView(this.getSuccessView(), errors.getModel());
}

From source file:com.thoughtworks.go.buildsession.ExecCommandExecutorTest.java

@Test
void execUseSystemEnvironmentVariables() {
    runBuild(execEchoEnv(pathSystemEnvName()), Passed);
    assertThat(console.output()).isEqualTo(System.getenv(pathSystemEnvName()));
}

From source file:com.github.lynxdb.server.common.CassandraConfig.java

@Override
protected String getContactPoints() {
    return System.getenv("cassandra_contactpoints");
}

From source file:org.zanata.sync.jobs.system.ResourceProducer.java

private static boolean isGitExecutableOnPath() {
    String tryNativeGit = System.getenv(TRY_NATIVE_GIT);
    if (Boolean.parseBoolean(tryNativeGit)) {
        Pattern pattern = Pattern.compile(Pattern.quote(File.pathSeparator));
        return pattern.splitAsStream(System.getenv("PATH")).map(Paths::get)
                .anyMatch(path -> Files.exists(path.resolve("git")));
    }/*from  w  w  w  . j av  a  2s  .  c o  m*/
    return false;
}

From source file:com.ijuru.ijambo.Context.java

/**
 * Connects to the database/*  w w w . j a  va2s  .c  om*/
 * @return the Mongo DB
 * @throws ParseException
 * @throws UnknownHostException
 */
public static DB connectDatabase() throws ParseException, UnknownHostException {

    // Check for AppFog environment
    String appFogEnv = System.getenv("VCAP_SERVICES");

    if (appFogEnv != null) {
        // Connect to MongoDB as AppFog service
        JSONParser parser = new JSONParser();
        JSONObject svcs = (JSONObject) parser.parse(appFogEnv);
        JSONArray mongoSettings = (JSONArray) svcs.get("mongodb-1.8");
        JSONObject mongoSettings0 = (JSONObject) mongoSettings.get(0);
        JSONObject mongoCreds0 = (JSONObject) mongoSettings0.get("credentials");
        //String db = (String)mongoCreds0.get("db");
        String connectionURL = (String) mongoCreds0.get("url");

        log.info("Running as AppFog instance with connection URL: " + connectionURL);

        DB db = new MongoURI(connectionURL).connectDB();

        // https://jira.mongodb.org/browse/JAVA-436
        db.authenticate((String) mongoCreds0.get("username"),
                ((String) mongoCreds0.get("password")).toCharArray());

        return db;
    }

    // Create default MongoDB instance
    m = new Mongo();
    return m.getDB("ijambo");
}

From source file:com.appdynamics.cloudfoundry.appdservicebroker.catalog.CatalogFactory.java

@Bean
//Catalog catalog(@Value("${serviceBroker.serviceId}") String serviceId,
//                @Value("${serviceBroker.planId}") String planId) throws ParseException{
Catalog catalog() throws ParseException {
    // @formatter:off
    return new Catalog().service().id(UUIDGenerator.generateServiceID()).name("appdynamics")
            .description("See How Your Apps Are Performing").bindable(true)
            .tags("appdynamics", "apm", "mobile real-user monitoring", "browser real-user monitoring",
                    "database monitoring", "server monitoring", "application analytics")
            .metadata().displayName("AppDynamics")
            .imageUrl(URI.create("http://pbs.twimg.com/profile_images/618576522677350400/jfkiwN8N_normal.png"))
            .longDescription(//from  w  w  w .j a  va 2  s.co m
                    "AppDynamics - One platform for unified monitoring, devops collaboration, and application analytics.")
            .providerDisplayName("AppDynamics Inc.")
            .documentationUrl(URI.create("https://docs.appdynamics.com"))
            .supportUrl(URI.create("http://www.appdynamics.com/support/")).and()
            .addAllPlans(System.getenv("APPD_PLANS")).and();
    // @formatter:on
}