/xservices/trunk/src/main/java/net/brutex/xservices/ws/rs/OpenAirInfoServiceImpl.java |
---|
8,12 → 8,13 |
import javax.ws.rs.core.HttpHeaders; |
import javax.ws.rs.core.Response; |
import lombok.extern.slf4j.Slf4j; |
import org.apache.commons.configuration2.PropertiesConfiguration; |
import org.apache.commons.configuration2.builder.fluent.Configurations; |
import org.apache.commons.configuration2.ex.ConfigurationException; |
import org.apache.commons.jcs.JCS; |
import org.apache.commons.jcs.access.exception.CacheException; |
import org.apache.logging.log4j.LogManager; |
import org.apache.logging.log4j.Logger; |
import net.brutex.mgmt.api.xml.Customer; |
import net.brutex.mgmt.api.xml.DateFilter; |
22,10 → 23,10 |
import net.brutex.mgmt.api.xml.StringEntity; |
import net.brutex.mgmt.openair.OpenAirRestConnection; |
@Slf4j |
public class OpenAirInfoServiceImpl implements OpenAirInfoService { |
static final Logger logger = LogManager.getLogger(); |
@Override |
public Response getCompanies(HttpHeaders paramHttpHeaders, String search) { |
OpenAirRestConnection con = getOpenAirConnection(); |
58,7 → 59,7 |
final PropertiesConfiguration props; |
try { |
final String config = "../openair.properties"; |
log.debug("Loading Open Air connection details from '{}'.", this.getClass().getClassLoader().getResource("/") |
logger.debug("Loading Open Air connection details from " + this.getClass().getClassLoader().getResource("/") |
+ config); |
final URL configloc = this.getClass().getClassLoader().getResource(config); |
75,9 → 76,12 |
con = new OpenAirRestConnection(JCS.getInstance("FileCache"), company, user, password); |
return con; |
} catch (CacheException | ConfigurationException e) { |
log.error(e.getMessage()); |
} catch (CacheException e) { |
logger.error(e); |
e.printStackTrace(); |
} catch (ConfigurationException e) { |
logger.error(e); |
e.printStackTrace(); |
} finally { |
} |
/xservices/trunk/src/main/java/net/brutex/xservices/ws/rs/CVSInfoImpl.java |
---|
12,7 → 12,6 |
import javax.ws.rs.core.HttpHeaders; |
import javax.ws.rs.core.Response; |
import lombok.extern.slf4j.Slf4j; |
import net.brutex.xservices.types.scm.AttributeType; |
import net.brutex.xservices.types.scm.ItemListType; |
import net.brutex.xservices.types.scm.ItemType; |
30,6 → 29,8 |
import org.apache.commons.jcs.JCS; |
import org.apache.commons.jcs.access.CacheAccess; |
import org.apache.commons.jcs.access.exception.CacheException; |
import org.apache.logging.log4j.LogManager; |
import org.apache.logging.log4j.Logger; |
import org.netbeans.lib.cvsclient.Client; |
import org.netbeans.lib.cvsclient.command.CommandAbortedException; |
import org.netbeans.lib.cvsclient.command.CommandException; |
44,9 → 45,8 |
import org.netbeans.lib.cvsclient.event.EventManager; |
import org.netbeans.lib.cvsclient.event.FileInfoEvent; |
@Slf4j |
public class CVSInfoImpl implements CVSInfo { |
private static final Logger logger = LogManager.getLogger(); |
final ObjectFactory FACTORY = new ObjectFactory(); |
final ItemListType list = this.FACTORY.createItemListType(); |
53,7 → 53,7 |
public Response getRepositoryFiles(HttpHeaders h, File f, String modules, |
boolean isRecursive, boolean showRevisions, boolean forceNoCache) { |
String cachekey = "getFiles" + f.toURI().toString(); |
log.debug("forceNoCache=" + forceNoCache); |
CVSInfoImpl.logger.debug("forceNoCache=" + forceNoCache); |
ItemListType cacheresult = (ItemListType) getCacheInstance().get( |
cachekey); |
121,7 → 121,7 |
try { |
CVSInfoImpl.this.getCacheInstance().put(key, cvsfile); |
} catch (CacheException e) { |
log.error("Could not cache item '" |
CVSInfoImpl.logger.error("Could not cache item '" |
+ key + "'", e); |
} |
} |
142,7 → 142,7 |
rlog.setRecursive(isRecursive); |
log.info("Executing CVS command '" + rlog.getCVSCommand() |
CVSInfoImpl.logger.info("Executing CVS command '" + rlog.getCVSCommand() |
+ "' against '" + cvsclient.getRoot().host + "@" |
+ cvsclient.getRoot().repository + "'"); |
client.executeCommand(rlog, cvsclient.getGlobalOptions()); |
149,7 → 149,7 |
getCacheInstance().put(cachekey, this.list); |
} catch (ConfigurationException e) { |
log.error("CVS Configuration File '" + f.getAbsolutePath() |
CVSInfoImpl.logger.error("CVS Configuration File '" + f.getAbsolutePath() |
+ f.getName() + "'not found.", e); |
} catch (CommandAbortedException e) { |
e.printStackTrace(); |
172,7 → 172,7 |
public Response getModules(HttpHeaders h, File f, boolean forceNoCache) { |
String cachekey = "Modules" + f.toURI().toString(); |
log.debug("forceNoCache=" + forceNoCache); |
CVSInfoImpl.logger.debug("forceNoCache=" + forceNoCache); |
ModuleListType response = (ModuleListType) getCacheInstance().get( |
cachekey); |
200,12 → 200,12 |
CheckoutCommand co = new CheckoutCommand(); |
co.setShowModulesWithStatus(true); |
log.info("Executing CVS command '" + co.getCVSCommand() |
CVSInfoImpl.logger.info("Executing CVS command '" + co.getCVSCommand() |
+ "' against '" + cvsclient.getRoot().host + "@" |
+ cvsclient.getRoot().repository + "'"); |
client.executeCommand(co, cvsclient.getGlobalOptions()); |
if (list.getModules().size() == 0) { |
log.warn("Repository '" |
CVSInfoImpl.logger.warn("Repository '" |
+ cvsclient.getRoot().repository |
+ "' does not have modules"); |
} |
220,14 → 220,14 |
public Response getTags(HttpHeaders h, File f, boolean withFiles) { |
String cachekey = f.toURI().toString() + ":taglist"; |
log.debug("Retrieving Tags from cache using key '" + cachekey |
CVSInfoImpl.logger.debug("Retrieving Tags from cache using key '" + cachekey |
+ "'"); |
TagListType tags = (TagListType) getCacheInstance().get(cachekey); |
if (tags != null) { |
log.debug("Delivering Tags from cache."); |
CVSInfoImpl.logger.debug("Delivering Tags from cache."); |
return Response.ok(tags).build(); |
} |
log.warn("Taglist not found in cache."); |
CVSInfoImpl.logger.warn("Taglist not found in cache."); |
return Response.noContent().build(); |
} |
239,17 → 239,17 |
ItemListType list = null; |
if (!forceNoCache) { |
log.debug("Retrieving file content from cache using key '" |
CVSInfoImpl.logger.debug("Retrieving file content from cache using key '" |
+ cachekey + "'"); |
list = (ItemListType) getCacheInstance().get(cachekey); |
} |
if (list != null) { |
log.debug("Delivering file content from cache."); |
CVSInfoImpl.logger.debug("Delivering file content from cache."); |
return Response.ok(list).build(); |
} |
log.warn("File content not found in cache."); |
CVSInfoImpl.logger.warn("File content not found in cache."); |
list = this.FACTORY.createItemListType(); |
try { |
CVSClient cvsclient = new CVSClient(f); |
306,7 → 306,7 |
checkout.setModule(filestring); |
checkout.setPipeToOutput(true); |
log.info("Execute CVS command '" + checkout.getCVSCommand() |
CVSInfoImpl.logger.info("Execute CVS command '" + checkout.getCVSCommand() |
+ "' against '" + cvsclient.getRoot().host + "@" |
+ cvsclient.getRoot().repository + "'"); |
client.executeCommand(checkout, cvsclient.getGlobalOptions()); |
330,10 → 330,10 |
CacheAccess<Object, Object> jcs = null; |
String cacheinstance = "CVSCache"; |
try { |
log.trace("Getting cache instance named 'CVSCache'"); |
CVSInfoImpl.logger.trace("Getting cache instance named 'CVSCache'"); |
jcs = JCS.getInstance("CVSCache"); |
} catch (CacheException e) { |
log.error("Failed to get cache instance", e); |
CVSInfoImpl.logger.error("Failed to get cache instance", e); |
e.printStackTrace(); |
} |
return jcs; |
347,24 → 347,29 |
+ client.getRoot().repository; |
String cachestring = "FINDINGS-" + cvsroot; |
log.debug("Fetch searchFileContent response from cache using cachekey '" |
CVSInfoImpl.logger |
.debug("Fetch searchFileContent response from cache using cachekey '" |
+ cachestring + "'"); |
FindingsListType result = (FindingsListType) getCacheInstance() |
.get(cachestring); |
if (result != null) |
log.debug("Found object for key '" + cachestring |
CVSInfoImpl.logger.debug("Found object for key '" + cachestring |
+ "' in cache."); |
else { |
log.debug("Found no object for key '" + cachestring |
CVSInfoImpl.logger.debug("Found no object for key '" + cachestring |
+ "' in cache."); |
} |
if (result != null) |
return Response.ok(result).build(); |
} catch (CommandAbortedException | AuthenticationException | ConfigurationException e) { |
} catch (CommandAbortedException e) { |
e.printStackTrace(); |
} catch (ConfigurationException e) { |
e.printStackTrace(); |
} catch (AuthenticationException e) { |
e.printStackTrace(); |
} |
return Response.noContent().build(); |
return Response.noContent().build(); |
} |
private AttributeType getAttribute(String name, String value) { |
/xservices/trunk/src/main/java/net/brutex/xservices/ws/rs/DIMCMInfoImpl.java |
---|
33,7 → 33,6 |
import javax.ws.rs.core.Response; |
import javax.ws.rs.core.UriInfo; |
import lombok.extern.slf4j.Slf4j; |
import org.apache.commons.configuration2.PropertiesConfiguration; |
import org.apache.commons.configuration2.builder.fluent.Configurations; |
import org.apache.commons.configuration2.ex.ConfigurationException; |
40,8 → 39,9 |
import org.apache.commons.jcs.JCS; |
import org.apache.commons.jcs.access.CacheAccess; |
import org.apache.commons.jcs.access.exception.CacheException; |
import org.apache.logging.log4j.LogManager; |
import org.apache.logging.log4j.Logger; |
import net.brutex.xservices.cmtypes.ItemType; |
import net.brutex.xservices.cmtypes.ItemTypeList; |
import net.brutex.xservices.types.FileInfoType; |
78,9 → 78,9 |
* |
* @author Brian Rosenberger, bru(at)brutex.de |
*/ |
@Slf4j |
public class DIMCMInfoImpl implements DIMCMInfo { |
Logger logger = LogManager.getLogger(); |
/* |
* (non-Javadoc) |
238,7 → 238,7 |
if (search == null || search.equals("")) { |
search = "*"; |
log.info("No search pattern supplied, using default '*'."); |
logger.info("No search pattern supplied, using default '*'."); |
} |
FileWalker finder = new FileWalker(search); |
245,7 → 245,7 |
try { |
Files.walkFileTree(dir.toPath(), |
EnumSet.of(FileVisitOption.FOLLOW_LINKS), depth, finder); |
log.info("FileWalker returned '" + finder.getCount() |
logger.info("FileWalker returned '" + finder.getCount() |
+ "' hits. '" + finder.getTotal() |
+ "' files have been scanned."); |
List<Path> result = finder.getResult(); |
261,7 → 261,7 |
list.add(new FileInfoType(f, baseuri)); |
} |
} catch (IOException e2) { |
log.error(e2.getMessage(), e2); |
logger.error(e2.getMessage(), e2); |
; |
} |
} |
324,7 → 324,7 |
if (conn != null) |
return conn; |
} catch (Exception e) { |
log.error(e.getMessage()); |
logger.error(e.getMessage()); |
} |
/* |
/xservices/trunk/src/main/java/net/brutex/xservices/ws/rs/FileInfoImpl.java |
---|
47,7 → 47,6 |
import javax.ws.rs.core.StreamingOutput; |
import javax.ws.rs.core.UriInfo; |
import lombok.extern.slf4j.Slf4j; |
import net.brutex.xservices.security.DirectoryPermission; |
import net.brutex.xservices.types.FileInfoType; |
import net.brutex.xservices.util.FileWalker; |
55,6 → 54,8 |
import org.apache.commons.jcs.JCS; |
import org.apache.commons.jcs.access.CacheAccess; |
import org.apache.commons.jcs.access.exception.CacheException; |
import org.apache.logging.log4j.LogManager; |
import org.apache.logging.log4j.Logger; |
import org.apache.shiro.SecurityUtils; |
import org.apache.shiro.authz.UnauthorizedException; |
63,11 → 64,11 |
* |
* @author Brian Rosenberger, bru(at)brutex.de |
*/ |
@Slf4j |
public class FileInfoImpl implements FileInfo { |
Logger logger = LogManager.getLogger(); |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.rs.FileInfo#getFiles(javax.ws.rs.core.HttpHeaders, java.lang.String, boolean, boolean, int, java.lang.String, int, int) |
76,19 → 77,19 |
{ |
if(dir==null) { |
dir = "c:/"; |
log.warn("No directory specified. Default is 'c:/'."); |
logger.warn("No directory specified. Default is 'c:/'."); |
} |
isPermitted(dir); |
URI baseuri = URI.create(uriInfo.getBaseUri()+FileInfo.BASE_PATH+"getFile?file="); |
log.info(String.format("Listing directory '%s'.", dir)); |
logger.info(String.format("Listing directory '%s'.", dir)); |
if (level <= 0) level = 1; |
if ((!withDir) && (!withFiles)) withFiles = true; |
String cachekey = level + "||" + withFiles + "||" + withDir + "||" + search + "||" + dir; |
try { |
log.debug(String.format("Hitting cache with cachekey '%s'", cachekey)); |
logger.debug(String.format("Hitting cache with cachekey '%s'", cachekey)); |
CacheAccess<Object, Object> jcs = JCS.getInstance("FileCache"); |
/*Try to retrieve the file list from the cache*/ |
97,9 → 98,9 |
if (list == null || !useCache) { |
list = setDirectory(baseuri, dir, withDir, withFiles, level, search); |
jcs.put(cachekey, list); |
log.debug("Stored in Cache: " + list.toString()); |
logger.debug("Stored in Cache: " + list.toString()); |
} else { |
log.debug("Got from Cache: " + list.toString()); |
logger.debug("Got from Cache: " + list.toString()); |
} |
int fromIndex = 0; |
109,7 → 110,7 |
if (toIndex > list.size()) toIndex = list.size(); |
if (fromIndex > toIndex) fromIndex = toIndex; |
GenericEntity<List<FileInfoType>> sublist = new GenericEntity<List<FileInfoType>>(list.subList(fromIndex, toIndex)) {}; |
log.info(String.format("Returning items %s to %s from total of %s items in the list.", fromIndex, toIndex, list.size())); |
logger.info(String.format("Returning items %s to %s from total of %s items in the list.", fromIndex, toIndex, list.size())); |
return Response.ok(sublist).build(); |
} catch (CacheException e) { |
return Response.serverError().build(); |
132,13 → 133,13 |
if(search==null || search.equals("") ) { |
search = "*"; |
log.info("No search pattern supplied, using default '*'."); |
logger.info("No search pattern supplied, using default '*'."); |
} |
FileWalker finder = new FileWalker(search); |
try { |
Files.walkFileTree(dir.toPath(), EnumSet.of(FileVisitOption.FOLLOW_LINKS), depth, finder); |
log.info("FileWalker returned '"+finder.getCount()+"' hits. '" + finder.getTotal() + "' files have been scanned."); |
logger.info("FileWalker returned '"+finder.getCount()+"' hits. '" + finder.getTotal() + "' files have been scanned."); |
List<Path> result = finder.getResult(); |
for(Path f : result) { |
if(! withDirectories) { |
150,7 → 151,7 |
list.add(new FileInfoType(f, baseuri)); |
} |
} catch (IOException e2) { |
log.error(e2.getMessage(), e2);; |
logger.error(e2.getMessage(), e2);; |
} |
} |
195,7 → 196,7 |
//In case we can not find the media type for some reason |
//the default assignment is taken, so we can |
//ignore this error. |
log.debug(String.format("Could not probe media type for file '%s'. Default is '%s'", path.toString(), mime.getType()), e); |
logger.debug(String.format("Could not probe media type for file '%s'. Default is '%s'", path.toString(), mime.getType()), e); |
} |
Response r = Response.ok(path.toFile(), mime).build(); |
String fileName = path.getFileName().toString(); |
203,7 → 204,7 |
return r; |
} catch (IOException e1) { |
// TODO Auto-generated catch block |
log.error(e1.getMessage(), e1); |
logger.error(e1.getMessage(), e1); |
return Response.serverError().build(); |
} |
} |
251,7 → 252,7 |
private boolean isPermitted(String dir) { |
if(! SecurityUtils.getSubject().isPermitted( new DirectoryPermission(dir))) { |
log.warn(String.format("User '%s' does not have permission to access '%s'.",SecurityUtils.getSubject().getPrincipal(), dir )); |
logger.warn(String.format("User '%s' does not have permission to access '%s'.",SecurityUtils.getSubject().getPrincipal(), dir )); |
throw new NotAuthorizedException(new UnauthorizedException("User does not have permission to access "+ dir)); |
} |
return true; |