Changeset 628


Ignore:
Timestamp:
04/01/11 16:49:04 (2 years ago)
Author:
philsmart
Message:
 
Location:
raptor-ica-embedded/trunk
Files:
3 added
2 deleted
11 edited
1 moved

Legend:

Unmodified
Added
Removed
  • raptor-ica-embedded/trunk/pom.xml

    r588 r628  
    275275 
    276276                <!-- includes the information-model --> 
    277                 <dependency> 
    278                         <groupId>uk.ac.cardiff.raptor</groupId> 
    279                         <artifactId>raptor-serviceinterfaces</artifactId> 
    280                         <version>0.4-SNAPSHOT</version> 
    281                         <exclusions> 
    282                                 <exclusion> 
    283                                         <artifactId>slf4j-api</artifactId> 
    284                                         <groupId>org.slf4j</groupId> 
    285                                 </exclusion> 
    286                         </exclusions> 
    287                 </dependency> 
     277 
    288278                <dependency> 
    289279                        <groupId>postgresql</groupId> 
  • raptor-ica-embedded/trunk/src/main/config/data-access.xml

    r623 r628  
    2323        <!--  List all the data access beans, used by the parser --> 
    2424        <bean id="dataAccessRegister" class="uk.ac.cardiff.raptor.raptorica.engine.DataAccessRegister"> 
    25                 <property name="authenticationModules"> 
     25                <property name="parsingModules"> 
    2626                        <list><!-- 
    2727                                <bean id="shibbolethAccessLFP" class="uk.ac.cardiff.raptor.raptorica.dao.external.file.LogFileParser"> 
     
    4545                                --> 
    4646                                <bean id="shibbolethAuditLFP" class="uk.ac.cardiff.raptor.raptorica.dao.external.file.LogFileParser"> 
    47                                         <property name="entryHandler"><ref bean="memoryEntryHandler"></ref></property> 
     47                                        <property name="entryHandler"><ref bean="persistantEntryHandler"></ref></property> 
    4848                                        <property name="logfile"> 
    49                                                 <value>file:///Users/philsmart/Documents/DataSets/Logs/idp-audit-17th.log 
     49                                                <value>file:///Users/philsmart/Documents/DataSets/Logs/shib2comb-sorted-to-20110213.log 
    5050                                                </value> 
    5151                                        </property> 
     
    5353                                                <ref bean="shibIDPAuditFileFormat" /> 
    5454                                        </property> 
    55                                         <property name="entryType"> 
     55                                        <property name="eventType"> 
    5656                                                <value>uk.ac.cardiff.model.event.ShibbolethIdpAuthenticationEvent</value> 
    5757                                        </property> 
     58                                        <property name="printParsingPosition"><value>true</value></property> 
    5859 
    5960                                        <!--  The inclusion list is an OR of field name, value pairs that are loaded by the parser 
  • raptor-ica-embedded/trunk/src/main/config/ica-core.xml

    r604 r628  
    2222 
    2323        <!-- Polling trigger setup --> 
    24  
    25  
    26  
    2724        <bean id="ICAProcessQuickTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean"> 
    2825                <property name="jobDetail"> 
     
    3027                </property> 
    3128                <property name="repeatInterval" value="30000" /> 
    32                 <!-- <property name="repeatCount" value="0" />--> 
    3329        </bean> 
    3430 
     
    4844        <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> 
    4945                <property name="triggers"> 
    50                         <list><!-- 
    51                                 <ref local="ICAProcessTrigger" /> 
    52                                 --> 
     46                        <list> 
    5347                                <ref local="ICAProcessQuickTrigger" /> 
    5448                        </list> 
     
    8680                <property name="eventReleaseEngine"><ref bean="eventReleaseEngine"></ref></property> 
    8781        </bean> 
    88          
     82 
    8983        <bean id="eventReleaseEngine" class="uk.ac.cardiff.raptor.registry.EventReleaseEngine"> 
    9084                <property name="attributeFilterEngine"><ref bean="attributeFilterEngine"/></property> 
     
    9387 
    9488        <bean id="attributeFilterEngine" class="uk.ac.cardiff.raptor.attribute.filtering.AttrributeFilterEngine"/> 
    95          
    96         <bean id="serviceEndpointInterface" class="uk.ac.cardiff.raptor.remoting.client.sei.impl.CxfServiceEndpointInterface"/> 
     89 
     90        <bean id="serviceEndpointInterface" class="uk.ac.cardiff.raptor.remoting.client.sei.impl.CxfServiceEndpointClient"/> 
    9791 
    9892        <import resource="dao-beans.xml"/> 
  • raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/dao/BaseEventParser.java

    r621 r628  
    1919package uk.ac.cardiff.raptor.raptorica.dao; 
    2020 
     21import java.util.Set; 
     22 
    2123import org.slf4j.Logger; 
    2224import org.slf4j.LoggerFactory; 
    2325 
     26import uk.ac.cardiff.model.event.Event; 
    2427import uk.ac.cardiff.raptor.raptorica.model.EntryHandler; 
     28import uk.ac.cardiff.raptor.raptorica.model.exception.ParserException; 
     29import uk.ac.cardiff.raptor.raptorica.model.filter.ExclusionList; 
     30import uk.ac.cardiff.raptor.raptorica.model.filter.InclusionList; 
    2531 
    2632 
     
    3036 * 
    3137 */ 
    32 public abstract class RawData { 
     38public abstract class BaseEventParser { 
    3339 
    34     /* class logger */ 
    35     private final Logger log = LoggerFactory.getLogger(RawData.class); 
     40    /** class logger */ 
     41    private final Logger log = LoggerFactory.getLogger(BaseEventParser.class); 
    3642 
    3743    /** The handler that is responsible for storing events */ 
    38     private EntryHandler entryHandler; 
     44    protected EntryHandler entryHandler; 
    3945 
    40     public abstract void parse() throws Exception; 
     46    /** A list of <fieldname,value> pairs that should be excluded during parsing */ 
     47    private ExclusionList exclusionList; 
    4148 
    42     public RawData() { 
    43         //setEntryHandler(new MemoryEntryHandler()); 
     49    /** A list of <fieldname, value> pairs that should be included during parsing */ 
     50    private InclusionList inclusionList; 
     51 
     52    /** 
     53     * Default constructor 
     54     */ 
     55    public BaseEventParser() { 
    4456    } 
    4557 
     58    /** 
     59     * The method that must be provided to parse events from a particular datasource 
     60     * 
     61     * @throws ParserException 
     62     */ 
     63    public abstract void parse() throws ParserException; 
     64 
     65 
     66    /** 
     67     * Creates a new object from a class name. Could be removed to a helper class 
     68     * 
     69     * @param className the fully qualified class name 
     70     * @return the new object instantiated as the type <code>className</code> 
     71     */ 
    4672    public Object createObject(String className) { 
    4773        Object object = null; 
     
    4975            Class classDefinition = Class.forName(className); 
    5076            object = classDefinition.newInstance(); 
    51             // this.setBeanProperty(object, "applicationContext", 
    52             // this.getApplicationContext()); 
    5377        } catch (InstantiationException e) { 
    5478            log.warn(e.getMessage()); 
     
    6286 
    6387    /** 
    64      * removes all entries from the entry handler 
     88     * Method to remove all entries from the entry handler 
    6589     */ 
    6690    public void removeAllEntries() { 
    67         getEntryHandler().removeAllEntries(); 
     91        entryHandler.removeAllEntries(); 
    6892 
    6993    } 
    7094 
     95    /** 
     96     * Sets and initialises the entry handler 
     97     * 
     98     * @param entryHandler 
     99     */ 
    71100    public void setEntryHandler(EntryHandler entryHandler) { 
    72101        this.entryHandler = entryHandler; 
     
    74103    } 
    75104 
     105    /** 
     106     * Gets the entry handler 
     107     * 
     108     * @return 
     109     */ 
    76110    public EntryHandler getEntryHandler() { 
    77111        return entryHandler; 
    78112    } 
    79113 
     114 
     115    /** 
     116     * Sets the exclusion list 
     117     * 
     118     * @param exclusionList 
     119     */ 
     120    public void setExclusionList(ExclusionList exclusionList) { 
     121        this.exclusionList = exclusionList; 
     122    } 
     123 
     124    /** 
     125     * Gets the exclusion list 
     126     * 
     127     * @return 
     128     */ 
     129    public ExclusionList getExclusionList() { 
     130        return exclusionList; 
     131    } 
     132 
     133 
     134    /** 
     135     * Sets the inclusion list 
     136     * 
     137     * @param inclusionList 
     138     */ 
     139    public void setInclusionList(InclusionList inclusionList) { 
     140        this.inclusionList = inclusionList; 
     141    } 
     142 
     143 
     144    /** 
     145     * Gets the inclusion list 
     146     * 
     147     * @return 
     148     */ 
     149    public InclusionList getInclusionList() { 
     150        return inclusionList; 
     151    } 
     152 
     153 
     154    /** 
     155     * Gets all the entries currently stored by this entry handler 
     156     * 
     157     * @return 
     158     */ 
     159    public Set<Event> getAuthentications() { 
     160        return entryHandler.getEntries(); 
     161 
     162    } 
     163 
     164 
     165 
    80166} 
  • raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/dao/external/UsageInput.java

    r454 r628  
    2222import java.util.Set; 
    2323 
    24 import uk.ac.cardiff.raptor.raptorica.dao.RawData; 
     24import uk.ac.cardiff.raptor.raptorica.dao.BaseEventParser; 
    2525 
    2626/** 
     
    2828 * 
    2929 */ 
    30 public abstract class UsageInput extends RawData{ 
     30public abstract class UsageInput extends BaseEventParser{ 
    3131 
    3232 
  • raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/dao/external/file/LogFileParser.java

    r617 r628  
    1717 
    1818import java.io.BufferedReader; 
    19 import java.io.FileInputStream; 
    2019import java.io.IOException; 
    2120import java.io.InputStream; 
    2221import java.io.InputStreamReader; 
    2322import java.lang.reflect.Method; 
     23import java.net.MalformedURLException; 
    2424import java.net.URL; 
    2525import java.net.URLConnection; 
    2626import java.util.ArrayList; 
    27 import java.util.LinkedHashSet; 
    2827import java.util.List; 
    29 import java.util.Map; 
    30 import java.util.Properties; 
    31 import java.util.Set; 
    3228import java.util.TimeZone; 
    3329import java.io.BufferedInputStream; 
    3430 
    35 import uk.ac.cardiff.raptor.raptorica.dao.external.AuthenticationInput; 
     31import uk.ac.cardiff.raptor.raptorica.dao.BaseEventParser; 
    3632import uk.ac.cardiff.raptor.raptorica.dao.external.format.Header; 
    3733import uk.ac.cardiff.raptor.raptorica.dao.external.format.LogFileFormat; 
    38 import uk.ac.cardiff.raptor.raptorica.dao.internal.ICADataConnection; 
    39 import uk.ac.cardiff.raptor.raptorica.model.PersistentParserSupport; 
     34import uk.ac.cardiff.raptor.raptorica.model.exception.HeaderException; 
     35import uk.ac.cardiff.raptor.raptorica.model.exception.ParserException; 
    4036import uk.ac.cardiff.raptor.raptorica.model.filter.ExclusionEntry; 
    4137import uk.ac.cardiff.raptor.raptorica.model.filter.InclusionEntry; 
     
    4844import org.slf4j.Logger; 
    4945import org.slf4j.LoggerFactory; 
    50 import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; 
    5146 
    5247import uk.ac.cardiff.raptor.raptorica.runtimeutils.ReflectionHelper; 
    53 import uk.ac.cardiff.model.*; 
    5448import uk.ac.cardiff.model.event.Event; 
    5549 
    5650/** 
     51 * A log file parser, used to parse files on the local filesystem according to a given 
     52 * format and transformed into the given event type. 
     53 * 
    5754 * @author phil 
    5855 * 
    59  *         This is the primary log file parser. 
    60  * 
    6156 */ 
    62 public class LogFileParser extends AuthenticationInput { 
    63     static Logger log = LoggerFactory.getLogger(LogFileParser.class); 
     57public class LogFileParser extends BaseEventParser { 
     58 
     59    /** The class logger*/ 
     60    private final Logger log = LoggerFactory.getLogger(LogFileParser.class); 
     61 
     62    /** The specification of the format of this log file */ 
    6463    private LogFileFormat format; 
     64 
     65    /** The fully qualified path of the log file */ 
    6566    private String logfile; 
    66     private String entryType; 
    67  
     67 
     68    /** The fully qualified name of the event type class */ 
     69    private String eventType; 
     70 
     71    /** Whether to print out the current position of parsing in the <code>logFile</code> */ 
     72    private boolean printParsingPosition; 
     73 
     74    /** 
     75     * Default constructor 
     76     */ 
    6877    public LogFileParser() { 
    69  
    70     } 
    71  
    72     public void parse() throws Exception { 
    73         log.info("parsing: {} instance: {}",logfile, this); 
    74  
    75         // Must use URL, as java.io does not work in a webapp 
    76         URL logfileURL = new URL(logfile); 
    77         URLConnection logfileconnection = logfileURL.openConnection(); 
    78         BufferedReader in = new BufferedReader(new InputStreamReader(logfileconnection.getInputStream())); 
    79         int lineCount = 0; 
    80         String inputLine; 
    81  
    82         int totalNoLines =count(logfileURL); 
    83  
    84         log.debug("Parsing file with {} lines",totalNoLines); 
    85         while ((inputLine = in.readLine()) != null) { 
    86             // log.debug(inputLine); 
    87             lineCount++; 
    88             double linePercentage = (((double)lineCount/(double)totalNoLines)*100); 
    89             if (linePercentage%25>=0 && linePercentage%25<=0.0001) log.debug("Complete {}%",linePercentage); 
    90  
    91             StrTokenizer tokenizer = new StrTokenizer(inputLine, format.getDelimeter()); 
    92             tokenizer.setIgnoreEmptyTokens(false); 
    93             ArrayList<String> allvalues = new ArrayList(); 
    94             while (tokenizer.hasNext()) { 
    95                 Object next = tokenizer.next(); 
    96                 if (next instanceof String) 
    97                     allvalues.add((String) next); 
    98                 else { 
    99                     log.error("input column was not a string"); 
    100                 } 
    101             } 
    102             /* first, dynamically construct the supplied entry class, which is subclass of Event */ 
    103             Event authE = (Event) this.createObject(getEntryType()); 
    104  
    105             /* now populate its fields */ 
    106             for (Header header : format.getHeaders()) { 
    107  
     78        super(); 
     79    } 
     80 
     81    @Override 
     82    public void parse() throws ParserException { 
     83        log.info("parsing: {} instance: {}", logfile, this); 
     84 
     85        try { 
     86            URL logfileURL = new URL(logfile); 
     87 
     88            URLConnection logfileconnection = logfileURL.openConnection(); 
     89 
     90            BufferedReader in = new BufferedReader(new InputStreamReader(logfileconnection.getInputStream())); 
     91            int lineCount = 0; 
     92            String inputLine; 
     93            int totalNoLines = count(logfileURL); 
     94 
     95            log.debug("Parsing file with {} lines", totalNoLines); 
     96            while ((inputLine = in.readLine()) != null) { 
     97                lineCount++; 
     98 
     99                if (printParsingPosition) { 
     100                    printParsingPosition(lineCount, totalNoLines); 
     101                } 
     102 
     103                // TODO TOKENIZE METHOD, then regex 
     104                StrTokenizer tokenizer = new StrTokenizer(inputLine, format.getDelimeter()); 
     105                tokenizer.setIgnoreEmptyTokens(false); 
     106                ArrayList<String> allvalues = new ArrayList<String>(); 
     107                while (tokenizer.hasNext()) { 
     108                    Object next = tokenizer.next(); 
     109                    if (next instanceof String) 
     110                        allvalues.add((String) next); 
     111                    else { 
     112                        log.error("input column was not a string"); 
     113                    } 
     114                } 
     115 
     116                Event authE = (Event) this.createObject(eventType); 
    108117                try { 
    109                     if (!(header.getFieldNo() >= allvalues.size())) { 
    110                         String value = allvalues.get(header.getFieldNo()); 
    111                         // log.debug("Field: " + header.getFieldName() + 
    112                         // " value: " + value+" Type:"+ header.getType()); 
    113                         switch (header.getType()) { 
     118                    populateField(allvalues, authE); 
     119                } catch (HeaderException e) { 
     120                    log.error("ERROR: trying to access field {}, when only {} fields in log file", e.getHeaderNo(), allvalues.size()); 
     121                } 
     122 
     123                boolean shouldBeIncluded = isIncluded(authE); 
     124                boolean preventAdd = isExcluded(authE); 
     125 
     126                if (shouldBeIncluded && !preventAdd) { 
     127                    entryHandler.addEntry(authE); 
     128                } 
     129 
     130            } 
     131            in.close(); 
     132 
     133            log.debug("done, walked {} lines", lineCount); 
     134            log.debug("LogFileParser currently has: {} entries, latestEntry: {}", getEntryHandler().getEntries().size(), getEntryHandler().getLatestEntryTime()); 
     135            entryHandler.endTransaction(); 
     136        } catch (MalformedURLException e1) { 
     137            throw new ParserException("Could not find the source file ["+logfile+"] for parsing",e1); 
     138        } catch (IOException e2) { 
     139            throw new ParserException("Could not read from the source file ["+logfile+"] during parsing",e2); 
     140        } 
     141 
     142        // System.exit(1); 
     143 
     144    } 
     145 
     146    /** 
     147     * Prints, as a percentage, the line currently being parsed. 
     148     * 
     149     * @param lineCount 
     150     * @param totalNoLines 
     151     */ 
     152    private void printParsingPosition(int lineCount, int totalNoLines) { 
     153        double linePercentage = (((double) lineCount / (double) totalNoLines) * 100); 
     154        if (linePercentage % 25 >= 0 && linePercentage % 25 <= 0.0001) 
     155            log.debug("Complete {}%", linePercentage); 
     156    } 
     157 
     158    /** 
     159     * Populates attributes in the Event class <code>authE</code> (or subclasses thereof) from the headers defined in <code>format</code> 
     160     * 
     161     * @param allvalues 
     162     * @param authE 
     163     * @throws HeaderException 
     164     */ 
     165    private void populateField(List<String> allvalues, Event authE) throws HeaderException { 
     166        for (Header header : format.getHeaders()) { 
     167            try { 
     168                if (!(header.getFieldNo() >= allvalues.size())) { 
     169                    String value = allvalues.get(header.getFieldNo()); 
     170                    switch (header.getType()) { 
    114171                        case DATE: 
    115                             addDate(value, header.getDateTimeFormat(), header.getTimeZone(),header.getFieldName(), authE); 
     172                            addDate(value, header.getDateTimeFormat(), header.getTimeZone(), header.getFieldName(), authE); 
    116173                            break; 
    117174                        case STRING: 
     
    124181                            addStringList(value, header.getFieldName(), authE, header.getListDelimeter()); 
    125182                            break; 
    126                         } 
    127  
    128                     } else { 
    129                         log.error("trying to access field " + header.getFieldNo() + ", when only " + allvalues.size() + " fields in log file \n --> " + inputLine); 
    130183                    } 
    131                 } catch (ClassCastException e) { 
    132                     log.error("Header key is not an integer, needs to be an integer (possibly look at data-access.xml)."); 
    133                 } 
    134             } 
    135  
    136             /* check its IN the inclusion list */ 
    137             boolean shouldBeIncluded = false; 
    138             if (getInclusionList()!=null){ 
    139                 for (InclusionEntry inclusion : getInclusionList().getInclusionEntries()){ 
    140                     String fieldname = inclusion.getFieldName(); 
    141                     Object valueFromEntry = getValueFromObject(fieldname, authE); 
    142                     if (valueFromEntry instanceof String) { 
    143                         String valueFromEntryString = (String)valueFromEntry; 
    144                         if (inclusion.filter(valueFromEntryString)){ 
    145                             //log.debug("entry [{}] had match true",valueFromEntryString); 
    146                             shouldBeIncluded = true; 
    147                         } 
     184 
     185                } else { 
     186                    StringBuilder exceptionMessage = new StringBuilder(); 
     187                    exceptionMessage.append("failed trying to access field "); 
     188                    exceptionMessage.append(header.getFieldNo()); 
     189                    throw new HeaderException(exceptionMessage.toString(), header.getFieldNo()); 
     190                } 
     191            } catch (ClassCastException e) { 
     192                throw new HeaderException("Header key is not an integer, needs to be an integer (error could exist in data-access.xml)", header.getFieldNo(), e); 
     193 
     194            } 
     195        } 
     196    } 
     197 
     198    /** 
     199     * Determines if the event should not be stored, as determined by a <fieldname, value> match on the input <code>authE</code> event with those in the 
     200     * <code>exclusionList</code>. 
     201     * 
     202     * @param authE 
     203     * @return true if any <fieldname,value> pairs in the <code>autheE</code> event are found in the exclusion list, false otherwise 
     204     */ 
     205    private boolean isExcluded(Event authE) { 
     206        if (getExclusionList() != null) { 
     207            for (ExclusionEntry exclusion : getExclusionList().getExclusionEntries()) { 
     208                String fieldname = exclusion.getFieldName(); 
     209                Object valueFromEntry = getValueFromObject(fieldname, authE); 
     210                if (valueFromEntry instanceof String) { 
     211                    String valueFromEntryString = (String) valueFromEntry; 
     212                    if (exclusion.filter(valueFromEntryString)) { 
     213                        return true; 
    148214                    } 
    149215                } 
    150216            } 
    151             else{ 
    152                 //no inclusion list, assume all 
    153                 shouldBeIncluded = true; 
    154             } 
    155  
    156             /* now check its not in the exclusion list */ 
    157             boolean preventAdd = false; 
    158             if (getExclusionList() != null) { 
    159                 for (ExclusionEntry exclusion : getExclusionList().getExclusionEntries()){ 
    160                     String fieldname = exclusion.getFieldName(); 
    161                     Object valueFromEntry = getValueFromObject(fieldname, authE); 
    162                     if (valueFromEntry instanceof String) { 
    163                         String valueFromEntryString = (String)valueFromEntry; 
    164                         if (exclusion.filter(valueFromEntryString)){ 
    165                             preventAdd=true; 
    166                         } 
     217        } 
     218        return false; 
     219    } 
     220 
     221    /** 
     222     * Determines if the event should stored, as determined by a <fieldname, value> match on the input <code>authE</code> event with those in the 
     223     * <code>exclusionList</code>. 
     224     * 
     225     * @param authE 
     226     * @return true if any <fieldname,value> pairs in the <code>autheE</code> event are found in the inclusion list, false otherwise 
     227     */ 
     228    private boolean isIncluded(Event authE) { 
     229        if (getInclusionList() != null) { 
     230            for (InclusionEntry inclusion : getInclusionList().getInclusionEntries()) { 
     231                String fieldname = inclusion.getFieldName(); 
     232                Object valueFromEntry = getValueFromObject(fieldname, authE); 
     233                if (valueFromEntry instanceof String) { 
     234                    String valueFromEntryString = (String) valueFromEntry; 
     235                    if (inclusion.filter(valueFromEntryString)) { 
     236                        return true; 
    167237                    } 
    168238                } 
    169239            } 
    170  
    171             if (shouldBeIncluded && !preventAdd) { 
    172                 /* 
    173                  * do not add the object to the arrayList if is timestamp is 
    174                  * older than the current latest entry this should save heap 
    175                  * space during operation 
    176                  */ 
    177  
    178                 getEntryHandler().addEntry(authE); 
    179             } 
    180  
    181         } 
    182  
    183         in.close(); 
    184  
    185         log.debug("done, walked " + lineCount + " lines"); 
    186         // getEntryHandler().addEntries(entries.); 
    187         log.debug("Currently has: " + getEntryHandler().getEntries().size() + " entries, latestEntry: " + getEntryHandler().getLatestEntryTime()); 
    188         getEntryHandler().endTransaction(); 
    189         //System.exit(1); 
    190  
    191         /* 
    192          * this is important, after one complete transaction, we push the 
    193          * latestTime entry by 1 millisecond, this stops the last entry of this 
    194          * transaction (n) being equal to itself in the second (n+1) transaction 
    195          * and so on. HOWEVER, this behaviour will also prevent a valid new 
    196          * entry in the n+1 transaction from being stored if it was a unique 
    197          * entry but at the same time as the last entry of the nth transaction. 
    198          * WE may therefore loose one or possibly two (more likely one) entry 
    199          * from the n+1 transactions - revise this. The good thing about this 
    200          * logic, is that we only need to check timestamps to obtain 
    201          * psuedo-incremental updates (even though the entire file is read in 
    202          * again, only newer entries are saved) 
    203          */ 
    204         // entryHandler.endTransaction(); 
    205  
    206     } 
    207  
    208     /** 
    209      * Fast method for finding the number of lines in a logfile 
     240        } else { 
     241            return true; 
     242        } 
     243 
     244        return false; 
     245    } 
     246 
     247    /** 
     248     * Efficient method for finding the number of lines in a logfile 
    210249     * 
    211250     * @param logfileURL 
     
    215254    private int count(URL logfileURL) throws IOException { 
    216255 
    217             URLConnection logfileconnection = logfileURL.openConnection(); 
    218             InputStream is = new BufferedInputStream(logfileconnection.getInputStream()); 
    219             byte[] c = new byte[1024]; 
    220             int count = 0; 
    221             int readChars = 0; 
    222             while ((readChars = is.read(c)) != -1) { 
    223                 for (int i = 0; i < readChars; ++i) { 
    224                     if (c[i] == '\n') 
    225                         ++count; 
    226                 } 
    227             } 
    228             return count; 
     256        URLConnection logfileconnection = logfileURL.openConnection(); 
     257        InputStream is = new BufferedInputStream(logfileconnection.getInputStream()); 
     258        byte[] c = new byte[1024]; 
     259        int count = 0; 
     260        int readChars = 0; 
     261        while ((readChars = is.read(c)) != -1) { 
     262            for (int i = 0; i < readChars; ++i) { 
     263                if (c[i] == '\n') 
     264                    ++count; 
     265            } 
     266        } 
     267        return count; 
    229268    } 
    230269 
     
    237276        try { 
    238277            String[] splitValue = value.split(delimeter); 
    239             // for (String s : splitValue)log.debug(s); 
    240278            String fieldAsMethod = ReflectionHelper.prepareMethodNameSet(fieldName); 
    241279            setValueOnObject(fieldAsMethod, splitValue, object); 
    242280        } catch (Exception e) { 
    243             log.error("Illegal StringList Value: " + value + " for field:" + fieldName + " | " + e.getMessage()); 
    244             // e.printStackTrace(); 
     281            log.error("Illegal StringList Value: {} for field: {}", new Object[] { value, fieldName, e }); 
    245282        } 
    246283    } 
     
    249286        try { 
    250287            /* 
    251              * first check the end of the date, if it has a Z it should have 
    252              * time zone information e.g. -0800 or +0500 but if it ends in just 
    253              * Z, there is not valid timezone information supplied, so remove 
     288             * first check the end of the date, if it has a Z it should have time zone information e.g. -0800 or +0500 but if it ends in just Z, there is not 
     289             * valid timezone information supplied, so remove 
    254290             */ 
     291            // TODO check this 
    255292            if (value.endsWith("Z")) 
    256293                value = value.substring(0, value.length() - 1); 
     
    262299            setValueOnObject(fieldAsMethod, dt, object); 
    263300        } catch (Exception e) { 
    264             log.error("Illegal Date Format For: " + value + " and format:" + format + " | " + e.getMessage()); 
    265             // e.printStackTrace(); 
     301            log.error("Illegal Date Value: {} for field: {}", new Object[] { value, fieldName, e }); 
    266302        } 
    267303 
     
    273309            setValueOnObject(fieldAsMethod, value, object); 
    274310        } catch (Exception e) { 
    275             log.error("Illegal String Value: " + value + " for field:" + fieldName + " | " + e.getMessage()); 
    276             // e.printStackTrace(); 
     311            log.error("Illegal String Value: {} for field: {}", new Object[] { value, fieldName, e }); 
    277312        } 
    278313 
     
    281316    private void addInteger(String value, String fieldName, Object object) { 
    282317        try { 
    283             Integer valueAsInt = new Integer(Integer.parseInt(value)); 
    284318            String fieldAsMethod = ReflectionHelper.prepareMethodNameSet(fieldName); 
    285319            setValueOnObject(fieldAsMethod, value, object); 
    286320        } catch (Exception e) { 
    287             log.error("Illegal Integer Value: " + value + " for field:" + fieldName + " | " + e.getMessage()); 
    288             // e.printStackTrace(); 
     321            log.error("Illegal Integer Value: {} for field: {}", new Object[] { value, fieldName, e }); 
    289322        } 
    290323 
     
    293326    private Object getValueFromObject(String fieldname, Object object) { 
    294327        try { 
    295             Class id = object.getClass(); 
     328            Class<? extends Object> id = object.getClass(); 
    296329            String fieldAsMethod = ReflectionHelper.prepareMethodNameGet(fieldname); 
    297330            Method getter = id.getMethod(fieldAsMethod, new Class[] {}); 
    298             // log.debug("Trying to Set :"+param) 
    299331            Object result = getter.invoke(object, new Object[] {}); 
    300332            return result; 
    301333        } catch (Throwable e) { 
    302             log.error("Field name '" + fieldname + "' does not match internal model attribute"); 
    303             e.printStackTrace(); 
    304             // System.exit(1); 
    305  
     334            log.error("Field name '{}' does not match internal model attribute", fieldname, e); 
    306335        } 
    307336        return null; 
     
    310339    private void setValueOnObject(String fieldname, Object param, Object object) { 
    311340        try { 
    312             Class id = object.getClass(); 
     341            Class<? extends Object> id = object.getClass(); 
    313342            Method setter = id.getMethod(fieldname, new Class[] { param.getClass() }); 
    314             // log.debug("Trying to Set :"+param) 
    315343            setter.invoke(object, new Object[] { param }); 
    316344        } catch (Throwable e) { 
    317             log.error("Field name '" + fieldname + "' does not match internal model attribute"); 
    318             e.printStackTrace(); 
    319             // System.exit(1); 
    320  
    321         } 
    322     } 
    323  
    324     private void preParse() { 
    325  
     345            log.error("Field name '{}' does not match internal model attribute", fieldname, e); 
     346 
     347        } 
    326348    } 
    327349 
     
    342364    } 
    343365 
    344     public void setEntryType(String entryType) { 
    345         this.entryType = entryType; 
    346     } 
    347  
    348     public String getEntryType() { 
    349         return entryType; 
    350     } 
    351  
    352     // public static void main(String args[]) throws IOException{ 
    353     // LogFileParser lfp = new LogFileParser(); 
    354     // lfp.setLogfile("/tmp/idp-access.log"); 
    355     // lfp.setFormat(new LogFileFormat()); 
    356     // lfp.parse(); 
    357     // } 
     366    /** 
     367     * @param printParsingPosition 
     368     *            the printParsingPosition to set 
     369     */ 
     370    public void setPrintParsingPosition(boolean printParsingPosition) { 
     371        this.printParsingPosition = printParsingPosition; 
     372    } 
     373 
     374    /** 
     375     * @return the printParsingPosition 
     376     */ 
     377    public boolean isPrintParsingPosition() { 
     378        return printParsingPosition; 
     379    } 
     380 
     381    /** 
     382     * @param eventType the eventType to set 
     383     */ 
     384    public void setEventType(String eventType) { 
     385        this.eventType = eventType; 
     386    } 
     387 
     388    /** 
     389     * @return the eventType 
     390     */ 
     391    public String getEventType() { 
     392        return eventType; 
     393    } 
    358394 
    359395} 
  • raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/engine/DataAccessRegister.java

    r454 r628  
    2424import org.apache.log4j.Logger; 
    2525 
    26 import uk.ac.cardiff.raptor.raptorica.dao.external.AuthenticationInput; 
     26import uk.ac.cardiff.raptor.raptorica.dao.BaseEventParser; 
    2727 
    2828/** 
    2929 * @author philsmart 
    3030 * 
    31  * Provides a register for parsing engines to plugin to. Also manages such engines. 
     31 * Provides a register for parsing modules to attach to. 
    3232 */ 
    3333public class DataAccessRegister { 
    34         static Logger log = Logger.getLogger(DataAccessRegister.class); 
    3534 
    36         private List<AuthenticationInput> authenticationModules; 
     35        /** Class logger */ 
     36        private final Logger log = Logger.getLogger(DataAccessRegister.class); 
    3737 
     38        /** List of parsing modules */ 
     39        private List<BaseEventParser> parsingModules; 
     40 
     41        /** 
     42         * Default constructor that sets an empty list of parsing modules by default. 
     43         */ 
    3844        public DataAccessRegister(){ 
    39                 setAuthenticationModules(new ArrayList<AuthenticationInput>()); 
     45            setParsingModules(new ArrayList<BaseEventParser>()); 
    4046        } 
    4147 
    42         public void setAuthenticationModules(List<AuthenticationInput> authenticationModules) { 
    43                 for (AuthenticationInput authI : authenticationModules)log.info("Registering: "+authI.getClass()); 
    44                 this.authenticationModules = authenticationModules; 
     48        /** 
     49         * Sets and prints the name of all parsing modules passed as an input parameter 
     50         * 
     51         * @param parsingModules 
     52         */ 
     53        public void setParsingModules(List<BaseEventParser> parsingModules) { 
     54                for (BaseEventParser parser : parsingModules) 
     55                    log.info("Registering: "+parser.getClass()); 
     56                this.parsingModules = parsingModules; 
    4557        } 
    4658 
    47         public List<AuthenticationInput> getAuthenticationModules() { 
    48                 return authenticationModules; 
     59        /** 
     60         * Gets the list of parsing modules currently registered 
     61         * 
     62         * @return list of parsing modules, all subclasses of the {@link BaseEventParser} class 
     63         */ 
     64        public List<BaseEventParser> getParsingModules() { 
     65                return parsingModules; 
    4966        } 
    5067 
  • raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/engine/ICAEngine.java

    r617 r628  
    2020 
    2121import java.util.ArrayList; 
    22 import java.util.LinkedHashSet; 
    2322import java.util.List; 
    24 import java.util.Set; 
    2523 
    2624import uk.ac.cardiff.raptor.exceptions.ReleaseFailureException; 
    27 import uk.ac.cardiff.raptor.raptorica.dao.external.AuthenticationInput; 
    28 import uk.ac.cardiff.raptor.registry.EventReleaseEngine; 
     25import uk.ac.cardiff.raptor.raptorica.dao.BaseEventParser; 
    2926import uk.ac.cardiff.raptor.remoting.client.EventReleaseClient; 
    3027 
     
    3734/** 
    3835 * @author philsmart 
    39  *  
     36 * 
    4037 *         Responsible for ALL low level capture operations 
    4138 */ 
     
    5451 
    5552        public void capturePerform() throws Exception { 
    56                 for (AuthenticationInput authI : getDataAccessRegister().getAuthenticationModules()) { 
    57                         log.info("Capturing from {}", authI); 
    58                         authI.parse(); 
     53                for (BaseEventParser parser : getDataAccessRegister().getParsingModules()) { 
     54                        log.info("Capturing from {}", parser); 
     55                        parser.parse(); 
    5956                } 
    6057        } 
     
    6966        private void retrieveTransactionFinished() { 
    7067                log.debug("Retrieve Transaction Finished, entries are being removed from the ICA..."); 
    71                 for (AuthenticationInput authI : getDataAccessRegister().getAuthenticationModules()) { 
    72                         authI.removeAllEntries(); 
     68                for (BaseEventParser parser : getDataAccessRegister().getParsingModules()) { 
     69                    parser.removeAllEntries(); 
    7370                } 
    74                 log.debug("Retrieve Transaction Finished, entries are being removed form the ICA...done"); 
     71                log.debug("Retrieve Transaction Finished, entries are being removed from the ICA...done"); 
    7572 
    7673        } 
     
    7976         * Converts all information from all modules into a single list that is sent 
    8077         * to the release engine 
    81          *  
     78         * 
    8279         * @return 
    8380         */ 
    8481        public boolean release() { 
    85                 List<Event> eventsToSend = new ArrayList<Event>();               
    86                 for (AuthenticationInput authI : getDataAccessRegister().getAuthenticationModules()){ 
    87                         eventsToSend.addAll(authI.getAuthentications()); 
     82                List<Event> eventsToSend = new ArrayList<Event>(); 
     83                for (BaseEventParser parser : getDataAccessRegister().getParsingModules()){ 
     84                        eventsToSend.addAll(parser.getAuthentications()); 
    8885                } 
    89                  
     86 
    9087                boolean success = false; 
    9188                try { 
  • raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/model/EntryHandler.java

    r617 r628  
    1919package uk.ac.cardiff.raptor.raptorica.model; 
    2020 
    21 import java.util.ArrayList; 
    22 import java.util.List; 
    2321import java.util.Set; 
    2422 
  • raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/model/PersistantEntryHandler.java

    r617 r628  
    3636/** 
    3737 * @author philsmart 
    38  *  
     38 * 
    3939 */ 
    4040public class PersistantEntryHandler implements EntryHandler { 
    4141 
    4242        /* class logger */ 
    43         static Logger log = LoggerFactory.getLogger(PersistantEntryHandler.class); 
     43        private final Logger log = LoggerFactory.getLogger(PersistantEntryHandler.class); 
    4444 
    4545        /* information about entries, e.g. last entry */ 
     
    6464                log.info("Persistant entry handler [{}] initialising", this); 
    6565                Integer rowCount = (Integer) dataConnection.runQueryUnique("select count(*) from Event", null); 
    66                 log.info("Persistent data store has {} entries", rowCount); 
     66                log.info("Persistent data store has {} events", rowCount); 
    6767                entryInformation = (EntryMetadata) dataConnection.runQueryUnique("from EntryMetadata", null); 
    6868                log.debug("Have saved entryInformaiton: " + entryInformation); 
     
    7171                log.debug("Entry Information " + entryInformation.getLatestEqualEntries()); 
    7272                // convert to set from list, maybe expensive 
    73                 List<Event> entriesAsList = dataConnection.runQuery("from Event", null); 
    74                 entries = new LinkedHashSet<Event>(entriesAsList); 
     73                //List<Event> entriesAsList = dataConnection.runQuery("from Event", null); 
     74                //entries = new LinkedHashSet<Event>(entriesAsList); 
     75                entries = new LinkedHashSet<Event>(); 
    7576                log.info("Persistant entry handler [{}] started", this); 
    7677        } 
     
    7879        /* 
    7980         * (non-Javadoc) 
    80          *  
     81         * 
    8182         * @see main.uk.ac.cf.model.EntryHandler#addEntries(java.util.List) 
    8283         */ 
     
    138139        /* 
    139140         * (non-Javadoc) 
    140          *  
     141         * 
    141142         * @see main.uk.ac.cf.model.EntryHandler#endTransaction() 
    142143         */ 
     
    152153        /* 
    153154         * (non-Javadoc) 
    154          *  
     155         * 
    155156         * @see main.uk.ac.cf.model.EntryHandler#getEntries() 
    156157         */ 
     
    162163        /* 
    163164         * (non-Javadoc) 
    164          *  
     165         * 
    165166         * @see main.uk.ac.cf.model.EntryHandler#isAfter(uk.ac.cardiff.model.Entry) 
    166167         */ 
     
    174175        /* 
    175176         * (non-Javadoc) 
    176          *  
     177         * 
    177178         * @see 
    178179         * main.uk.ac.cf.model.EntryHandler#isEqualTime(uk.ac.cardiff.model.Entry) 
     
    187188        /* 
    188189         * (non-Javadoc) 
    189          *  
     190         * 
    190191         * @see 
    191192         * main.uk.ac.cf.model.EntryHandler#isNewerOrEqual(uk.ac.cardiff.model.Entry 
     
    203204        /* 
    204205         * (non-Javadoc) 
    205          *  
     206         * 
    206207         * @see main.uk.ac.cf.model.EntryHandler#removeAllEntries() 
    207208         */ 
     
    233234        /* 
    234235         * (non-Javadoc) 
    235          *  
     236         * 
    236237         * @see main.uk.ac.cf.model.EntryHandler#getLatestEntryTime() 
    237238         */ 
     
    243244        /* 
    244245         * (non-Javadoc) 
    245          *  
     246         * 
    246247         * @see 
    247248         * main.uk.ac.cf.model.EntryHandler#setLatestEntryTime(org.joda.time.DateTime 
  • raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/server/RunServer.java

    r604 r628  
     1/** 
     2 * Copyright (C) 2010 Cardiff University, Wales <smartp@cf.ac.uk> 
     3 * 
     4 * Licensed under the Apache License, Version 2.0 (the "License"); 
     5 * you may not use this file except in compliance with the License. 
     6 * You may obtain a copy of the License at 
     7 * 
     8 *         http://www.apache.org/licenses/LICENSE-2.0 
     9 * 
     10 * Unless required by applicable law or agreed to in writing, software 
     11 * distributed under the License is distributed on an "AS IS" BASIS, 
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     13 * See the License for the specific language governing permissions and 
     14 * limitations under the License. 
     15 */ 
    116package uk.ac.cardiff.raptor.raptorica.server; 
    217 
  • raptor-ica-embedded/trunk/src/main/resources/package.xml

    r462 r628  
    11<?xml version="1.0" encoding="UTF-8"?> 
     2<!-- 
     3 
     4    Copyright (C) 2010 Cardiff University, Wales <smartp@cf.ac.uk> 
     5 
     6    Licensed under the Apache License, Version 2.0 (the "License"); 
     7    you may not use this file except in compliance with the License. 
     8    You may obtain a copy of the License at 
     9 
     10            http://www.apache.org/licenses/LICENSE-2.0 
     11 
     12    Unless required by applicable law or agreed to in writing, software 
     13    distributed under the License is distributed on an "AS IS" BASIS, 
     14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     15    See the License for the specific language governing permissions and 
     16    limitations under the License. 
     17 
     18--> 
    219<assembly> 
    320    <id>package</id> 
Note: See TracChangeset for help on using the changeset viewer.