protected void doPost(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   HttpSession session = request.getSession();
   String state = (String) session.getAttribute("state");
   if (state == null) {
     state = new BigInteger(130, new SecureRandom()).toString(32);
     request.getSession().setAttribute("state", state);
   }
   File test = new File("test.txt");
   Logger.getAnonymousLogger().warning("Path to test file: " + test.getAbsolutePath());
   GoogleApiClientDAO googleApiClientDAO = new GoogleApiClientDAO();
   GoogleApiClient googleApiClient = googleApiClientDAO.get();
   String script =
       new Scanner(new File("WEB-INF/resources/helper.js"), "UTF-8")
           .useDelimiter("\\A")
           .next()
           .replaceAll("[{]{2}\\s*CLIENT_ID\\s*[}]{2}", googleApiClient.getId())
           .replaceAll("[{]{2}\\s*STATE\\s*[}]{2}", state)
           .replaceAll("[{]{2}\\s*APPLICATION_NAME\\s*[}]{2}", APPLICATION_NAME);
   response.setContentType("text/javascript");
   PrintWriter pw = response.getWriter();
   pw.write(script);
   pw.write("\n\n\n\n");
   pw.flush();
   pw.close();
 }
Пример #2
0
 private void createTables() {
   Connection connection = null;
   Statement statement = null;
   try {
     connection = getConnection();
     statement = connection.createStatement();
     statement.execute("drop table if exists agent");
     statement.execute(
         "create table agent (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, username varchar(20), "
             + "emailaddress varchar(132), name varchar(132), city varchar(50), state char(2), "
             + "zipcode varchar(9),  latitude DECIMAL(18,12), longitude DECIMAL(18,12), level smallint, "
             + "profileid char(21), imageurl varchar(132), role smallint, vetted char(1)) ");
     statement.execute("create unique index agent1 on agent (emailaddress)");
     statement.execute("create unique index agent2 on agent (profileid)");
     statement.execute("drop table if exists googleapiclient");
     statement.execute("create table googleapiclient (id varchar(132), secret varchar(50))");
     statement.execute("drop table if exists geocache");
     statement.execute(
         "create table geocache "
             + "(query varchar(132) primary key, latitude DECIMAL(18,12), longitude DECIMAL(18,12), "
             + "formatted_address varchar(256) ,city varchar(50), state char(2), zipcode char(9) )");
     statement.execute("drop table if exists comment");
     statement.execute(
         "create table comment (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, commenttype smallint, commenttext varchar(256), emailaddress varchar(132), logtime timestamp)");
     statement.execute("create index comment1 on comment (emailaddress)");
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     close(statement, connection);
   }
   GoogleApiClientDAO googleApiClientDAO = new GoogleApiClientDAO();
   GoogleApiClient googleApiClient = new GoogleApiClient();
   googleApiClient.setId(properties.getProperty("googleapiclientid"));
   googleApiClient.setSecret(properties.getProperty("googleapisecret"));
   googleApiClientDAO.insert(googleApiClient);
 }