+
+
+ public static Map<String,String> extractBasicAuthentication(String authorization){
+ Map<String,String> authValues = new HashMap<>();
+ if(authorization == null) {
+ authValues.put("ERROR", "Authorization cannot be null");
+ return authValues;
+ }
+ authorization = authorization.replaceFirst("Basic", "");
+ String decoded = Base64.base64Decode(authorization);
+ StringTokenizer token = new StringTokenizer(decoded, ":");
+ authValues.put(MusicUtil.USERID, token.nextToken());
+ authValues.put(MusicUtil.PASSWORD,token.nextToken());
+ return authValues;
+
+ }
+
+ public static boolean isValidConsistency(String consistency) {
+ for (String string : cosistencyLevel) {
+ if (string.equalsIgnoreCase(consistency))
+ return true;
+ }
+ return false;
+
+ }
+
+ public static ConsistencyLevel getConsistencyLevel(String consistency) {
+ return consistencyName.get(consistency.toUpperCase());
+ }
+
+ public static void loadProperties() throws Exception {
+ Properties prop = new Properties();
+ InputStream input = null;
+ try {
+ // load the properties file
+ input = MusicUtil.class.getClassLoader().getResourceAsStream("music.properties");
+ prop.load(input);
+ } catch (Exception ex) {
+ logger.error(EELFLoggerDelegate.errorLogger, "Unable to find properties file.");
+ throw new Exception();
+ } finally {
+ if (input != null) {
+ try {
+ input.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ // get the property value and return it
+ MusicUtil.setMyCassaHost(prop.getProperty("cassandra.host"));
+ String zkHosts = prop.getProperty("zookeeper.host");
+ MusicUtil.setMyZkHost(zkHosts);
+ MusicUtil.setCassName(prop.getProperty("cassandra.user"));
+ MusicUtil.setCassPwd(prop.getProperty("cassandra.password"));
+ MusicUtil.setCassandraPort(Integer.parseInt(prop.getProperty("cassandra.port")));
+ MusicUtil.setNotifyTimeOut(Integer.parseInt(prop.getProperty("notify.timeout")));
+ MusicUtil.setNotifyInterval(Integer.parseInt(prop.getProperty("notify.interval")));
+ MusicUtil.setCacheObjectMaxLife(Integer.parseInt(prop.getProperty("cacheobject.maxlife")));
+ }
+
+ public static void setNotifyInterval(int notifyinterval) {
+ MusicUtil.notifyinterval = notifyinterval;
+ }
+ public static void setNotifyTimeOut(int notifytimeout) {
+ MusicUtil.notifytimeout = notifytimeout;
+ }
+
+ public static int getNotifyInterval() {
+ return MusicUtil.notifyinterval;
+ }
+
+ public static int getNotifyTimeout() {
+ return MusicUtil.notifytimeout;
+ }
+
+ public static int getCacheObjectMaxLife() {
+ return MusicUtil.cacheObjectMaxLife;
+ }
+
+ public static void setCacheObjectMaxLife(int cacheObjectMaxLife) {
+ MusicUtil.cacheObjectMaxLife = cacheObjectMaxLife;
+ }