List of usage examples for org.apache.commons.configuration ConfigurationException printStackTrace
public void printStackTrace()
From source file:ch.epfl.lsir.xin.algorithm.baseline.GlobalAverage.java
/** * constructor/* ww w. jav a2s . co m*/ * @param: training ratings * @param: read a saved model or not * @param: file of a saved model * */ public GlobalAverage(RatingMatrix ratingMatrix, boolean readModel, String file) { //set configuration file for parameter setting. config.setFile(new File(".//conf//GlobalMean.properties")); try { config.load(); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } this.ratingMatrix = ratingMatrix; if (readModel)//read model from a local file { readModel(file); } }
From source file:gov.va.chir.tagline.beans.Configuration.java
public Configuration(final String filename) { this.filename = filename; // Load configuration file try {//from ww w . j a va 2s. c om config = new PropertiesConfiguration(filename); } catch (ConfigurationException e) { config = null; e.printStackTrace(); } }
From source file:com.squarecash4glass.servlet.AuthFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { if (response instanceof HttpServletResponse && request instanceof HttpServletRequest) { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; if (httpRequest.getParameter("authToken") != null) { httpRequest.getSession().setAttribute("authToken", httpRequest.getParameter("authToken")); }/*from w w w. j a v a2 s .c om*/ // skip auth for static content, middle of auth flow, notify servlet if (httpRequest.getRequestURI().startsWith("/static") || httpRequest.getRequestURI().equals("/oauth2callback") || httpRequest.getRequestURI().equals("/oauth2callbacksquare") || httpRequest.getRequestURI().equals("/oauth2callbackdwolla") || httpRequest.getRequestURI().equals("/oauth2callbackvenmo") || httpRequest.getRequestURI().equals("/favicon.ico") || httpRequest.getRequestURI().equals("/script/jquery-2.1.1.js") || httpRequest.getRequestURI().equals("/SquareAuth.jsp") || httpRequest.getRequestURI().startsWith("/rest") || httpRequest.getRequestURI().contains("/_ah")) { LOG.info("Skipping auth check for certain urls"); filterChain.doFilter(request, response); return; } LOG.info("Checking to see if authorized by google"); // TODO get Token OAuth2Util oAuth2Utilgoogle = null; try { oAuth2Utilgoogle = Oauth2Factory.getOauth2Util("google", "sandbox"); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); throw new IOException(e); } String userid = oAuth2Utilgoogle.getUserId(httpRequest); if (userid == null || oAuth2Utilgoogle.getCredentialFromStore((userid)) == null || oAuth2Utilgoogle.getCredentialFromStore(userid).getAccessToken() == null) { // redirect to auth flow httpResponse.sendRedirect(WebUtil.buildUrl(httpRequest, "/oauth2callback")); return; } // check dwolla is authenticated LOG.info("Checking to see if authorized by dwolla"); if (userid == null || oAuth2Utilgoogle.getCredentialFromStore(userid + "dwolla") == null || oAuth2Utilgoogle.getCredentialFromStore(userid + "dwolla").getAccessToken() == null) { // redirect to auth flow httpResponse.sendRedirect(WebUtil.buildUrl(httpRequest, "/oauth2callbackdwolla")); return; } // check dwolla is authenticated LOG.info("Checking to see if authorized by venmo"); if (userid == null || oAuth2Utilgoogle.getCredentialFromStore(userid + "venmo") == null || oAuth2Utilgoogle.getCredentialFromStore(userid + "venmo").getAccessToken() == null) { // redirect to auth flow httpResponse.sendRedirect(WebUtil.buildUrl(httpRequest, "/oauth2callbackvenmo")); return; } // Things checked out OK :) LOG.info("User logged in, skipping filter"); filterChain.doFilter(request, response); } else { LOG.warning("Unexpected non HTTP servlet response. Proceeding anyway."); filterChain.doFilter(request, response); } }
From source file:main.java.workload.Workload.java
protected Workload(String file) { setFile_name(file);/*from w ww.j a va 2 s . c o m*/ BufferedReader config_file = null; AbstractFileConfiguration parameters = null; try { config_file = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(getFile_name()))); Global.LOGGER .info("Configuration file " + getFile_name() + " is found under src/main/resources and read."); //Load configuration parameters parameters = new PropertiesConfiguration(); parameters.load(config_file); //Read the number of tables and types of transactions tbl = parameters.getInt("tables"); tr_types = parameters.getInt("transaction.types"); Global.LOGGER.info("Number of database tables: " + tbl); Global.LOGGER.info("Types of workload transactions: " + tr_types); } catch (ConfigurationException e) { e.printStackTrace(); } finally { if (config_file != null) { try { config_file.close(); } catch (IOException e) { e.printStackTrace(); } } } //Initialize other variables this.warmingup = false; this.tbl_types = new HashMap<Integer, Integer>(); this.schema = new HashMap<Integer, ArrayList<Integer>>(); this.tr_proportions = new HashMap<Integer, Double>(); this.tr_tuple_distributions = new HashMap<Integer, ArrayList<Integer>>(); this.tr_changes = new HashMap<Integer, ArrayList<Integer>>(); this._cache = new HashMap<Integer, ArrayList<Integer>>(); this._cache_keys = new ArrayList<Integer>(); this._cache_id = 0; }
From source file:com.squarecash4glass.servlet.OAuth2AuthorizationServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { String provider = getProvider(req); LOG.info("in oauth flow for: " + provider); Configuration oauthConfiguration; try {//from w w w. ja va 2s. co m oauthConfiguration = Oauth2Factory.getOauth2Configuration(provider, "sandbox"); } catch (ConfigurationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); throw new ServletException(e1); } OAuth2Util oAuth2Util = Oauth2Factory.getOauth2Util(oauthConfiguration); if (req.getParameter("error") != null) { LOG.severe("Something went wrong during auth: " + req.getParameter("error")); res.setContentType("text/plain"); res.getWriter().write("Something went wrong during auth. Please check your log for details"); return; } // If we have a code, finish the OAuth 2.0 dance if (req.getParameter("code") != null) { LOG.info("Got a code. Attempting to exchange for access token."); TokenResponse tokenResponse = null; AuthorizationCodeFlow flow = oAuth2Util.newAuthorizationCodeFlow(); try { tokenResponse = flow.newTokenRequest(req.getParameter("code")) .setRedirectUri(WebUtil.buildUrl(req, oauthConfiguration.getString("oauthcallback"))) .execute(); } catch (TokenResponseException e) { LOG.severe("exception getting token: " + e.getMessage()); throw e; } LOG.info("tokenResponse: " + tokenResponse); if ("google".equals(provider)) { // Extract the Google User ID from the ID token in the auth response Payload googlePayload = ((GoogleTokenResponse) tokenResponse).parseIdToken().getPayload(); String userId = googlePayload.getSubject(); String email = googlePayload.getEmail(); req.getSession().setAttribute("userId", userId); User user = new User(userId, email); ofy().save().entities(user).now(); LOG.info("Code exchange worked. User " + userId + " logged in."); } String userid = OAuth2Util.getUserId(req); flow.createAndStoreCredential(tokenResponse, userid + oauthConfiguration.getString("useridPostfix")); // Redirect back to index res.sendRedirect(WebUtil.buildUrl(req, "/main")); return; } // Else, we have a new flow. Initiate a new flow. LOG.info("No auth context found. Kicking off a new dwolla auth flow."); AuthorizationCodeFlow flow = oAuth2Util.newAuthorizationCodeFlow(); GenericUrl url = flow.newAuthorizationUrl() .setRedirectUri(WebUtil.buildUrl(req, oauthConfiguration.getString("oauthcallback"))); adjustURL(provider, url); LOG.info("redirecting to URL: " + url.build()); res.sendRedirect(url.build()); }
From source file:ch.epfl.lsir.xin.algorithm.baseline.MostPopular.java
/** * constructor//from w w w . j a v a 2 s . c o m * @param: input dataset * */ public MostPopular(RatingMatrix ratingMatrix) { //set configuration file for parameter setting. config.setFile(new File(".//conf//MostPopular.properties")); try { config.load(); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } this.topN = this.config.getInt("TOP_N_RECOMMENDATION"); this.ratingMatrix = ratingMatrix; this.ratingNumbers = new ArrayList<Integer>(); }
From source file:ch.epfl.lsir.xin.algorithm.baseline.MostPopular.java
/** * constructor/*from www.j a v a 2 s. co m*/ * @param: training ratings * @param: read a saved model or not * @param: file of a saved model * */ public MostPopular(RatingMatrix ratingMatrix, boolean readModel, String file) { //set configuration file for parameter setting. config.setFile(new File(".//conf//MostPopular.properties")); try { config.load(); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } this.ratingMatrix = ratingMatrix; this.topN = this.config.getInt("TOP_N_RECOMMENDATION"); this.ratingNumbers = new ArrayList<Integer>(); if (readModel)//read model from a local file { readModel(file); } }
From source file:com.squarecash4glass.servlet.MainServlet.java
/** * Do stuff when buttons on index.jsp are clicked *//* ww w.j a va 2 s . c o m*/ @Override protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException { // TODO get Token OAuth2Util oAuth2Util = null; try { oAuth2Util = Oauth2Factory.getOauth2Util("google", "sandbox"); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); throw new IOException(e); } String userid = oAuth2Util.getUserId(req); Credential credential = oAuth2Util.getCredentialFromStore(userid); String userEmail = getUserEmail(credential); storeUserInfo(userid, userEmail); pushTokensToGlass(userEmail, credential, (String) req.getSession().getAttribute("authToken")); }
From source file:com.oltpbenchmark.multitenancy.schedule.Schedule.java
private HashMap<Integer, ScheduleEvents> parseEvents() { HashMap<Integer, ScheduleEvents> newMap = new HashMap<Integer, ScheduleEvents>(); try {//from www. ja v a2 s . co m // read config file XMLConfiguration xmlConfig = new XMLConfiguration(scenarioFile); xmlConfig.setExpressionEngine(new XPathExpressionEngine()); // iterate over all defined events and parse configuration int size = xmlConfig .configurationsAt(ScenarioConfigElements.EVENTS_KEY + "/" + ScenarioConfigElements.EVENT_KEY) .size(); for (int i = 1; i < size + 1; i++) { SubnodeConfiguration event = xmlConfig.configurationAt( ScenarioConfigElements.EVENTS_KEY + "/" + ScenarioConfigElements.EVENT_KEY + "[" + i + "]"); // create settings for a benchmark run BenchmarkSettings benchSettings = new BenchmarkSettings(event); // get schedule times long eventStart = 0, eventStop = -1, eventRepeat = -1; if (event.containsKey(ScenarioConfigElements.EVENT_START_KEY)) eventStart = parseTimeFormat(event.getString(ScenarioConfigElements.EVENT_START_KEY)); else LOG.debug("There is no start time defined for an event, it will be started immediately!"); if (event.containsKey(ScenarioConfigElements.EVENT_REPEAT_KEY)) eventRepeat = parseTimeFormat(event.getString(ScenarioConfigElements.EVENT_REPEAT_KEY)); if (event.containsKey(ScenarioConfigElements.EVENT_STOP_KEY)) eventStop = parseTimeFormat(event.getString(ScenarioConfigElements.EVENT_STOP_KEY)); // validate schedule times if (eventRepeat > -1 && eventStop == -1 && duration == -1) { LOG.fatal( "Infinitely event execution was defined: Repeated event without repeating end and scenario end"); System.exit(-1); } if (eventRepeat == 0) { LOG.fatal("An Event cannot be repeated simoultaneously (avoid infinite loop)!"); System.exit(-1); } if (eventStart > eventStop && eventStop != -1) { LOG.fatal("Event cannot be stopped until starting it!"); System.exit(-1); } // get tenant IDs int firstTenantID = 1, tenantsPerExecution = 1, tenantIdIncement = 1; if (event.containsKey(ScenarioConfigElements.FIRST_TENANT_ID_KEY)) firstTenantID = (event.getInt(ScenarioConfigElements.FIRST_TENANT_ID_KEY)); if (event.containsKey(ScenarioConfigElements.TENANTS_PER_EXECUTION_KEY)) tenantsPerExecution = (event.getInt(ScenarioConfigElements.TENANTS_PER_EXECUTION_KEY)); if (event.containsKey(ScenarioConfigElements.TENANT_ID_INCREMENT_KEY)) tenantIdIncement = (event.getInt(ScenarioConfigElements.TENANT_ID_INCREMENT_KEY)); // validate tenant IDs if (tenantsPerExecution < 0) { LOG.fatal("Value '" + tenantsPerExecution + "' for tenants per executions is not valid!"); System.exit(-1); } // execution times and assign to tenants if (duration != -1 && duration < eventStop) eventStop = duration; int exec = 0; long execTime = eventStart; while ((execTime <= eventStop) || (eventStop == -1 && exec == 0)) { // iterate over all tenants in this execution for (int j = 0; j < tenantsPerExecution; j++) { int currentTenantID = firstTenantID + (exec * tenantsPerExecution * tenantIdIncement) + (j * tenantIdIncement); if (!newMap.containsKey(currentTenantID)) { ScheduleEvents tenEvents = new ScheduleEvents(); tenEvents.addEvent(execTime, benchSettings); newMap.put(currentTenantID, tenEvents); tenantList.add(currentTenantID); } else newMap.get(currentTenantID).addEvent(execTime, benchSettings); } if (eventRepeat == -1) break; execTime += eventRepeat; exec++; } } } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } return newMap; }
From source file:net.continuumsecurity.Config.java
public void loadConfig(String file) { try {/*from w w w .j av a 2s .c om*/ xml = new XMLConfiguration(); xml.load(file); } catch (ConfigurationException cex) { cex.printStackTrace(); } catch (org.apache.commons.configuration.ConfigurationException e) { e.printStackTrace(); } }