Example usage for javax.servlet ServletException getMessage

List of usage examples for javax.servlet ServletException getMessage

Introduction

In this page you can find the example usage for javax.servlet ServletException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.biouno.unochoice.AbstractUnoChoiceParameter.java

@Override
public ParameterValue createValue(StaplerRequest request, JSONObject json) {
    if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.entering(AbstractUnoChoiceParameter.class.getName(), "createValue",
                new Object[] { request, json });
    }/*  w  w w .j a  v a  2s  .c  o  m*/
    if (json.containsKey("file")) {
        // copied from FileParameterDefinition
        FileItem src;
        try {
            src = request.getFileItem(json.getString("file"));
        } catch (ServletException e) {
            LOGGER.log(Level.SEVERE, "Fatal error while reading uploaded file: " + e.getMessage(), e);
            return null;
        } catch (IOException e) {
            LOGGER.log(Level.SEVERE, "IO error while reading uploaded file: " + e.getMessage(), e);
            return null;
        }
        if (src == null) {
            // the requested file parameter wasn't uploaded
            return null;
        }
        FileParameterValue p = new FileParameterValue(getName(), src);
        p.setDescription(getDescription());
        return p;
    } else {
        final JSONObject parameterJsonModel = new JSONObject(false);
        final Object value = json.get("value");
        final Object name = json.get("name");
        final String valueAsText;

        if (JSONUtils.isArray(value)) {
            valueAsText = ((JSONArray) value).join(",", true);
        } else {
            valueAsText = (value == null) ? "" : String.valueOf(value);
        }

        parameterJsonModel.put("name", name);
        parameterJsonModel.put("value", valueAsText);

        StringParameterValue parameterValue = request.bindJSON(StringParameterValue.class, parameterJsonModel);
        parameterValue.setDescription(getDescription());
        return parameterValue;
    }
}

From source file:info.magnolia.rendering.model.ModelExecutionFilterTest.java

@Test
public void testThrowsServletExceptionWhenParameterPointsToNonExistingContent() throws Exception {

    // GIVEN// w  w  w .  ja  va  2 s . com
    FilterChain chain = mock(FilterChain.class);
    ModelExecutionFilter filter = Components.getComponent(ModelExecutionFilter.class);
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();

    setupRequestAndAggregationState(request, response, "10002");

    EarlyExecutionAware renderingModel = mock(EarlyExecutionAware.class);
    setupRendererThatReturnsMockRenderingModel(renderingModel);

    // THEN
    try {
        filter.doFilter(request, response, chain);
        fail();
    } catch (ServletException e) {
        assertEquals("Can't read content for early execution, node: 10002", e.getMessage());
    }
}

From source file:org.echocat.jemoni.jmx.support.ServletHealthUnitTest.java

@Test
public void testInitRegistryByFilterConfig() throws Exception {
    try {// www .  jav a  2  s .  co  m
        new ServletHealth().init(filterConfig(null, REGISTRY_REF_INIT_ATTRIBUTE, "myRegistry"));
        fail("Expected exception missing");
    } catch (ServletException expected) {
        assertThat(expected.getMessage(), is("Could not find a spring context."));
    }
    try {
        new ServletHealth().init(filterConfig(applicationContext(), REGISTRY_REF_INIT_ATTRIBUTE, "myRegistry"));
        fail("Expected exception missing");
    } catch (ServletException expected) {
        assertThat(expected.getMessage(), contains("Could not find bean"));
    }
    final ServletHealth health = new ServletHealth();
    final JmxRegistry myRegistry = new JmxRegistry();
    assertThat(health.getRegistry(), isSameAs(getLocalInstance()));
    health.init(filterConfig(applicationContext("myRegistry", myRegistry), REGISTRY_REF_INIT_ATTRIBUTE,
            "myRegistry"));
    health.close();
    assertThat(health.getRegistry(), isSameAs(myRegistry));
}

From source file:org.echocat.jemoni.jmx.support.ServletHealthUnitTest.java

@Test
public void testInitInterceptorByFilterConfig() throws Exception {
    try {/*from w  w  w.j a v  a 2 s . c  om*/
        new ServletHealth().init(filterConfig(null, INTERCEPTOR_REF_INIT_ATTRIBUTE, "myInterceptor"));
        fail("Expected exception missing");
    } catch (ServletException expected) {
        assertThat(expected.getMessage(), is("Could not find a spring context."));
    }
    try {
        new ServletHealth()
                .init(filterConfig(applicationContext(), INTERCEPTOR_REF_INIT_ATTRIBUTE, "myInterceptor"));
        fail("Expected exception missing");
    } catch (ServletException expected) {
        assertThat(expected.getMessage(), contains("Could not find bean"));
    }
    final ServletHealth health = new ServletHealth();
    final ServletHealthInterceptor myInterceptor = mock(ServletHealthInterceptor.class);
    assertThat(health.getInterceptor(), is(null));
    health.init(filterConfig(applicationContext("myInterceptor", myInterceptor), INTERCEPTOR_REF_INIT_ATTRIBUTE,
            "myInterceptor"));
    health.close();
    assertThat(health.getInterceptor(), isSameAs(myInterceptor));
    health.init(filterConfig(null, INTERCEPTOR_INIT_ATTRIBUTE, MyInterceptor.class.getName()));
    health.close();
    assertThat(health.getInterceptor(), isInstanceOf(MyInterceptor.class));
}

From source file:eu.eidas.node.service.IdPResponseServlet.java

/**
 * Executes the method {@link eu.eidas.node.auth.service.AUSERVICE#processIdpResponse} (of the ProxyService) and
 * then sets the internal variables used by the redirection JSP or the consent-value jsp, accordingly to {@link
 * EidasParameterKeys#NO_CONSENT_VALUE} or {@link EidasParameterKeys#CONSENT_VALUE} respectively.
 *
 * @param request//from ww w  .  j  a v a2  s  . c  om
 * @param response
 * @return {@link EidasParameterKeys#CONSENT_VALUE} if the consent-value form is to be displayed, {@link
 * EidasParameterKeys#NO_CONSENT_VALUE} otherwise.
 * @see EidasParameterKeys#NO_CONSENT_VALUE
 * @see EidasParameterKeys#CONSENT_VALUE
 */

private void execute(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    try {

        RequestDispatcher dispatcher = getServletContext()
                .getRequestDispatcher(handleExecute(request, response));
        dispatcher.forward(request, response);
        HttpSession session = request.getSession(false);
        if (null != session
                && session.getAttribute(EidasParameterKeys.EIDAS_CONNECTOR_SESSION.toString()) == null) {
            session.invalidate();
        }
    } catch (ServletException e) {
        getLogger().info("ERROR : ServletException {}", e.getMessage());
        getLogger().debug("ERROR : ServletException {}", e);
        throw e;
    } catch (IOException e) {
        getLogger().info("IOException {}", e.getMessage());
        getLogger().debug("IOException {}", e);
        throw e;
    }

}

From source file:io.hops.hopsworks.api.user.AuthService.java

private void login(Users user, String email, String password, HttpServletRequest req) throws UserException {
    if (user == null) {
        throw new IllegalArgumentException("User not set.");
    }//from   w  w  w.  j a v  a2 s .co m
    if (user.getBbcGroupCollection() == null || user.getBbcGroupCollection().isEmpty()) {
        throw new UserException(RESTCodes.UserErrorCode.NO_ROLE_FOUND, Level.FINE);
    }
    if (statusValidator.checkStatus(user.getStatus())) {
        try {
            req.login(email, password);
            authController.registerLogin(user, req);
        } catch (ServletException e) {
            LOGGER.log(Level.WARNING, e.getMessage());
            authController.registerAuthenticationFailure(user, req);
            throw new UserException(RESTCodes.UserErrorCode.AUTHENTICATION_FAILURE, Level.SEVERE, null,
                    e.getMessage(), e);
        }
    } else { // if user == null
        throw new UserException(RESTCodes.UserErrorCode.AUTHENTICATION_FAILURE, Level.INFO);
    }
}

From source file:eu.eidas.node.APSelectorServlet.java

/**
 * Prepares the citizen to be redirected to the AP.
 * @param request/*w  w w  .j  a  va  2 s  . c om*/
 * @param response
 * @throws ServletException
 * @throws IOException
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    try {
        LOG.debug("**** EXECUTE : APSelectorServlet ****");

        APSelectorBean controllerService = (APSelectorBean) getApplicationContext()
                .getBean("springManagedAPSelector");

        validateSession(controllerService);

        // Prevent cookies from being accessed through client-side script.
        setHTTPOnlyHeader(request, response);

        final Map<String, Object> parameters = getHttpRequestParameters(request);

        IPersonalAttributeList attrList = (PersonalAttributeList) request
                .getAttribute(EIDASParameters.ATTRIBUTE_LIST.toString());

        String strAttrList = (String) parameters.get(SpecificParameterNames.STR_ATTR_LIST.toString());
        if (strAttrList == null) {
            strAttrList = (String) request.getAttribute(SpecificParameterNames.STR_ATTR_LIST.toString());
        }

        if (strAttrList != null) {
            LOG.debug("Setting AttributeList...");
            attrList = new PersonalAttributeList();
            attrList.populate(strAttrList);
            validateAttrList(controllerService, attrList);
        }

        if (controllerService.getNumberOfAps() > 0 && !checkAttributes(attrList)) {
            LOG.debug("Build parameter list");

            final String username = (String) controllerService.getSession()
                    .get(EIDASParameters.USERNAME.toString());
            EIDASUtil.validateParameter(APSelectorServlet.class.getCanonicalName(),
                    EIDASParameters.USERNAME.toString(), username);
            parameters.put(EIDASParameters.USERNAME.toString(), username);
            request.setAttribute(EIDASParameters.USERNAME.toString(), username);
            LOG.debug("Build username=" + username);

            if (controllerService.isExternalAP()) {
                LOG.debug("External AP configured");
                request.setAttribute(SpecificParameterNames.CALLBACK_URL.toString(),
                        encodeURL(controllerService.getCallbackURL(), request, response));
                final boolean retVal = controllerService.getSpecificEidasNode().prepareAPRedirect(attrList,
                        parameters, getHttpRequestAttributesHeaders(request), controllerService.getSession());
                if (retVal) {
                    request.setAttribute(EIDASParameters.AP_URL.toString(),
                            controllerService.getSession().get(EIDASParameters.AP_URL.toString()));
                    request.setAttribute(SpecificParameterNames.STR_ATTR_LIST.toString(), attrList.toString());
                    LOG.debug("[execute] external-ap");

                    RequestDispatcher dispatcher = getServletContext()
                            .getRequestDispatcher(response.encodeURL(SpecificViewNames.AP_REDIRECT.toString()));
                    dispatcher.forward(request, response);
                    return;
                }
            } else {
                controllerService.getSpecificEidasNode().getAttributesFromAttributeProviders(attrList,
                        parameters, getHttpRequestAttributesHeaders(request));
            }
        }

        final EIDASAuthnRequest authReq = (EIDASAuthnRequest) controllerService.getSession()
                .get(EIDASParameters.AUTH_REQUEST.toString());
        if (SAMLCore.EIDAS10_SAML_PREFIX.getValue().equalsIgnoreCase(authReq.getMessageFormatName())) {
            for (PersonalAttribute pa : attrList) {
                if (!pa.getValue().isEmpty() && !StringUtils.isEmpty(pa.getValue().get(0))
                        && StringUtils.isEmpty(pa.getStatus())) {
                    pa.setStatus(EIDASStatusCode.STATUS_AVAILABLE.toString());
                }
            }
        }

        if (authReq.getPersonalAttributeList().containsKey(controllerService.getAttribute())
                && controllerService.isSigModuleExists()) {
            final PersonalAttribute attr = authReq.getPersonalAttributeList()
                    .get(controllerService.getAttribute());
            if (!attr.isEmptyValue()) {
                LOG.debug("[execute] external-sig-module");
                final String signedDocValue = attr.getValue().get(0);
                request.setAttribute(SpecificParameterNames.DATA.toString(), signedDocValue);
                attrList.put(attr.getName(), attr);
                request.setAttribute(EIDASParameters.ATTRIBUTE_LIST.toString(), attrList);
                String dataURL = controllerService.getDataURL() + ";jsessionid=" + request.getSession().getId();
                request.setAttribute(SpecificParameterNames.DATA_URL.toString(), dataURL);
                controllerService.getSession().put(EIDASParameters.ATTRIBUTE_LIST.toString(), attrList);
                request.setAttribute(SpecificParameterNames.SIG_MODULE_CREATOR_URL.toString(),
                        controllerService.getSigCreatorModuleURL());

                RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(
                        response.encodeURL(SpecificViewNames.EXTERNAL_SIG_MODULE_REDIRECT.toString()));
                dispatcher.forward(request, response);
                return;

            } else {
                LOG.info("ERROR : [execute] No " + controllerService.getAttribute() + " value found!");
            }
        }

        request.setAttribute(EIDASParameters.ATTRIBUTE_LIST.toString(), attrList);
        request.setAttribute(SpecificParameterNames.STR_ATTR_LIST.toString(), strAttrList);

        LOG.trace("[execute] internal-ap");
        RequestDispatcher dispatcher = getServletContext()
                .getRequestDispatcher(response.encodeURL(SpecificViewNames.AP_RESPONSE.toString()));
        dispatcher.forward(request, response);

    } catch (ServletException e) {
        LOG.info("ERROR : ", e.getMessage());
        LOG.debug("ERROR : ", e);
        throw e;
    } catch (IOException e) {
        LOG.info("ERROR : ", e.getMessage());
        LOG.debug("ERROR : ", e);
        throw e;
    } catch (AbstractEIDASException e) {
        LOG.info("ERROR : ", e.getErrorMessage());
        LOG.debug("ERROR : ", e);
        throw e;
    }

}

From source file:org.pentaho.pat.plugin.PatLifeCycleListener.java

public void loaded() throws PluginLifecycleException {
    ClassLoader origContextClassloader = Thread.currentThread().getContextClassLoader();
    IServiceManager serviceManager = (IServiceManager) PentahoSystem.get(IServiceManager.class,
            PentahoSessionHolder.getSession());
    try {/*from  w  ww .j a  v a 2s .  c o m*/
        sessionBean = (SessionServlet) serviceManager.getServiceBean("gwt", "session.rpc"); //$NON-NLS-1$
        queryBean = (QueryServlet) serviceManager.getServiceBean("gwt", "query.rpc"); //$NON-NLS-1$
        discoveryBean = (DiscoveryServlet) serviceManager.getServiceBean("gwt", "discovery.rpc"); //$NON-NLS-1$
        platformBean = (PlatformServlet) serviceManager.getServiceBean("gwt", "platform.rpc"); //$NON-NLS-1$

        final IPluginManager pluginManager = (IPluginManager) PentahoSystem.get(IPluginManager.class,
                PentahoSessionHolder.getSession());
        final PluginClassLoader pluginClassloader = (PluginClassLoader) pluginManager
                .getClassLoader(PAT_PLUGIN_NAME);
        final String hibernateConfigurationFile = PentahoSystem
                .getSystemSetting("hibernate/hibernate-settings.xml", "settings/config-file", null); //$NON-NLS-1$
        final String pentahoHibConfigPath = PentahoSystem.getApplicationContext()
                .getSolutionPath(hibernateConfigurationFile);

        if (pluginClassloader == null)
            throw new ServiceException(Messages.getString("LifeCycleListener.NoPluginClassloader")); //$NON-NLS-1$

        Thread.currentThread().setContextClassLoader(pluginClassloader);
        final URL contextUrl = pluginClassloader.getResource(PAT_APP_CONTEXT);
        final URL patHibConfigUrl = pluginClassloader.getResource(PAT_HIBERNATE_CONFIG);
        final URL patPluginPropertiesUrl = pluginClassloader.getResource(PAT_PLUGIN_PROPERTIES);
        if (patHibConfigUrl == null)
            throw new ServiceException("File not found: PAT Hibernate Config : " + PAT_HIBERNATE_CONFIG);
        else
            LOG.debug(PAT_PLUGIN_NAME + ": PAT Hibernate Config:" + patHibConfigUrl.toString());

        if (patPluginPropertiesUrl == null)
            throw new ServiceException("File not found: PAT Plugin properties : " + PAT_PLUGIN_PROPERTIES);
        else
            LOG.debug(PAT_PLUGIN_NAME + ": PAT Plugin Properties:" + patPluginPropertiesUrl.toString());

        if (contextUrl != null) {
            String appContextUrl = contextUrl.toString();
            final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
                    new String[] { appContextUrl }, false);
            applicationContext.setClassLoader(pluginClassloader);
            applicationContext.setConfigLocation(appContextUrl);
            applicationContext.setAllowBeanDefinitionOverriding(true);

            final Configuration pentahoHibConfig = new Configuration();
            pentahoHibConfig.configure(new File(pentahoHibConfigPath));

            final AnnotationConfiguration patHibConfig = new AnnotationConfiguration();
            patHibConfig.configure(patHibConfigUrl);

            Properties properties = new Properties();
            properties.load(pluginClassloader.getResourceAsStream(PAT_PLUGIN_PROPERTIES));
            String hibernateDialectCfg = (String) properties.get("pat.plugin.datasource.hibernate.dialect");
            String hibernateDialect = null;
            if (StringUtils.isNotBlank(hibernateDialectCfg)) {
                if (hibernateDialectCfg.equals("auto")) {
                    hibernateDialect = pentahoHibConfig.getProperty("dialect");
                } else {
                    hibernateDialect = hibernateDialectCfg;
                }
            }

            if (StringUtils.isNotBlank(hibernateDialect)) {
                patHibConfig.setProperty("hibernate.dialect", hibernateDialect);
                LOG.info(PAT_PLUGIN_NAME + " : using hibernate dialect: " + hibernateDialect);
            }

            String dataSourceType = (String) properties.get("pat.plugin.datasource.type");
            String datasourceResource = null;
            if (StringUtils.isNotEmpty(dataSourceType) && dataSourceType.equals("jdbc")) {
                datasourceResource = PAT_DATASOURCE_JDBC;
                LOG.info(PAT_PLUGIN_NAME + " : using JDBC connection");

            }
            if (StringUtils.isNotEmpty(dataSourceType) && dataSourceType.equals("jndi")) {
                datasourceResource = PAT_DATASOURCE_JNDI;
                LOG.info(PAT_PLUGIN_NAME + " : using JNDI : " + (String) properties.get("jndi.name"));
            }

            XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource(datasourceResource));
            PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
            cfg.setLocation(new ClassPathResource(PAT_PLUGIN_PROPERTIES));
            cfg.postProcessBeanFactory(factory);

            XmlBeanFactory bfSession = new XmlBeanFactory(new ClassPathResource(PAT_SESSIONFACTORY), factory);

            PropertyPlaceholderConfigurer cfgSession = new PropertyPlaceholderConfigurer();
            cfgSession.setProperties(patHibConfig.getProperties());
            cfgSession.postProcessBeanFactory(bfSession);

            ClassPathXmlApplicationContext tmpCtxt = new ClassPathXmlApplicationContext();
            tmpCtxt.refresh();
            DefaultListableBeanFactory tmpBf = (DefaultListableBeanFactory) tmpCtxt.getBeanFactory();

            tmpBf.setParentBeanFactory(bfSession);

            applicationContext.setClassLoader(pluginClassloader);
            applicationContext.setParent(tmpCtxt);
            applicationContext.refresh();

            sessionBean.setStandalone(true);
            SessionServlet.setApplicationContext(applicationContext);
            sessionBean.init();

            queryBean.setStandalone(true);
            QueryServlet.setApplicationContext(applicationContext);
            queryBean.init();

            discoveryBean.setStandalone(true);
            DiscoveryServlet.setApplicationContext(applicationContext);
            discoveryBean.init();

            platformBean.setStandalone(true);
            PlatformServlet.setApplicationContext(applicationContext);
            platformBean.init();

            injectPentahoXmlaUrl();
        } else {
            throw new Exception(Messages.getString("LifeCycleListener.AppContextNotFound"));
        }

    } catch (ServiceException e1) {
        LOG.error(e1.getMessage(), e1);
    } catch (ServletException e) {
        LOG.error(e.getMessage(), e);
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    } finally {
        // reset the classloader of the current thread
        if (origContextClassloader != null) {
            Thread.currentThread().setContextClassLoader(origContextClassloader);
        }
    }
}

From source file:org.apache.tiles.servlet.context.ServletTilesRequestContext.java

/**
 * Forwards to a path.//from w ww .ja  va  2 s .co  m
 *
 * @param path The path to forward to.
 * @throws IOException If something goes wrong during the operation.
 */
private void forward(String path) throws IOException {
    RequestDispatcher rd = request.getRequestDispatcher(path);
    try {
        rd.forward(request, response);
    } catch (ServletException ex) {
        LOG.error("Servlet Exception while including path", ex);
        throw new IOException("Error including path '" + path + "'. " + ex.getMessage());
    }
}

From source file:org.apache.tiles.servlet.context.ServletTilesRequestContext.java

/** {@inheritDoc} */
public void include(String path) throws IOException {
    RequestDispatcher rd = request.getRequestDispatcher(path);
    try {// w w  w.j  a v  a  2 s. c  om
        rd.include(request, response);
    } catch (ServletException ex) {
        LOG.error("Servlet Exception while including path", ex);
        throw new IOException("Error including path '" + path + "'. " + ex.getMessage());
    }
}