Example usage for javax.management InvalidAttributeValueException getMessage

List of usage examples for javax.management InvalidAttributeValueException getMessage

Introduction

In this page you can find the example usage for javax.management InvalidAttributeValueException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.cyberway.issue.crawler.admin.CrawlJobHandler.java

/**
 * Creates a new settings handler based on an existing job. Basically all
 * the settings file for the 'based on' will be copied to the specified
 * directory./*from   ww  w.  ja v a2  s. c  o  m*/
 *
 * @param orderFile Order file to base new order file on.  Cannot be null.
 * @param name Name for the new settings
 * @param description Description of the new settings.
 * @param seeds The contents of the new settings' seed file.
 * @param newSettingsDir
 * @param errorHandler
 * @param filename Name of new order file.
 * @param seedfile Name of new seeds file.
 *
 * @return The new settings handler.
 * @throws FatalConfigurationException
 *             If there are problems with reading the 'base on'
 *             configuration, with writing the new configuration or it's
 *             seed file.
 */
protected XMLSettingsHandler createSettingsHandler(final File orderFile, final String name,
        final String description, final String seeds, final File newSettingsDir,
        final CrawlJobErrorHandler errorHandler, final String filename, final String seedfile)
        throws FatalConfigurationException {
    XMLSettingsHandler newHandler = null;
    try {
        newHandler = new XMLSettingsHandler(orderFile);
        if (errorHandler != null) {
            newHandler.registerValueErrorHandler(errorHandler);
        }
        newHandler.setErrorReportingLevel(errorHandler.getLevel());
        newHandler.initialize();
    } catch (InvalidAttributeValueException e2) {
        throw new FatalConfigurationException("InvalidAttributeValueException occured while creating"
                + " new settings handler for new job/profile\n" + e2.getMessage());
    }

    // Make sure the directory exists.
    newSettingsDir.mkdirs();

    try {
        // Set the seed file
        ((ComplexType) newHandler.getOrder().getAttribute("scope"))
                .setAttribute(new Attribute("seedsfile", seedfile));
    } catch (AttributeNotFoundException e1) {
        throw new FatalConfigurationException(
                "AttributeNotFoundException occured while setting up" + "new job/profile\n" + e1.getMessage());
    } catch (InvalidAttributeValueException e1) {
        throw new FatalConfigurationException("InvalidAttributeValueException occured while setting"
                + "up new job/profile\n" + e1.getMessage());
    } catch (MBeanException e1) {
        throw new FatalConfigurationException(
                "MBeanException occured while setting up new" + " job/profile\n" + e1.getMessage());
    } catch (ReflectionException e1) {
        throw new FatalConfigurationException(
                "ReflectionException occured while setting up" + " new job/profile\n" + e1.getMessage());
    }

    File newFile = new File(newSettingsDir.getAbsolutePath(), filename);

    try {
        newHandler.copySettings(newFile,
                (String) newHandler.getOrder().getAttribute(CrawlOrder.ATTR_SETTINGS_DIRECTORY));
    } catch (IOException e3) {
        // Print stack trace to help debug issue where cannot create
        // new job from an old that has overrides.
        e3.printStackTrace();
        throw new FatalConfigurationException("IOException occured while writing new settings files"
                + " for new job/profile\n" + e3.getMessage());
    } catch (AttributeNotFoundException e) {
        throw new FatalConfigurationException("AttributeNotFoundException occured while writing new"
                + " settings files for new job/profile\n" + e.getMessage());
    } catch (MBeanException e) {
        throw new FatalConfigurationException("MBeanException occured while writing new settings files"
                + " for new job/profile\n" + e.getMessage());
    } catch (ReflectionException e) {
        throw new FatalConfigurationException("ReflectionException occured while writing new settings"
                + " files for new job/profile\n" + e.getMessage());
    }
    CrawlerSettings orderfile = newHandler.getSettingsObject(null);

    orderfile.setName(name);
    orderfile.setDescription(description);

    if (seeds != null) {
        BufferedWriter writer = null;
        try {
            writer = new BufferedWriter(new FileWriter(newHandler.getPathRelativeToWorkingDirectory(seedfile)));
            try {
                writer.write(seeds);
            } finally {
                writer.close();
            }
        } catch (IOException e) {
            throw new FatalConfigurationException(
                    "IOException occured while writing seed file for new" + " job/profile\n" + e.getMessage());
        }
    }
    return newHandler;
}

From source file:com.cyberway.issue.crawler.admin.CrawlJob.java

/**
 * A constructor for reloading jobs from disk. Jobs (not profiles) have
 * their data written to persistent storage in the file system. This method
 * is used to load the job from such storage. This is done by the
 * <code>CrawlJobHandler</code>.
 * <p>/*from  w w w .j a v  a 2 s  . c o m*/
 * Proper structure of a job file (TODO: Maybe one day make this an XML file)
 * Line 1. UID <br>
 * Line 2. Job name (string) <br>
 * Line 3. Job status (string) <br>
 * Line 4. is job read only (true/false) <br>
 * Line 5. is job running (true/false) <br>
 * Line 6. job priority (int) <br>
 * Line 7. number of journal entries <br>
 * Line 8. setting file (with path) <br>
 * Line 9. statistics tracker file (with path) <br>
 * Line 10-?. error message (String, empty for null), can be many lines <br>
 * @param jobFile
 *            a file containing information about the job to load.
 * @param errorHandler The crawl jobs settings error handler.
 *            null means none is set
 * @throws InvalidJobFileException
 *            if the specified file does not refer to a valid job file.
 * @throws IOException
 *            if io operations fail
 */
protected CrawlJob(final File jobFile, final CrawlJobErrorHandler errorHandler)
        throws InvalidJobFileException, IOException {
    this(null, null, null, errorHandler, PRIORITY_AVERAGE, null, null, false, true);
    this.jobDir = jobFile.getParentFile();

    // Check for corrupt job.state files (can be corrupt if we crash).
    if (jobFile.length() == 0) {
        throw new InvalidJobFileException(jobFile.getCanonicalPath() + " is corrupt (length is zero)");
    }

    // Open file. Read data and set up class variables accordingly...
    BufferedReader jobReader = new BufferedReader(new FileReader(jobFile), 4096);
    // UID
    this.UID = jobReader.readLine();
    // name
    this.name = jobReader.readLine();
    // status
    this.status = jobReader.readLine();
    if (status.equals(STATUS_ABORTED) == false && status.equals(STATUS_CREATED) == false
            && status.equals(STATUS_DELETED) == false && status.equals(STATUS_FINISHED) == false
            && status.equals(STATUS_FINISHED_ABNORMAL) == false
            && status.equals(STATUS_FINISHED_DATA_LIMIT) == false
            && status.equals(STATUS_FINISHED_DOCUMENT_LIMIT) == false
            && status.equals(STATUS_FINISHED_TIME_LIMIT) == false
            && status.equals(STATUS_MISCONFIGURED) == false && status.equals(STATUS_PAUSED) == false
            && status.equals(STATUS_CHECKPOINTING) == false && status.equals(STATUS_PENDING) == false
            && status.equals(STATUS_RUNNING) == false && status.equals(STATUS_WAITING_FOR_PAUSE) == false
            && status.equals(STATUS_PREPARING) == false) {
        // status is invalid. Must be one of the above
        throw new InvalidJobFileException("Status (line 3) in job file " + "is not valid: '" + status + "'");
    }
    // isReadOnly
    String tmp = jobReader.readLine();
    if (tmp.equals("true")) {
        isReadOnly = true;
    } else if (tmp.equals("false")) {
        isReadOnly = false;
    } else {
        throw new InvalidJobFileException("isReadOnly (line 4) in job" + " file '" + jobFile.getAbsolutePath()
                + "' is not " + "valid: '" + tmp + "'");
    }
    // isRunning
    tmp = jobReader.readLine();
    if (tmp.equals("true")) {
        this.isRunning = true;
    } else if (tmp.equals("false")) {
        this.isRunning = false;
    } else {
        throw new InvalidJobFileException("isRunning (line 5) in job " + "file '" + jobFile.getAbsolutePath()
                + "' is not valid: " + "'" + tmp + "'");
    }
    // priority
    tmp = jobReader.readLine();
    try {
        this.priority = Integer.parseInt(tmp);
    } catch (NumberFormatException e) {
        throw new InvalidJobFileException("priority (line 5) in job " + "file '" + jobFile.getAbsolutePath()
                + "' is not valid: " + "'" + tmp + "'");
    }
    // numberOfJournalEntries
    tmp = jobReader.readLine();
    try {
        this.numberOfJournalEntries = Integer.parseInt(tmp);
    } catch (NumberFormatException e) {
        throw new InvalidJobFileException("numberOfJournalEntries " + "(line 5) in job file '"
                + jobFile.getAbsolutePath() + "' is not valid: " + "'" + tmp + "'");
    }
    // settingsHandler
    tmp = jobReader.readLine();
    try {
        File f = new File(tmp);
        this.settingsHandler = new XMLSettingsHandler((f.isAbsolute()) ? f : new File(jobDir, f.getName()));
        if (this.errorHandler != null) {
            this.settingsHandler.registerValueErrorHandler(errorHandler);
        }
        this.settingsHandler.initialize();
    } catch (InvalidAttributeValueException e1) {
        throw new InvalidJobFileException("Problem reading from settings " + "file (" + tmp
                + ") specified in job file '" + jobFile.getAbsolutePath() + "'\n" + e1.getMessage());
    }
    // Statistics tracker.
    jobReader.readLine();
    // errorMessage
    // TODO: Multilines
    tmp = jobReader.readLine();
    errorMessage = "";
    while (tmp != null) {
        errorMessage += tmp + '\n';
        tmp = jobReader.readLine();
    }
    if (errorMessage.length() == 0) {
        // Empty error message should be null
        errorMessage = null;
    }
    // TODO: Load stattrack if needed.

    // TODO: This should be inside a finally block.
    jobReader.close();
}

From source file:com.cyberway.issue.crawler.Heritrix.java

protected String addCrawlJob(final File order, final String name, final String description, final String seeds)
        throws FatalConfigurationException, IOException {
    CrawlJob addedJob = null;/*  ww w.j a v a  2  s.c  om*/
    if (this.jobHandler == null) {
        throw new NullPointerException("Heritrix jobhandler is null.");
    }
    try {
        if (order.getName().toLowerCase().endsWith(JAR_SUFFIX)) {
            return addCrawlJobBasedonJar(order, name, description, seeds);
        }
        addedJob = this.jobHandler.addJob(createCrawlJob(this.jobHandler, order, name));
    } catch (InvalidAttributeValueException e) {
        FatalConfigurationException fce = new FatalConfigurationException(
                "Converted InvalidAttributeValueException on " + order.getAbsolutePath() + ": "
                        + e.getMessage());
        fce.setStackTrace(e.getStackTrace());
    }
    return addedJob != null ? addedJob.getUID() : null;
}

From source file:org.archive.crawler.admin.CrawlJobHandler.java

/**
 * Creates a new settings handler based on an existing job. Basically all
 * the settings file for the 'based on' will be copied to the specified
 * directory./*from   w ww .  j  av a2s  .co m*/
 *
 * @param orderFile Order file to base new order file on.  Cannot be null.
 * @param name Name for the new settings
 * @param description Description of the new settings.
 * @param seeds The contents of the new settings' seed file.
 * @param newSettingsDir
 * @param errorHandler
 * @param filename Name of new order file.
 * @param seedfile Name of new seeds file.
 *
 * @return The new settings handler.
 * @throws FatalConfigurationException
 *             If there are problems with reading the 'base on'
 *             configuration, with writing the new configuration or it's
 *             seed file.
 */
protected XMLSettingsHandler createSettingsHandler(final File orderFile, final String name,
        final String description, final String seeds, final File newSettingsDir,
        final CrawlJobErrorHandler errorHandler, final String filename, final String seedfile)
        throws FatalConfigurationException {
    XMLSettingsHandler newHandler = null;
    try {
        newHandler = new XMLSettingsHandler(orderFile);
        if (errorHandler != null) {
            newHandler.registerValueErrorHandler(errorHandler);
        }
        newHandler.setErrorReportingLevel(errorHandler.getLevel());
        newHandler.initialize();
    } catch (InvalidAttributeValueException e2) {
        throw new FatalConfigurationException("InvalidAttributeValueException occured while creating"
                + " new settings handler for new job/profile\n" + e2.getMessage());
    }

    // Make sure the directory exists.
    newSettingsDir.mkdirs();

    try {
        // Set the seed file
        ((ComplexType) newHandler.getOrder().getAttribute("scope"))
                .setAttribute(new Attribute("seedsfile", seedfile));
    } catch (AttributeNotFoundException e1) {
        throw new FatalConfigurationException(
                "AttributeNotFoundException occured while setting up" + "new job/profile\n" + e1.getMessage());
    } catch (InvalidAttributeValueException e1) {
        throw new FatalConfigurationException("InvalidAttributeValueException occured while setting"
                + "up new job/profile\n" + e1.getMessage());
    } catch (MBeanException e1) {
        throw new FatalConfigurationException(
                "MBeanException occured while setting up new" + " job/profile\n" + e1.getMessage());
    } catch (ReflectionException e1) {
        throw new FatalConfigurationException(
                "ReflectionException occured while setting up" + " new job/profile\n" + e1.getMessage());
    }

    File newFile = new File(newSettingsDir.getAbsolutePath(), filename);

    try {
        newHandler.copySettings(newFile,
                (String) newHandler.getOrder().getAttribute(CrawlOrder.ATTR_SETTINGS_DIRECTORY));
    } catch (IOException e3) {
        // Print stack trace to help debug issue where cannot create
        // new job from an old that has overrides.
        e3.printStackTrace();
        throw new FatalConfigurationException("IOException occured while writing new settings files"
                + " for new job/profile\n" + e3.getMessage());
    } catch (AttributeNotFoundException e) {
        throw new FatalConfigurationException("AttributeNotFoundException occured while writing new"
                + " settings files for new job/profile\n" + e.getMessage());
    } catch (MBeanException e) {
        throw new FatalConfigurationException("MBeanException occured while writing new settings files"
                + " for new job/profile\n" + e.getMessage());
    } catch (ReflectionException e) {
        throw new FatalConfigurationException("ReflectionException occured while writing new settings"
                + " files for new job/profile\n" + e.getMessage());
    }
    CrawlerSettings orderfile = newHandler.getSettingsObject(null);

    orderfile.setName(name);
    orderfile.setDescription(description);

    if (seeds != null) {
        BufferedWriter writer = null;
        try {
            writer = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(newHandler.getPathRelativeToWorkingDirectory(seedfile)), "UTF-8"));
            try {
                writer.write(seeds);
            } finally {
                writer.close();
            }
        } catch (IOException e) {
            throw new FatalConfigurationException(
                    "IOException occured while writing seed file for new" + " job/profile\n" + e.getMessage());
        }
    }
    return newHandler;
}

From source file:org.webcurator.core.harvester.agent.HarvesterHeritrix.java

/**
 * @return//ww  w  . j  a v a  2  s . co  m
 */
private XMLSettingsHandler getSettingsHandler() {
    XMLSettingsHandler settings = job.getSettingsHandler();
    if (settings == null || settings.getOrder() == null) {
        File profile = new File(job.getDirectory() + File.separator + PROFILE_NAME);
        try {
            settings = new XMLSettingsHandler(profile);
            settings.initialize();
        } catch (InvalidAttributeValueException e) {
            if (log.isErrorEnabled()) {
                log.error("Failed to get settings for job " + name + ": " + e.getMessage(), e);
            }
            throw new HarvesterException("Failed to get settings for job " + name + ": " + e.getMessage(), e);
        }
    }
    return settings;
}