Search in sources :

Example 16 with SuppressFBWarnings

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;
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) BeanDescription(com.fasterxml.jackson.databind.BeanDescription) BeanPropertyDefinition(com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 17 with SuppressFBWarnings

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);
    }
}
Also used : CarbonException(org.wso2.carbon.CarbonException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 18 with SuppressFBWarnings

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;
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) JavaScriptFileManagerImpl(org.jaggeryjs.hostobjects.file.JavaScriptFileManagerImpl) JavaScriptFile(org.jaggeryjs.hostobjects.file.JavaScriptFile) File(java.io.File) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 19 with SuppressFBWarnings

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) {
            }
        }
    }
}
Also used : ScriptableObject(org.mozilla.javascript.ScriptableObject) ScriptReader(org.jaggeryjs.jaggery.core.ScriptReader) JaggeryContext(org.jaggeryjs.scriptengine.engine.JaggeryContext) RhinoEngine(org.jaggeryjs.scriptengine.engine.RhinoEngine) ScriptReader(org.jaggeryjs.jaggery.core.ScriptReader) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 20 with SuppressFBWarnings

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);
            }
        }
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)142 IOException (java.io.IOException)23 File (java.io.File)22 ArrayList (java.util.ArrayList)20 JPanel (javax.swing.JPanel)14 RollingStock (jmri.jmrit.operations.rollingstock.RollingStock)13 ScriptException (org.jaggeryjs.scriptengine.exceptions.ScriptException)13 FlowLayout (java.awt.FlowLayout)8 BoxLayout (javax.swing.BoxLayout)7 Location (jmri.jmrit.operations.locations.Location)7 Dimension (java.awt.Dimension)5 FileOutputStream (java.io.FileOutputStream)5 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 Iterator (java.util.Iterator)5 JScrollPane (javax.swing.JScrollPane)5 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 List (java.util.List)4 Entry (java.util.Map.Entry)4