X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Frserv%2FCachingFileAccess.java;h=cdda50db48eba07714994cd2a0299a7721a01c09;hb=bdb54b7c8a5df0e686490658067c9013ee43dd7a;hp=ce87533ee700a5d271b5dfd4b3a78d0846d0979f;hpb=e3093b8d1b19ad92a4af90df39a2087f40a687d4;p=aaf%2Fauthz.git diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/CachingFileAccess.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/CachingFileAccess.java index ce87533e..cdda50db 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/CachingFileAccess.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/CachingFileAccess.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,15 +24,12 @@ package org.onap.aaf.auth.rserv; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -52,23 +49,21 @@ import java.util.regex.Pattern; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.onap.aaf.misc.env.Env; import org.onap.aaf.misc.env.EnvJAXB; import org.onap.aaf.misc.env.LogTarget; import org.onap.aaf.misc.env.Store; -import org.onap.aaf.misc.env.TimeTaken; import org.onap.aaf.misc.env.Trans; /* * CachingFileAccess - * + * * Author: Jonathan Gathman, Gathsys 2010 - * + * */ public class CachingFileAccess extends HttpCode { public static void setEnv(Store store, String[] args) { - for (int i=0;i extends HttpCode typeMap; private final NavigableMap content; private final Set attachOnly; - public final static String CFA_WEB_PATH = "aaf_cfa_web_path"; + public static final String CFA_WEB_PATH = "aaf_cfa_web_path"; // when to re-validate from file // Re validating means comparing the Timestamp on the disk, and seeing it has changed. Cache is not marked - // dirty unless file has changed, but it still makes File IO, which for some kinds of cached data, i.e. + // dirty unless file has changed, but it still makes File IO, which for some kinds of cached data, i.e. // deployed GUI elements is unnecessary, and wastes time. // This parameter exists to cover the cases where data can be more volatile, so the user can choose how often the // File IO will be accessed, based on probability of change. "0", of course, means, check every time. - private final static String CFA_CACHE_CHECK_INTERVAL = "aaf_cfa_cache_check_interval"; - private final static String CFA_MAX_SIZE = "aaf_cfa_max_size"; // Cache size limit - private final static String CFA_CLEAR_COMMAND = "aaf_cfa_clear_command"; + private static final String CFA_CACHE_CHECK_INTERVAL = "aaf_cfa_cache_check_interval"; + private static final String CFA_MAX_SIZE = "aaf_cfa_max_size"; // Cache size limit + private static final String CFA_CLEAR_COMMAND = "aaf_cfa_clear_command"; // Note: can be null without a problem, but included // to tie in with existing Logging. @@ -98,13 +93,15 @@ public class CachingFileAccess extends HttpCode extends HttpCode extends HttpCode2 && slash>=0 && key.substring(0,slash).equals(clearCommand)) { resp.setHeader("Content-Type",typeMap.get("txt")); - if ("clear".equals(cmd)) { + if ("clear".equals(key.substring(slash+1))) { content.clear(); resp.setStatus(200/*HttpStatus.OK_200*/); } else { @@ -170,7 +179,7 @@ public class CachingFileAccess extends HttpCode0?key+'/'+cmd:key, null, checkInterval); + Content c = load(logT , webPath,key, null, checkInterval); if (c.attachmentOnly) { resp.setHeader("Content-disposition", "attachment"); } @@ -181,14 +190,14 @@ public class CachingFileAccess extends HttpCode extends HttpCode extends HttpCode extends HttpCode extends HttpCode0; } - + if (mediaType==null) { // determine from file Ending int idx = key.lastIndexOf('.'); String subkey = key.substring(++idx); @@ -272,9 +281,9 @@ public class CachingFileAccess extends HttpCode extends HttpCode extends HttpCode extends HttpCode() { @Override @@ -392,7 +401,7 @@ public class CachingFileAccess extends HttpCode extends HttpCode extends HttpCode extends HttpCode extends HttpCode content; - + public Cleanup(NavigableMap content, int size) { maxSize = size; this.content = content; } - + private class Comp implements Comparable { public Map.Entry entry; - + public Comp(Map.Entry en) { entry = en; } - + @Override public int compareTo(Comp o) { return (int)(entry.getValue().access-o.entry.getValue().access); } - + } @SuppressWarnings("unchecked") @Override @@ -519,16 +528,10 @@ public class CachingFileAccess extends HttpCode entry = scont.get(i).entry; content.remove(entry.getKey()); - //System.out.println("removed Cache Item " + entry.getKey() + "/" + new Date(entry.getValue().access).toString()); } -// for (int i=end;i entry = scont.get(i).entry; -// //System.out.println("remaining Cache Item " + entry.getKey() + "/" + new Date(entry.getValue().access).toString()); -// } } } }