Changeset 628
- Timestamp:
- 04/01/11 16:49:04 (2 years ago)
- Location:
- raptor-ica-embedded/trunk
- Files:
-
- 3 added
- 2 deleted
- 11 edited
- 1 moved
-
pom.xml (modified) (1 diff)
-
src/main/config/data-access.xml (modified) (3 diffs)
-
src/main/config/ica-core.xml (modified) (5 diffs)
-
src/main/java/uk/ac/cardiff/raptor/raptorica/dao/BaseEventParser.java (moved) (moved from raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/dao/RawData.java) (5 diffs)
-
src/main/java/uk/ac/cardiff/raptor/raptorica/dao/external/AuthenticationInput.java (deleted)
-
src/main/java/uk/ac/cardiff/raptor/raptorica/dao/external/UsageInput.java (modified) (2 diffs)
-
src/main/java/uk/ac/cardiff/raptor/raptorica/dao/external/file/LogFileParser.java (modified) (12 diffs)
-
src/main/java/uk/ac/cardiff/raptor/raptorica/dao/external/file/LogFileParserForcedIncrement.java (deleted)
-
src/main/java/uk/ac/cardiff/raptor/raptorica/engine/DataAccessRegister.java (modified) (1 diff)
-
src/main/java/uk/ac/cardiff/raptor/raptorica/engine/ICAEngine.java (modified) (5 diffs)
-
src/main/java/uk/ac/cardiff/raptor/raptorica/model/EntryHandler.java (modified) (1 diff)
-
src/main/java/uk/ac/cardiff/raptor/raptorica/model/PersistantEntryHandler.java (modified) (12 diffs)
-
src/main/java/uk/ac/cardiff/raptor/raptorica/model/exception (added)
-
src/main/java/uk/ac/cardiff/raptor/raptorica/model/exception/HeaderException.java (added)
-
src/main/java/uk/ac/cardiff/raptor/raptorica/model/exception/ParserException.java (added)
-
src/main/java/uk/ac/cardiff/raptor/raptorica/server/RunServer.java (modified) (1 diff)
-
src/main/resources/package.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
raptor-ica-embedded/trunk/pom.xml
r588 r628 275 275 276 276 <!-- 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 288 278 <dependency> 289 279 <groupId>postgresql</groupId> -
raptor-ica-embedded/trunk/src/main/config/data-access.xml
r623 r628 23 23 <!-- List all the data access beans, used by the parser --> 24 24 <bean id="dataAccessRegister" class="uk.ac.cardiff.raptor.raptorica.engine.DataAccessRegister"> 25 <property name=" authenticationModules">25 <property name="parsingModules"> 26 26 <list><!-- 27 27 <bean id="shibbolethAccessLFP" class="uk.ac.cardiff.raptor.raptorica.dao.external.file.LogFileParser"> … … 45 45 --> 46 46 <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> 48 48 <property name="logfile"> 49 <value>file:///Users/philsmart/Documents/DataSets/Logs/ idp-audit-17th.log49 <value>file:///Users/philsmart/Documents/DataSets/Logs/shib2comb-sorted-to-20110213.log 50 50 </value> 51 51 </property> … … 53 53 <ref bean="shibIDPAuditFileFormat" /> 54 54 </property> 55 <property name="e ntryType">55 <property name="eventType"> 56 56 <value>uk.ac.cardiff.model.event.ShibbolethIdpAuthenticationEvent</value> 57 57 </property> 58 <property name="printParsingPosition"><value>true</value></property> 58 59 59 60 <!-- 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 22 22 23 23 <!-- Polling trigger setup --> 24 25 26 27 24 <bean id="ICAProcessQuickTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean"> 28 25 <property name="jobDetail"> … … 30 27 </property> 31 28 <property name="repeatInterval" value="30000" /> 32 <!-- <property name="repeatCount" value="0" />-->33 29 </bean> 34 30 … … 48 44 <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> 49 45 <property name="triggers"> 50 <list><!-- 51 <ref local="ICAProcessTrigger" /> 52 --> 46 <list> 53 47 <ref local="ICAProcessQuickTrigger" /> 54 48 </list> … … 86 80 <property name="eventReleaseEngine"><ref bean="eventReleaseEngine"></ref></property> 87 81 </bean> 88 82 89 83 <bean id="eventReleaseEngine" class="uk.ac.cardiff.raptor.registry.EventReleaseEngine"> 90 84 <property name="attributeFilterEngine"><ref bean="attributeFilterEngine"/></property> … … 93 87 94 88 <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.CxfServiceEndpoint Interface"/>89 90 <bean id="serviceEndpointInterface" class="uk.ac.cardiff.raptor.remoting.client.sei.impl.CxfServiceEndpointClient"/> 97 91 98 92 <import resource="dao-beans.xml"/> -
raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/dao/BaseEventParser.java
r621 r628 19 19 package uk.ac.cardiff.raptor.raptorica.dao; 20 20 21 import java.util.Set; 22 21 23 import org.slf4j.Logger; 22 24 import org.slf4j.LoggerFactory; 23 25 26 import uk.ac.cardiff.model.event.Event; 24 27 import uk.ac.cardiff.raptor.raptorica.model.EntryHandler; 28 import uk.ac.cardiff.raptor.raptorica.model.exception.ParserException; 29 import uk.ac.cardiff.raptor.raptorica.model.filter.ExclusionList; 30 import uk.ac.cardiff.raptor.raptorica.model.filter.InclusionList; 25 31 26 32 … … 30 36 * 31 37 */ 32 public abstract class RawData{38 public abstract class BaseEventParser { 33 39 34 /* class logger */35 private final Logger log = LoggerFactory.getLogger( RawData.class);40 /** class logger */ 41 private final Logger log = LoggerFactory.getLogger(BaseEventParser.class); 36 42 37 43 /** The handler that is responsible for storing events */ 38 pr ivateEntryHandler entryHandler;44 protected EntryHandler entryHandler; 39 45 40 public abstract void parse() throws Exception; 46 /** A list of <fieldname,value> pairs that should be excluded during parsing */ 47 private ExclusionList exclusionList; 41 48 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() { 44 56 } 45 57 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 */ 46 72 public Object createObject(String className) { 47 73 Object object = null; … … 49 75 Class classDefinition = Class.forName(className); 50 76 object = classDefinition.newInstance(); 51 // this.setBeanProperty(object, "applicationContext",52 // this.getApplicationContext());53 77 } catch (InstantiationException e) { 54 78 log.warn(e.getMessage()); … … 62 86 63 87 /** 64 * removesall entries from the entry handler88 * Method to remove all entries from the entry handler 65 89 */ 66 90 public void removeAllEntries() { 67 getEntryHandler().removeAllEntries();91 entryHandler.removeAllEntries(); 68 92 69 93 } 70 94 95 /** 96 * Sets and initialises the entry handler 97 * 98 * @param entryHandler 99 */ 71 100 public void setEntryHandler(EntryHandler entryHandler) { 72 101 this.entryHandler = entryHandler; … … 74 103 } 75 104 105 /** 106 * Gets the entry handler 107 * 108 * @return 109 */ 76 110 public EntryHandler getEntryHandler() { 77 111 return entryHandler; 78 112 } 79 113 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 80 166 } -
raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/dao/external/UsageInput.java
r454 r628 22 22 import java.util.Set; 23 23 24 import uk.ac.cardiff.raptor.raptorica.dao. RawData;24 import uk.ac.cardiff.raptor.raptorica.dao.BaseEventParser; 25 25 26 26 /** … … 28 28 * 29 29 */ 30 public abstract class UsageInput extends RawData{30 public abstract class UsageInput extends BaseEventParser{ 31 31 32 32 -
raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/dao/external/file/LogFileParser.java
r617 r628 17 17 18 18 import java.io.BufferedReader; 19 import java.io.FileInputStream;20 19 import java.io.IOException; 21 20 import java.io.InputStream; 22 21 import java.io.InputStreamReader; 23 22 import java.lang.reflect.Method; 23 import java.net.MalformedURLException; 24 24 import java.net.URL; 25 25 import java.net.URLConnection; 26 26 import java.util.ArrayList; 27 import java.util.LinkedHashSet;28 27 import java.util.List; 29 import java.util.Map;30 import java.util.Properties;31 import java.util.Set;32 28 import java.util.TimeZone; 33 29 import java.io.BufferedInputStream; 34 30 35 import uk.ac.cardiff.raptor.raptorica.dao. external.AuthenticationInput;31 import uk.ac.cardiff.raptor.raptorica.dao.BaseEventParser; 36 32 import uk.ac.cardiff.raptor.raptorica.dao.external.format.Header; 37 33 import 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;34 import uk.ac.cardiff.raptor.raptorica.model.exception.HeaderException; 35 import uk.ac.cardiff.raptor.raptorica.model.exception.ParserException; 40 36 import uk.ac.cardiff.raptor.raptorica.model.filter.ExclusionEntry; 41 37 import uk.ac.cardiff.raptor.raptorica.model.filter.InclusionEntry; … … 48 44 import org.slf4j.Logger; 49 45 import org.slf4j.LoggerFactory; 50 import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;51 46 52 47 import uk.ac.cardiff.raptor.raptorica.runtimeutils.ReflectionHelper; 53 import uk.ac.cardiff.model.*;54 48 import uk.ac.cardiff.model.event.Event; 55 49 56 50 /** 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 * 57 54 * @author phil 58 55 * 59 * This is the primary log file parser.60 *61 56 */ 62 public class LogFileParser extends AuthenticationInput { 63 static Logger log = LoggerFactory.getLogger(LogFileParser.class); 57 public 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 */ 64 63 private LogFileFormat format; 64 65 /** The fully qualified path of the log file */ 65 66 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 */ 68 77 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); 108 117 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()) { 114 171 case DATE: 115 addDate(value, header.getDateTimeFormat(), header.getTimeZone(), header.getFieldName(), authE);172 addDate(value, header.getDateTimeFormat(), header.getTimeZone(), header.getFieldName(), authE); 116 173 break; 117 174 case STRING: … … 124 181 addStringList(value, header.getFieldName(), authE, header.getListDelimeter()); 125 182 break; 126 }127 128 } else {129 log.error("trying to access field " + header.getFieldNo() + ", when only " + allvalues.size() + " fields in log file \n --> " + inputLine);130 183 } 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; 148 214 } 149 215 } 150 216 } 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; 167 237 } 168 238 } 169 239 } 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 210 249 * 211 250 * @param logfileURL … … 215 254 private int count(URL logfileURL) throws IOException { 216 255 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; 229 268 } 230 269 … … 237 276 try { 238 277 String[] splitValue = value.split(delimeter); 239 // for (String s : splitValue)log.debug(s);240 278 String fieldAsMethod = ReflectionHelper.prepareMethodNameSet(fieldName); 241 279 setValueOnObject(fieldAsMethod, splitValue, object); 242 280 } 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 }); 245 282 } 246 283 } … … 249 286 try { 250 287 /* 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 254 290 */ 291 // TODO check this 255 292 if (value.endsWith("Z")) 256 293 value = value.substring(0, value.length() - 1); … … 262 299 setValueOnObject(fieldAsMethod, dt, object); 263 300 } 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 }); 266 302 } 267 303 … … 273 309 setValueOnObject(fieldAsMethod, value, object); 274 310 } 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 }); 277 312 } 278 313 … … 281 316 private void addInteger(String value, String fieldName, Object object) { 282 317 try { 283 Integer valueAsInt = new Integer(Integer.parseInt(value));284 318 String fieldAsMethod = ReflectionHelper.prepareMethodNameSet(fieldName); 285 319 setValueOnObject(fieldAsMethod, value, object); 286 320 } 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 }); 289 322 } 290 323 … … 293 326 private Object getValueFromObject(String fieldname, Object object) { 294 327 try { 295 Class id = object.getClass();328 Class<? extends Object> id = object.getClass(); 296 329 String fieldAsMethod = ReflectionHelper.prepareMethodNameGet(fieldname); 297 330 Method getter = id.getMethod(fieldAsMethod, new Class[] {}); 298 // log.debug("Trying to Set :"+param)299 331 Object result = getter.invoke(object, new Object[] {}); 300 332 return result; 301 333 } 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); 306 335 } 307 336 return null; … … 310 339 private void setValueOnObject(String fieldname, Object param, Object object) { 311 340 try { 312 Class id = object.getClass();341 Class<? extends Object> id = object.getClass(); 313 342 Method setter = id.getMethod(fieldname, new Class[] { param.getClass() }); 314 // log.debug("Trying to Set :"+param)315 343 setter.invoke(object, new Object[] { param }); 316 344 } 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 } 326 348 } 327 349 … … 342 364 } 343 365 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 } 358 394 359 395 } -
raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/engine/DataAccessRegister.java
r454 r628 24 24 import org.apache.log4j.Logger; 25 25 26 import uk.ac.cardiff.raptor.raptorica.dao. external.AuthenticationInput;26 import uk.ac.cardiff.raptor.raptorica.dao.BaseEventParser; 27 27 28 28 /** 29 29 * @author philsmart 30 30 * 31 * Provides a register for parsing engines to plugin to. Also manages such engines.31 * Provides a register for parsing modules to attach to. 32 32 */ 33 33 public class DataAccessRegister { 34 static Logger log = Logger.getLogger(DataAccessRegister.class);35 34 36 private List<AuthenticationInput> authenticationModules; 35 /** Class logger */ 36 private final Logger log = Logger.getLogger(DataAccessRegister.class); 37 37 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 */ 38 44 public DataAccessRegister(){ 39 setAuthenticationModules(new ArrayList<AuthenticationInput>());45 setParsingModules(new ArrayList<BaseEventParser>()); 40 46 } 41 47 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; 45 57 } 46 58 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; 49 66 } 50 67 -
raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/engine/ICAEngine.java
r617 r628 20 20 21 21 import java.util.ArrayList; 22 import java.util.LinkedHashSet;23 22 import java.util.List; 24 import java.util.Set;25 23 26 24 import uk.ac.cardiff.raptor.exceptions.ReleaseFailureException; 27 import uk.ac.cardiff.raptor.raptorica.dao.external.AuthenticationInput; 28 import uk.ac.cardiff.raptor.registry.EventReleaseEngine; 25 import uk.ac.cardiff.raptor.raptorica.dao.BaseEventParser; 29 26 import uk.ac.cardiff.raptor.remoting.client.EventReleaseClient; 30 27 … … 37 34 /** 38 35 * @author philsmart 39 * 36 * 40 37 * Responsible for ALL low level capture operations 41 38 */ … … 54 51 55 52 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(); 59 56 } 60 57 } … … 69 66 private void retrieveTransactionFinished() { 70 67 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(); 73 70 } 74 log.debug("Retrieve Transaction Finished, entries are being removed f orm the ICA...done");71 log.debug("Retrieve Transaction Finished, entries are being removed from the ICA...done"); 75 72 76 73 } … … 79 76 * Converts all information from all modules into a single list that is sent 80 77 * to the release engine 81 * 78 * 82 79 * @return 83 80 */ 84 81 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()); 88 85 } 89 86 90 87 boolean success = false; 91 88 try { -
raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/model/EntryHandler.java
r617 r628 19 19 package uk.ac.cardiff.raptor.raptorica.model; 20 20 21 import java.util.ArrayList;22 import java.util.List;23 21 import java.util.Set; 24 22 -
raptor-ica-embedded/trunk/src/main/java/uk/ac/cardiff/raptor/raptorica/model/PersistantEntryHandler.java
r617 r628 36 36 /** 37 37 * @author philsmart 38 * 38 * 39 39 */ 40 40 public class PersistantEntryHandler implements EntryHandler { 41 41 42 42 /* class logger */ 43 staticLogger log = LoggerFactory.getLogger(PersistantEntryHandler.class);43 private final Logger log = LoggerFactory.getLogger(PersistantEntryHandler.class); 44 44 45 45 /* information about entries, e.g. last entry */ … … 64 64 log.info("Persistant entry handler [{}] initialising", this); 65 65 Integer rowCount = (Integer) dataConnection.runQueryUnique("select count(*) from Event", null); 66 log.info("Persistent data store has {} e ntries", rowCount);66 log.info("Persistent data store has {} events", rowCount); 67 67 entryInformation = (EntryMetadata) dataConnection.runQueryUnique("from EntryMetadata", null); 68 68 log.debug("Have saved entryInformaiton: " + entryInformation); … … 71 71 log.debug("Entry Information " + entryInformation.getLatestEqualEntries()); 72 72 // 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>(); 75 76 log.info("Persistant entry handler [{}] started", this); 76 77 } … … 78 79 /* 79 80 * (non-Javadoc) 80 * 81 * 81 82 * @see main.uk.ac.cf.model.EntryHandler#addEntries(java.util.List) 82 83 */ … … 138 139 /* 139 140 * (non-Javadoc) 140 * 141 * 141 142 * @see main.uk.ac.cf.model.EntryHandler#endTransaction() 142 143 */ … … 152 153 /* 153 154 * (non-Javadoc) 154 * 155 * 155 156 * @see main.uk.ac.cf.model.EntryHandler#getEntries() 156 157 */ … … 162 163 /* 163 164 * (non-Javadoc) 164 * 165 * 165 166 * @see main.uk.ac.cf.model.EntryHandler#isAfter(uk.ac.cardiff.model.Entry) 166 167 */ … … 174 175 /* 175 176 * (non-Javadoc) 176 * 177 * 177 178 * @see 178 179 * main.uk.ac.cf.model.EntryHandler#isEqualTime(uk.ac.cardiff.model.Entry) … … 187 188 /* 188 189 * (non-Javadoc) 189 * 190 * 190 191 * @see 191 192 * main.uk.ac.cf.model.EntryHandler#isNewerOrEqual(uk.ac.cardiff.model.Entry … … 203 204 /* 204 205 * (non-Javadoc) 205 * 206 * 206 207 * @see main.uk.ac.cf.model.EntryHandler#removeAllEntries() 207 208 */ … … 233 234 /* 234 235 * (non-Javadoc) 235 * 236 * 236 237 * @see main.uk.ac.cf.model.EntryHandler#getLatestEntryTime() 237 238 */ … … 243 244 /* 244 245 * (non-Javadoc) 245 * 246 * 246 247 * @see 247 248 * 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 */ 1 16 package uk.ac.cardiff.raptor.raptorica.server; 2 17 -
raptor-ica-embedded/trunk/src/main/resources/package.xml
r462 r628 1 1 <?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 --> 2 19 <assembly> 3 20 <id>package</id>
Note: See TracChangeset
for help on using the changeset viewer.
