use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project Gaffer by gchq.
the class GraphConfigurationService method getSerialisedFields.
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Need to wrap all runtime exceptions before they are given to the user")
@Override
public Set<String> getSerialisedFields(final String className) {
final Class<?> clazz;
try {
clazz = Class.forName(className);
} catch (final Exception e) {
throw new IllegalArgumentException("Class name was not recognised: " + className, e);
}
final ObjectMapper mapper = new ObjectMapper();
final JavaType type = mapper.getTypeFactory().constructType(clazz);
final BeanDescription introspection = mapper.getSerializationConfig().introspect(type);
final List<BeanPropertyDefinition> properties = introspection.findProperties();
final Set<String> fields = new HashSet<>();
for (final BeanPropertyDefinition property : properties) {
fields.add(property.getName());
}
return fields;
}
use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project jaggery by wso2.
the class TomcatJaggeryWebappsDeployer method handleZipWebappDeployment.
/**
* Handle the deployment of a an archive Jaggery app. i.e., a WAR
*
* @param webapp The WAR Jaggery app file
* @param webContextParams ServletContext params for this webapp
* @param applicationEventListeners Application event listeners
* @throws CarbonException If a deployment error occurs
*/
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
protected void handleZipWebappDeployment(File webapp, List<WebContextParameter> webContextParams, List<Object> applicationEventListeners) throws CarbonException {
synchronized (this) {
String appPath = webapp.getAbsolutePath().substring(0, webapp.getAbsolutePath().indexOf(".zip"));
try {
JaggeryDeploymentUtil.unZip(new FileInputStream(webapp), appPath);
if (!webapp.delete()) {
throw new CarbonException(appPath + "could not be deleted");
}
} catch (FileNotFoundException e) {
throw new CarbonException(e);
}
File unzippedWebapp = new File(appPath);
handleExplodedWebappDeployment(unzippedWebapp, webContextParams, applicationEventListeners);
}
}
use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project jaggery by wso2.
the class WebAppFileManager method getFile.
@SuppressFBWarnings({ "PATH_TRAVERSAL_IN", "PATH_TRAVERSAL_IN" })
@Override
public File getFile(String path) throws ScriptException {
if (path.startsWith(FILE_PATH)) {
return new JavaScriptFileManagerImpl().getFile(path);
}
String oldPath = path;
path = FilenameUtils.normalizeNoEndSeparator(path);
if (path == null) {
String msg = "Invalid file path : " + oldPath;
log.error(msg);
throw new ScriptException(msg);
}
File file = new File(context.getRealPath("/"), path);
if (file.isDirectory()) {
String msg = "File hostobject doesn't handle directories. Specified path contains a directory : " + path;
log.error(msg);
throw new ScriptException(msg);
}
return file;
}
use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project jaggery by wso2.
the class CommandLineExecutor method parseJaggeryScript.
/**
* Parse Jaggery scripts resides in the file path
*
* @param fileURL url of the file
*/
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
static void parseJaggeryScript(final String fileURL) {
FileInputStream fstream = null;
try {
//Initialize the Rhino context
RhinoEngine.enterGlobalContext();
fstream = new FileInputStream(fileURL);
final RhinoEngine engine = CommandLineManager.getCommandLineEngine();
final ScriptableObject scope = engine.getRuntimeScope();
//initialize JaggeryContext
final JaggeryContext jaggeryContext = new JaggeryContext();
jaggeryContext.setTenantDomain(DEFAULT_TENANTDOMAIN);
jaggeryContext.setEngine(engine);
jaggeryContext.setScope(scope);
jaggeryContext.addProperty(CommonManager.JAGGERY_OUTPUT_STREAM, System.out);
RhinoEngine.putContextProperty("jaggeryContext", jaggeryContext);
//Parsing the script
final Reader source = new ScriptReader(new BufferedInputStream(fstream));
out.println("\n");
ShellUtilityService.initializeUtilityServices();
engine.exec(source, scope, null);
ShellUtilityService.destroyUtilityServices();
out.flush();
out.println("\n");
} catch (Exception e) {
out.println("\n");
out.println("Error: " + e.getMessage());
out.println("\n");
} finally {
if (fstream != null) {
try {
fstream.close();
} catch (IOException ignored) {
}
}
}
}
use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project jaggery by wso2.
the class FileHostObject method addFileToZip.
/**
* To add a file to zip
*
* @param path Root path name
* @param srcFile Source File that need to be added to zip
* @param zip ZipOutputStream
* @throws IOException
*/
@SuppressFBWarnings({ "PATH_TRAVERSAL_IN", "PATH_TRAVERSAL_IN" })
private static void addFileToZip(String path, String srcFile, ZipOutputStream zip) throws IOException {
FileInputStream in = null;
try {
File folder = new File(srcFile);
if (folder.isDirectory()) {
addFolderToZip(path, srcFile, zip);
} else {
byte[] buf = new byte[1024];
int len;
in = new FileInputStream(srcFile);
zip.putNextEntry(new ZipEntry(path + File.separator + folder.getName()));
while ((len = in.read(buf)) > 0) {
zip.write(buf, 0, len);
}
}
} catch (IOException er) {
log.error("Cannot add file to zip " + er);
throw new IOException(er);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ex) {
log.error("Unable to close file input stream. " + ex);
}
}
}
}
Aggregations