Example usage for java.lang Error Error

List of usage examples for java.lang Error Error

Introduction

In this page you can find the example usage for java.lang Error Error.

Prototype

public Error(Throwable cause) 

Source Link

Document

Constructs a new error with the specified cause and a detail message of (cause==null ?

Usage

From source file:com.adito.rss.FeedManager.java

/**
 * Get an instance of the feed manager//w  w w  . j  a  v  a 2 s . co  m
 * 
 * @return feed manager
 */
public static FeedManager getInstance() {
    if (instance == null) {
        try {
            URL baseLocation = new URL(SystemProperties.get("adito.rssFeeds.baseLocation", FEED_3SP_URL));
            instance = new FeedManager(baseLocation);
        } catch (MalformedURLException murle) {
            try {
                URL baseLocation = new URL(FEED_3SP_URL);
                instance = new FeedManager(baseLocation);
            } catch (MalformedURLException murle2) {
                // Should not happen
                throw new Error("Invalid default feed location.");
            }
        }
    }
    return instance;
}

From source file:edu.unc.lib.dl.cdr.sword.server.deposit.AtomPubEntryDepositHandler.java

@Override
public DepositReceipt doDeposit(PID destination, Deposit deposit, PackagingType type, SwordConfiguration config,
        String depositor, String owner) throws SwordError {
    log.debug("Preparing to perform an Atom Pub entry metadata only deposit to " + destination.getPid());

    if (deposit.getSwordEntry() == null || deposit.getSwordEntry().getEntry() == null)
        throw new SwordError(UriRegistry.ERROR_CONTENT, 415, "No AtomPub entry was included in the submission");

    if (log.isDebugEnabled()) {
        Abdera abdera = new Abdera();
        Writer writer = abdera.getWriterFactory().getWriter("prettyxml");
        try {/*from ww  w .  j  av  a  2  s .c  o  m*/
            writer.writeTo(deposit.getSwordEntry().getEntry(), System.out);
        } catch (IOException e) {
            throw new Error(e);
        }
    }

    PID depositPID = null;
    UUID depositUUID = UUID.randomUUID();
    depositPID = new PID("uuid:" + depositUUID.toString());
    File dir = makeNewDepositDirectory(depositPID.getUUID());
    dir.mkdir();

    // write SWORD Atom entry to file
    File atomFile = new File(dir, "atom.xml");
    Abdera abdera = new Abdera();

    try (FileOutputStream fos = new FileOutputStream(atomFile)) {
        Writer writer = abdera.getWriterFactory().getWriter("prettyxml");
        writer.writeTo(deposit.getSwordEntry().getEntry(), fos);
    } catch (IOException e) {
        throw new SwordError(ErrorURIRegistry.INGEST_EXCEPTION, 400,
                "Unable to unpack your deposit: " + deposit.getFilename(), e);
    }

    // write deposit file to data directory
    if (deposit.getFile() != null) {
        File dataDir = new File(dir, "data");
        dataDir.mkdirs();
        File depositFile = new File(dataDir, deposit.getFilename());
        try {
            FileUtils.moveFile(deposit.getFile(), depositFile);
        } catch (IOException e) {
            throw new Error(e);
        }
    }

    registerDeposit(depositPID, destination, deposit, type, depositor, owner,
            Collections.<String, String>emptyMap());
    return buildReceipt(depositPID, config);
}

From source file:com.sslexplorer.rss.FeedManager.java

/**
 * Get an instance of the feed manager/*from  w  w w.  j  a  v  a  2  s  . c  om*/
 * 
 * @return feed manager
 */
public static FeedManager getInstance() {
    if (instance == null) {
        try {
            URL baseLocation = new URL(SystemProperties.get("sslexplorer.rssFeeds.baseLocation", FEED_3SP_URL));
            instance = new FeedManager(baseLocation);
        } catch (MalformedURLException murle) {
            try {
                URL baseLocation = new URL(FEED_3SP_URL);
                instance = new FeedManager(baseLocation);
            } catch (MalformedURLException murle2) {
                // Should not happen
                throw new Error("Invalid default feed location.");
            }
        }
    }
    return instance;
}

From source file:com.genentech.struchk.NormalizerPool.java

/**
 * Check a molfile./*from   w  w w .  jav a  2  s .  c o  m*/
 * @param gneStructFlag may be "" in which case the structure flag is guessed from the
 *        specified stereo centers.
 */
public GNEMolecule normalizeMol(String molStr, String gneStructFlag) {
    PooledNormalizer pnorm = null;
    try {
        pnorm = (PooledNormalizer) pool.borrowObject();
        return pnorm.norm.normalizeMol(molStr, gneStructFlag);
    } catch (Exception e) {
        handleException(pnorm, e);
        throw new Error(e);
    } finally {
        returnToPool(pnorm);
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission.java

public EditSubmission(Map<String, String[]> queryParameters, EditConfiguration editConfig) {
    if (editConfig == null)
        throw new Error("EditSubmission needs an EditConfiguration");
    this.editKey = editConfig.getEditKey();
    if (this.editKey == null || this.editKey.trim().length() == 0)
        throw new Error("EditSubmission needs an 'editKey' parameter from the EditConfiguration");

    validationErrors = new HashMap<String, String>();

    this.urisFromForm = new HashMap<String, String>();
    for (String var : editConfig.getUrisOnform()) {
        String[] valuesArray = queryParameters.get(var);
        String uri = null;//ww w .  j a va 2s . c  om
        List<String> values = (valuesArray != null) ? Arrays.asList(valuesArray) : null;
        if (values != null && values.size() > 0) {
            if (values.size() == 1) {
                uri = values.get(0);
            } else if (values.size() > 1) {
                uri = values.get(0);
                log.error("Cannot yet handle multiple URIs for a single field, using first URI on list");
            }
            urisFromForm.put(var, uri);
        } else {
            log.debug("No value found for query parameter " + var);
        }
        //check to see if a URI field from the form was blank but was intended to create a new URI
        if (uri != null && uri.length() == 0 && editConfig.getNewResources().containsKey(var)) {
            log.debug("A new resource URI will be made for var " + var + " since it was blank on the form.");
            urisFromForm.remove(var);
        }
    }
    this.literalsFromForm = new HashMap<String, Literal>();
    for (String var : editConfig.getLiteralsOnForm()) {
        Field field = editConfig.getField(var);
        if (field == null) {
            log.error("could not find field " + var + " in EditConfiguration");
            continue;
        }
        if (field.getOptionsType() == Field.OptionsType.DATETIME
                || XSD.dateTime.getURI().equals(field.getRangeDatatypeUri())) {
            Literal literal = getDateTime(queryParameters, var);
            if (literal != null) {
                literalsFromForm.put(var, literal);
            } else {
                log.debug("datetime fields for parameter " + var + " were not on form");
            }
        } else if (field.getOptionsType() == Field.OptionsType.DATE
                || XSD.date.getURI().equals(field.getRangeDatatypeUri())) {
            Literal literal = getDate(queryParameters, var);
            if (literal != null) {
                literalsFromForm.put(var, literal);
            } else {
                log.debug("date fields for parameter " + var + " were not on form");
            }
        } else if (field.getOptionsType() == Field.OptionsType.TIME
                || XSD.time.getURI().equals(field.getRangeDatatypeUri())) {
            Literal literal = getTime(queryParameters, var);
            if (literal != null) {
                literalsFromForm.put(var, literal);
            } else {
                log.debug("time fields for parameter " + var + " were not on form");
            }
        } else if (field.getEditElement() != null) {
            log.debug("skipping field with edit element, it should not be in literals on form list");
        } else {
            String[] valuesArray = queryParameters.get(var);
            List<String> valueList = (valuesArray != null) ? Arrays.asList(valuesArray) : null;
            if (valueList != null && valueList.size() > 0) {
                String value = valueList.get(0);

                // remove any characters that are not valid in XML 1.0
                // from user input so they don't cause problems
                // with model serialization
                value = EditN3Utils.stripInvalidXMLChars(value);

                if (!StringUtils.isEmpty(value)) {
                    literalsFromForm.put(var,
                            createLiteral(value, field.getRangeDatatypeUri(), field.getRangeLang()));
                }

                if (valueList != null && valueList.size() > 1)
                    log.debug("For field " + var + ", cannot yet handle multiple "
                            + "Literals for a single field, using first Literal on list");

            } else {
                log.debug("could not find value for parameter " + var);
            }
        }
    }

    if (log.isDebugEnabled()) {
        for (String key : literalsFromForm.keySet()) {
            log.debug(key + " literal " + literalsFromForm.get(key));
        }
        for (String key : urisFromForm.keySet()) {
            log.debug(key + " uri " + urisFromForm.get(key));
        }
    }

    processEditElementFields(editConfig, queryParameters);

    this.basicValidation = new BasicValidation(editConfig, this);
    Map<String, String> errors = basicValidation.validateUris(urisFromForm);
    if (errors != null) {
        validationErrors.putAll(errors);
    }

    errors = basicValidation.validateLiterals(literalsFromForm);
    if (errors != null) {
        validationErrors.putAll(errors);
    }

    if (editConfig.getValidators() != null) {
        for (N3Validator validator : editConfig.getValidators()) {
            if (validator != null) {
                errors = validator.validate(editConfig, this);
                if (errors != null)
                    validationErrors.putAll(errors);
            }
        }
    }

    if (log.isDebugEnabled())
        log.debug(this.toString());
}

From source file:edu.unc.lib.dl.xml.ModsXmlHelperTest.java

@Test
public void testTransform() {
    Document mods = null;/*from www  .  j av  a  2 s.co  m*/
    Document result = null;
    SAXBuilder builder = new SAXBuilder();
    try {
        mods = builder.build("src/test/resources/samples/mods.xml");
        result = ModsXmlHelper.transform(mods.getRootElement());
    } catch (JDOMException e) {
        throw new Error(e);
    } catch (IOException e) {
        throw new Error(e);
    } catch (TransformerException e) {
        throw new Error(e);
    }
    if (log.isInfoEnabled()) {
        XMLOutputter out = new XMLOutputter();
        String str = out.outputString(result);
        log.info(str);
    }
    assertTrue("Must have proper number of DC elements", 5 == result.getRootElement().getChildren().size());
}

From source file:com.proofpoint.zookeeper.io.TempLocalDirectory.java

public void cleanupPrevious() {
    try {//from www.  j  ava2 s.  c  o  m
        FileUtils.cleanDirectory(path);
        log.debug("Cleaned up local temp dir: " + path.getAbsolutePath());
    } catch (IOException e) {
        log.warn(e, "Error cleaning up temp local directory: %s", path.getAbsolutePath());
        throw new Error(e);
    }
}

From source file:io.servicecomb.core.definition.loader.SchemaLoader.java

/**
 * resource??schemaId.yaml// w  w  w .ja  va 2s .com
 */
public SchemaMeta registerSchema(String microserviceName, Resource resource) {
    try {
        String schemaId = FilenameUtils.getBaseName(resource.getFilename());

        String swaggerContent = IOUtils.toString(resource.getURL());
        SchemaMeta schemaMeta = registerSchema(microserviceName, schemaId, swaggerContent);

        return schemaMeta;
    } catch (Throwable e) {
        throw new Error(e);
    }
}

From source file:org.fcrepo.examples.models.integration.ExampleNodeTypesIT.java

public ExampleNodeTypesIT() {
    connectionManager = new PoolingHttpClientConnectionManager();
    connectionManager.setMaxTotal(Integer.MAX_VALUE);
    connectionManager.setDefaultMaxPerRoute(20);
    connectionManager.closeIdleConnections(3, TimeUnit.SECONDS);
    client = HttpClientBuilder.create().setConnectionManager(connectionManager).build();
    modelSetsDirectory = new File(modelSetsPath);
    if (!modelSetsDirectory.exists()) {
        throw new Error("Cannot find model sets");
    }/*from w w w .  ja  va2s .c  om*/
}

From source file:com.osbitools.ws.shared.prj.web.AbstractWsPrjInit.java

@Override
public void contextInitialized(ServletContextEvent evt) {
    super.contextInitialized(evt);
    ServletContext ctx = evt.getServletContext();

    // First - Load Custom Error List 
    try {//from   w ww. j  av  a 2 s  . c  o m
        Class.forName("com.osbitools.ws.shared.prj.CustErrorList");
    } catch (ClassNotFoundException e) {
        // Ignore Error 
    }

    // Initialize Entity Utils
    IEntityUtils eut = getEntityUtils();
    ctx.setAttribute("entity_utils", eut);

    // Initiate LangSetFileUtils
    ctx.setAttribute("ll_set_utils", new LangSetUtils());

    // Check if git repository exists and create one
    // Using ds subdirectory as git root repository 
    File drepo = new File(
            getConfigDir(ctx) + File.separator + eut.getPrjRootDirName() + File.separator + ".git");
    Git git;
    try {

        if (!drepo.exists()) {
            if (!drepo.mkdirs())
                throw new RuntimeErrorException(
                        new Error("Unable create directory '" + drepo.getAbsolutePath() + "'"));

            try {
                git = createGitRepo(drepo);
            } catch (Exception e) {
                throw new RuntimeErrorException(new Error(
                        "Unable create new repo on path: " + drepo.getAbsolutePath() + ". " + e.getMessage()));
            }

            getLogger(ctx).info("Created new git repository '" + drepo.getAbsolutePath() + "'");
        } else if (!drepo.isDirectory()) {
            throw new RuntimeErrorException(
                    new Error(drepo.getAbsolutePath() + " is regular file and not a directory"));
        } else {
            git = Git.open(drepo);
            getLogger(ctx).debug("Open existing repository " + drepo.getAbsolutePath());
        }
    } catch (IOException e) {
        // Something unexpected and needs to be analyzed
        e.printStackTrace();

        throw new RuntimeErrorException(new Error(e));
    }

    // Save git handler
    ctx.setAttribute("git", git);

    // Check if remote destination set/changed
    StoredConfig config = git.getRepository().getConfig();
    String rname = (String) ctx.getAttribute(PrjMgrConstants.PREMOTE_GIT_NAME);
    String rurl = (String) ctx.getAttribute("git_remote_url");

    if (!Utils.isEmpty(rname) && !Utils.isEmpty(rurl)) {
        String url = config.getString("remote", rname, "url");
        if (!rurl.equals(url)) {
            config.setString("remote", rname, "url", rurl);
            try {
                config.save();
            } catch (IOException e) {
                getLogger(ctx).error("Error saving git remote url. " + e.getMessage());
            }
        }
    }

    // Temp directory for files upload
    String tname = System.getProperty("java.io.tmpdir");
    getLogger(ctx).info("Using temporarily directory '" + tname + "' for file uploads");
    File tdir = new File(tname);

    if (!tdir.exists())
        throw new RuntimeErrorException(
                new Error("Temporarily directory for file upload '" + tname + "' is not found"));
    if (!tdir.isDirectory())
        throw new RuntimeErrorException(
                new Error("Temporarily directory for file upload '" + tname + "' is not a directory"));

    DiskFileItemFactory dfi = new DiskFileItemFactory();
    dfi.setSizeThreshold(
            ((Integer) ctx.getAttribute(PrjMgrConstants.SMAX_FILE_UPLOAD_SIZE_NAME)) * 1024 * 1024);
    dfi.setRepository(tdir);
    evt.getServletContext().setAttribute("dfi", dfi);

    // Save entity utils in context
    evt.getServletContext().setAttribute("entity_utils", getEntityUtils());
}