Example usage for java.lang IllegalStateException getLocalizedMessage

List of usage examples for java.lang IllegalStateException getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:org.deegree.services.controller.OGCFrontController.java

/**
 * Sends an exception report to the client.
 * <p>/* w  ww  . j ava  2s .  co m*/
 * NOTE: Usually, exception reports are generated by the specific service controller. This method is only used when
 * the request is so broken that it cannot be dispatched.
 * </p>
 * 
 * @param ows
 *            if not null, it will be used to determine the responsible controller for exception serializing
 * @param e
 *            exception to be serialized
 * @param res
 *            response object
 * @throws ServletException
 */
private void sendException(OWS ows, OWSException e, HttpResponseBuffer res, Version requestVersion)
        throws ServletException {
    String userAgent = null;
    if (OGCFrontController.getContext() != null) {
        userAgent = OGCFrontController.getContext().getUserAgent();
    }

    if (ows == null) {
        Collection<List<OWS>> values = serviceConfiguration.getAll().values();
        if (values.size() > 0 && !values.iterator().next().isEmpty()) {
            ows = values.iterator().next().get(0);
        }
    }
    if (ows != null) {
        // use exception serializer / mime type from first registered controller (fair chance that this will be
        // correct)
        XMLExceptionSerializer serializer = ows.getExceptionSerializer(requestVersion);
        ((AbstractOWS) ows).sendException(null, serializer, e, res);
    } else {
        // use the most common serializer (OWS 1.1.0)
        XMLExceptionSerializer serializer = null;
        if (requestVersion == null) {
            serializer = new OWS110ExceptionReportSerializer(parseVersion("1.1.0"));
        } else {
            serializer = new OWS110ExceptionReportSerializer(requestVersion);
        }

        if (!res.isCommitted()) {
            try {
                res.reset();
            } catch (IllegalStateException e2) {
                // rb: the illegal state exception occurred.
                throw new ServletException(e2);
            }
            try {
                serializer.serializeException(res, e);
            } catch (Exception e2) {
                LOG.error("An error occurred while trying to send an exception: " + e2.getLocalizedMessage(),
                        e);
                throw new ServletException(e2);
            }
            res.setExceptionSent();
        }
    }

    if (userAgent != null && userAgent.toLowerCase().contains("mozilla")) {
        res.setContentType("application/xml");
    }
}

From source file:org.pentaho.platform.engine.core.system.PentahoSystem.java

public static boolean init(final IApplicationContext pApplicationContext, final Map listenerMap) {
    if (debug) {/*from  w ww  .j a  va  2 s . c o m*/
        Logger.debug(PentahoSystem.class, "PentahoSystem init called"); //$NON-NLS-1$
    }

    if (PentahoSystem.initializedStatus == PentahoSystem.SYSTEM_INITIALIZED_OK) {
        // TODO: Removing the catching of this IllegalStateException. It's being trapped here now as too many existing
        // tests call init more than once without an intervening shutdown().
        try {
            throw new IllegalStateException("'Init' method was run twice without 'shutdown'");
        } catch (IllegalStateException e) {
            Logger.error(PentahoSystem.class,
                    "PentahoSystem was already initialized when init() called again without a preceding shutdown(). "
                            + "This is likely in error",
                    e);
        }
    }

    PentahoSystem.initializedStatus = PentahoSystem.SYSTEM_INITIALIZED_OK;

    // PDI-3438 Scheduled job fails to open a transformation
    // Kettle jobs spawn threads which may require authentication to load transformations from
    // the kettle repository, by using the INHERITABLETHREADLOCAL strategy, spawned threads will
    // enjoy the same SecurityContext as their parent!
    SecurityContextHolder.setStrategyName(securityContextHolderStrategy);

    PentahoSystem.globalAttributes = Collections.synchronizedMap(new HashMap());
    PentahoSystem.globalParameters = new SimpleParameterProvider(PentahoSystem.globalAttributes);

    PentahoSystem.applicationContext = pApplicationContext;

    if (debug) {
        Logger.debug(PentahoSystem.class, "Setting property path"); //$NON-NLS-1$
    }
    System.setProperty("pentaho.solutionpath", "solution:"); //$NON-NLS-1$
    if (LocaleHelper.getLocale() == null) {
        LocaleHelper.setLocale(Locale.getDefault());
    }

    if (PentahoSystem.systemSettingsService != null) {
        if (debug) {
            Logger.debug(PentahoSystem.class, "Reading ACL list from pentaho.xml"); //$NON-NLS-1$
        }
        // Set Up ACL File Extensions by reading pentaho.xml for acl-files
        //
        // Read the files that are permitted to have ACLs on them from
        // the pentaho.xml.
        //
        String aclFiles = PentahoSystem.getSystemSetting("acl-files", "xaction,url"); //$NON-NLS-1$ //$NON-NLS-2$
        StringTokenizer st = new StringTokenizer(aclFiles, ","); //$NON-NLS-1$
        String extn;
        while (st.hasMoreElements()) {
            extn = st.nextToken();
            if (!extn.startsWith(".")) { //$NON-NLS-1$
                extn = "." + extn; //$NON-NLS-1$
            }
            PentahoSystem.ACLFileExtensionList.add(extn);
        }
    }

    if (debug) {
        Logger.debug(PentahoSystem.class, "Initialize XML Factories"); //$NON-NLS-1$
    }
    PentahoSystem.initXMLFactories();

    if (debug) {
        Logger.debug(PentahoSystem.class, "Set Logging Level from pentaho.xml setting"); //$NON-NLS-1$
    }
    PentahoSystem.loggingLevel = ILogger.ERROR;
    if (PentahoSystem.systemSettingsService != null) {
        PentahoSystem.loggingLevel = Logger
                .getLogLevel(PentahoSystem.systemSettingsService.getSystemSetting("log-level", "ERROR")); //$NON-NLS-1$//$NON-NLS-2$
    }

    Logger.setLogLevel(PentahoSystem.loggingLevel);

    // to guarantee hostnames in SSL mode are not being spoofed
    if (debug) {
        Logger.debug(PentahoSystem.class, "Register host name verifier"); //$NON-NLS-1$
    }
    PentahoSystem.registerHostnameVerifier();

    assert null != aggObjectFactory : "aggObjectFactory must be non-null"; //$NON-NLS-1$
    try {
        if (debug) {
            Logger.debug(PentahoSystem.class, "Validating object factory"); //$NON-NLS-1$
        }
        PentahoSystem.validateObjectFactory();
    } catch (PentahoSystemException e1) {
        throw new RuntimeException(e1); // this is fatal
    }

    // store a list of the system listeners
    try {
        if (debug) {
            Logger.debug(PentahoSystem.class, "Start System Listeners"); //$NON-NLS-1$
        }
        PentahoSystem.notifySystemListenersOfStartup();
    } catch (PentahoSystemException e) {
        String msg = e.getLocalizedMessage();
        Logger.error(PentahoSystem.class.getName(), msg, e);
        PentahoSystem.initializedStatus |= PentahoSystem.SYSTEM_LISTENERS_FAILED;
        PentahoSystem.addInitializationFailureMessage(PentahoSystem.SYSTEM_LISTENERS_FAILED, msg);
        return false;
    }

    // once everything else is initialized, start global actions
    if (debug) {
        Logger.debug(PentahoSystem.class, "Global startup"); //$NON-NLS-1$
    }
    PentahoSystem.globalStartup();

    if (debug) {
        Logger.debug(PentahoSystem.class, "PentahoSystem Init Complete"); //$NON-NLS-1$
    }
    return true;
}