Example usage for java.lang IllegalArgumentException getMessage

List of usage examples for java.lang IllegalArgumentException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:SimpleDateFormatDemo.java

/** Formats and displays today's date. */
public void reformat() {
    SimpleDateFormat formatter = new SimpleDateFormat(currentPattern, availableLocales.getCurrent());
    try {/*w  w w.  j ava 2 s.  c  om*/
        String dateString = formatter.format(today);
        result.setForeground(Color.black);
        result.setText(dateString);
    } catch (IllegalArgumentException iae) {
        result.setForeground(Color.red);
        result.setText("Error: " + iae.getMessage());
    }
}

From source file:com.xpn.xwiki.render.filter.MacroFilter.java

public void handleMatch(StringBuffer buffer, MatchResult result, FilterContext context) {
    String command = result.group(1);

    if (command != null) {
        // {$peng} are variables not macros.
        if (!command.startsWith("$")) {
            MacroParameter mParams = context.getMacroParameter();
            switch (result.groups()) {
            case 3:
                mParams.setContent(result.group(3));
                mParams.setContentStart(result.beginOffset(3));
                mParams.setContentEnd(result.endOffset(3));
            case 2:
                mParams.setParams(result.group(2));
            }/*  w  w w  .  j  a  v a 2 s.  c o m*/
            mParams.setStart(result.beginOffset(0));
            mParams.setEnd(result.endOffset(0));

            // @DANGER: recursive calls may replace macros in included source code
            try {
                if (getMacroRepository().containsKey(command)) {
                    Macro macro = (Macro) getMacroRepository().get(command);
                    // recursively filter macros within macros
                    if (null != mParams.getContent()) {
                        mParams.setContent(filter(mParams.getContent(), context));
                    }

                    Writer writer = new StringBufferWriter(buffer);
                    macro.execute(writer, mParams);
                } else if (command.startsWith("!")) {
                    // @TODO including of other snips
                    RenderEngine engine = context.getRenderContext().getRenderEngine();
                    if (engine instanceof IncludeRenderEngine) {
                        String include = ((IncludeRenderEngine) engine).include(command.substring(1));
                        if (null != include) {
                            // Filter paramFilter = new ParamFilter(mParams);
                            // included = paramFilter.filter(included, null);
                            buffer.append(include);
                        } else {
                            buffer.append(command.substring(1) + " not found.");
                        }
                    }
                    return;
                } else {
                    buffer.append(result.group(0));
                    return;
                }
            } catch (IllegalArgumentException e) {
                buffer.append("<div class=\"error\">" + command + ": " + e.getMessage() + "</div>");
            } catch (Throwable e) {
                log.warn("MacroFilter: unable to format macro: " + result.group(1), e);
                buffer.append("<div class=\"error\">" + command + ": " + e.getMessage() + "</div>");
                return;
            }
        } else {
            buffer.append("<");
            buffer.append(command.substring(1));
            buffer.append(">");
        }
    } else {
        buffer.append(result.group(0));
    }
}

From source file:com.appleframework.monitor.action.ProjectAction.java

/**
 * //  www  .  j  a  va  2  s  .c  o  m
 *
 * @return
 * @throws IOException
 */

@RequestMapping(value = "/projects/add", method = RequestMethod.POST)
public @ResponseBody WebResult add(@RequestBody Project project, HttpServletRequest request)
        throws IOException {
    //Project project =entity.getBody();
    LogsUser user = (LogsUser) request.getSession().getAttribute(CasFilter.SESSION_USER_KEY);
    project.setAdmins(Lists.newArrayList(user.getUsername()));
    WebResult result = new WebResult();
    project.setMetricCollection(project.getMetricCollection());
    try {
        projectCreator.create(project);
    } catch (IllegalArgumentException e) {
        result.setSuccess(false);
        result.setMessage(e.getMessage());
        logger.error("", e);
    }
    return result;
}

From source file:it.unitn.disi.smatch.webapi.server.controllers.AbstractController.java

@ResponseBody
@ExceptionHandler(IllegalArgumentException.class)
protected JSONObject handleIllegalArgumentException(IllegalArgumentException e) throws JSONException {
    logger.warn(e.getMessage(), e);
    return prepareErrorResponse(e.getMessage(), HttpServletResponse.SC_BAD_REQUEST);
}

From source file:org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilterTests.java

public void testRenewInitParamThrows() throws Exception {
    final Cas20ProxyReceivingTicketValidationFilter f = new Cas20ProxyReceivingTicketValidationFilter();
    final MockFilterConfig config = new MockFilterConfig();
    config.addInitParameter("casServerUrlPrefix", "https://cas.example.com");
    config.addInitParameter("renew", "true");
    try {/*from w ww . j  a v  a  2 s.c  o m*/
        f.init(config);
        fail("Should have thrown IllegalArgumentException.");
    } catch (final IllegalArgumentException e) {
        assertTrue(e.getMessage().contains("Renew MUST"));
    }
}

From source file:com.skymobi.monitor.action.ProjectAction.java

/**
 * //from  www.  ja  va 2s.  c  o  m
 *
 * @return
 * @throws IOException
 */

@RequestMapping(value = "/projects/add", method = RequestMethod.POST)
public @ResponseBody WebResult add(@RequestBody Project project) throws IOException {
    //        Project project =entity.getBody();
    String userName = simpleAuthz.getPrincipal();
    project.setAdmins(Lists.newArrayList(userName));
    WebResult result = new WebResult();
    project.setMetricCollection(project.getMetricCollection());
    try {

        projectCreator.create(project);

    } catch (IllegalArgumentException e) {
        result.setSuccess(false);
        result.setMessage(e.getMessage());
        logger.debug("", e);
    }
    return result;
}

From source file:org.inbio.ait.web.ajax.controller.SpeciesController.java

@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String paramLayer = request.getParameter("layers");
    String paramTaxon = request.getParameter("taxons");
    String paramIndi = request.getParameter("indi");
    String limitPolygons = request.getParameter("limit");
    String errorMsj = "Error con los parmetros: " + paramLayer + " " + paramTaxon + " " + paramIndi + " "
            + limitPolygons;/*from   w w w  .j ava  2  s . c  om*/

    try {
        //Arrays that contains the parameters data
        String[] layerArray = paramLayer.split("\\|");
        String[] taxonArray = paramTaxon.split("\\|");
        String[] indiArray = paramIndi.split("\\|");
        String[] limitArray = limitPolygons.split("\\|");

        if (layerArray != null && !layerArray[0].equals("")) { //If there is geographical criteria
            //Total of matches in the limit polygons
            Long totalLimitMatches = queryManager.countByCriteria(limitArray, taxonArray, indiArray,
                    TaxonInfoIndexColums.SPECIES.getName());

            //Total matches by polygon
            List<Node> matchesByPolygon = new ArrayList<Node>();
            for (int i = 0; i < layerArray.length; i++) {
                String[] thePolygon = { layerArray[i] };
                Long countAbs = queryManager.countByCriteria(thePolygon, taxonArray, indiArray,
                        TaxonInfoIndexColums.SPECIES.getName());
                List<String> spList = speciesManager.speciesByCriteria(thePolygon, taxonArray, indiArray);
                Long percentage = 0L;
                if (totalLimitMatches > 0) {
                    percentage = (countAbs * 100) / totalLimitMatches;
                }
                Node aux = new Node(); //Absulute count,percentage
                aux.setValue1(countAbs);
                aux.setValue2(percentage);
                aux.setValue3(spList);
                matchesByPolygon.add(aux);
            }
            return writeReponse(request, response, null, matchesByPolygon);
        } else {
            //Specimens that match with the search criteria
            List<String> species = speciesManager.speciesByCriteria(layerArray, taxonArray, indiArray);
            return writeReponse(request, response, species, null);
        }

    } catch (IllegalArgumentException iae) {
        throw new Exception(errorMsj + " " + iae.getMessage());
    }
}

From source file:org.artifactory.rest.resource.archive.ArchiveResource.java

private Response downloadFolderOrRepo(String repoKey, String path, String archiveTypeString) throws Exception {
    RepoPath pathToDownload = RepoPathFactory.create(repoKey, path);
    ArchiveType archiveType;/*from  w  w w. java 2  s . c o m*/
    try {
        archiveType = ArchiveType.fromValue(archiveTypeString);
    } catch (IllegalArgumentException iae) {
        throw new BadRequestException(iae.getMessage());
    }
    BasicStatusHolder status = new BasicStatusHolder();
    InputStream toWrite = addonsManager.addonByType(RestAddon.class).downloadFolderOrRepo(pathToDownload,
            archiveType, status);
    if (status.isError()) {
        int statusCode = status.getLastError().getStatusCode();
        return Response.status(statusCode)
                .entity(new ErrorResponse(statusCode, status.getLastError().getMessage()))
                .type(MediaType.APPLICATION_JSON).build();
    } else if (toWrite == null) {
        //This will get caught by the GlobalExceptionMapper and return an 'unexpected error' message.
        throw new Exception();
    }
    return Response.status(HttpStatus.SC_OK).type(MediaType.WILDCARD).entity((StreamingOutput) out -> {
        try {
            IOUtils.copy(toWrite, out);
        } finally {
            log.debug("Closing folder download stream");
            IOUtils.closeQuietly(out);
            IOUtils.closeQuietly(toWrite);
        }
    }).build();

}

From source file:gaffer.export.ExporterTest.java

@Test
public void shouldThrowExceptionIfUserNullWhenGettingExportName() {
    // Given//ww w.ja va2  s.co  m
    final ExporterImpl exporter = new ExporterImpl();

    // When / Then
    try {
        exporter.getExportName();
    } catch (final IllegalArgumentException e) {
        assertNotNull(e.getMessage());
    }
}

From source file:org.xdi.oxauth.action.OpenIdConnectDiscoveryAction.java

public void exec() {
    try {//from  w ww  .j  a  v a 2  s  . c om
        ClientExecutor clientExecutor = null;
        if (acceptUntrustedCertificate) {
            HttpClient httpClient = new SslDefaultHttpClient(new TrustAllTrustManager());
            clientExecutor = new ApacheHttpClient4Executor(httpClient);
        }

        OpenIdConnectDiscoveryRequest openIdConnectDiscoveryRequest = new OpenIdConnectDiscoveryRequest(
                resource);
        host = openIdConnectDiscoveryRequest.getHost();
        rel = REL_VALUE;

        OpenIdConnectDiscoveryClient openIdConnectDiscoveryClient = new OpenIdConnectDiscoveryClient(resource);

        OpenIdConnectDiscoveryResponse openIdConnectDiscoveryResponse;
        if (clientExecutor == null) {
            openIdConnectDiscoveryResponse = openIdConnectDiscoveryClient.exec();
        } else {
            openIdConnectDiscoveryResponse = openIdConnectDiscoveryClient.exec(clientExecutor);
        }

        showResults = true;
        requestString1 = openIdConnectDiscoveryClient.getRequestAsString();
        responseString1 = openIdConnectDiscoveryClient.getResponseAsString();

        if (openIdConnectDiscoveryResponse.getStatus() == 200) {
            String openIdConfigurationUrl = openIdConnectDiscoveryResponse.getLinks().get(0).getHref()
                    + "/.well-known/openid-configuration";
            OpenIdConfigurationClient openIdConfigurationClient = new OpenIdConfigurationClient(
                    openIdConfigurationUrl);
            OpenIdConfigurationResponse openIdConfigurationResponse;
            if (clientExecutor == null) {
                openIdConfigurationResponse = openIdConfigurationClient.execOpenIdConfiguration();
            } else {
                openIdConfigurationResponse = openIdConfigurationClient.execOpenIdConfiguration(clientExecutor);
            }

            requestString2 = openIdConfigurationClient.getRequestAsString();
            responseString2 = openIdConfigurationClient.getResponseAsString();

            registrationAction.setRegistrationEndpoint(openIdConfigurationResponse.getRegistrationEndpoint());
            authorizationAction
                    .setAuthorizationEndpoint(openIdConfigurationResponse.getAuthorizationEndpoint());
            authorizationAction.setJwksUri(openIdConfigurationResponse.getJwksUri());
            tokenAction.setTokenEndpoint(openIdConfigurationResponse.getTokenEndpoint());
            userInfoAction.setUserInfoEndpoint(openIdConfigurationResponse.getUserInfoEndpoint());
            checkSessionAction.setCheckSessionEndpoint(openIdConfigurationResponse.getCheckSessionIFrame());
            endSessionAction.setEndSessionEndpoint(openIdConfigurationResponse.getEndSessionEndpoint());
        }
    } catch (IllegalArgumentException e) {
        log.error(e.getMessage(), e);
    } catch (URISyntaxException e) {
        log.error(e.getMessage(), e);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}