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:io.sqp.core.util.TypeUtil.java

/**
 * Checks a value to be not null and tries to map it to a given class.
 * The method first checks the value to be not-null and then if it's assignable to the desired class.
 * If it's not directly assignable (e.g. a int is not assignable to a Double), Jackson's object mapper
 * is used to convert the value, as it is able to map any classes if they are somehow compatible.
 * Therefore this method can also be used to map a {@literal List<Integer>} to an {@literal int[]}.
 * This method also does range checks, e.g. it fails if you try to convert 2^30 to a Short.
 * @param value The value to be checked and mapped.
 * @param clazz The class the value should be mapped to
 * @param what A brief description of the message that is used in a potential error message. E.g. "the identifier"
 * @param <T> The desired object type
 * @return The converted, non-null object.
 * @throws IllegalArgumentException If the value is null or cannot be converted to the desired type
 */// w ww .j  av  a  2  s  . c o  m
public static <T> T checkAndConvert(Object value, Class<T> clazz, String what) {
    if (value == null) {
        throw new IllegalArgumentException(what + " is null.");
    }
    if (clazz.isAssignableFrom(value.getClass())) {
        return clazz.cast(value);
    }
    try {
        return _objectMapper.convertValue(value, clazz);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(
                what + " could not be mapped to type " + clazz.getName() + ": " + e.getMessage(), e);
    }
}

From source file:org.elasticsearch.client.RestClientBuilderTests.java

private static void assertSetPathPrefixThrows(final String pathPrefix) {
    try {/* w w w  .j  a  va 2  s  .  co  m*/
        RestClient.builder(new HttpHost("localhost", 9200)).setPathPrefix(pathPrefix);
        fail("path prefix [" + pathPrefix + "] should have failed");
    } catch (final IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString(pathPrefix));
    }
}

From source file:com.ajah.http.Http.java

private static String get(final String url) throws IOException, HttpException {
    URI uri;/*  w w w .  j  a  v  a  2s  . com*/
    try {
        uri = URI.create(url);
    } catch (final IllegalArgumentException e) {
        log.warning("Illegal URI [" + url + "] - " + e.getMessage());
        throw new BadRequestException(e);
    }
    return get(uri);
}

From source file:bachelorthesis.captchabuilder.builder.BorderParser.java

/**
 * Parses the string arguments for rendering a border, creates a
 * BorderProducer and passes it to the CaptchaBuilder
 * <p/>/*from   w w  w  . j a v a2s  . c  o m*/
 * @param borderOptions the string arguments for building a border
 * @param builder       the CaptchaBuilder Object to be modified
 * <p/>
 * @return a modified CaotchaBuilder object
 * <p/>
 * @throws ParseException
 * @see CaptchaBuilder
 */
public static CaptchaBuilder parse(String[] borderOptions, CaptchaBuilder builder) throws ParseException {
    if (borderOptions.length == 0) {
        //return builder.addBorder();
        builder.addBuildSequence(new BorderProducerBuilder(BorderProducerType.SOLID));
        return builder;
    }

    if (borderOptions.length > 1) {
        throw new ParseException("Border takes a max of 1 arguments");
    }

    for (String borderOption : borderOptions) {
        if (!borderOption.isEmpty()) {
            try {
                String[] optionArgs = borderOption.split(CaptchaConstants.buildSequencelvl3Delim);
                BorderProducerType borderProducerType = BorderProducerType.valueOf(optionArgs[0]);
                String[] borderOptionArgs = Arrays.copyOfRange(optionArgs, 1, optionArgs.length);
                return parseBorderProducer(borderProducerType, borderOptionArgs, builder);
            } catch (IllegalArgumentException e) {
                throw new ParseException(e.getMessage());
            }
        }
    }

    return builder;
}

From source file:com.act.web.includeservletasstring.IncludeServletAsString.java

static public String invokeServletAndReturnAsString(String url, HttpServletRequest servletRequest,
        HttpServletResponse servletResponse) throws IOException, ServletException {

    if (log.isDebugEnabled()) {
        log.debug("Including url \"" + url + "\"...");
    }/*from  w  w w .  jav  a  2  s .  co  m*/

    RequestDispatcher requestDispatcher = servletRequest.getRequestDispatcher(url);

    if (requestDispatcher == null) {
        IllegalArgumentException iae = new IllegalArgumentException(
                "Failed to get RequestDispatcher for url: " + url);
        log.error(iae.getMessage(), iae);
        throw iae;
    }

    BufferedResponse bufferedResponse = new BufferedResponse(servletResponse);

    requestDispatcher.include(servletRequest, bufferedResponse);

    byte[] buffer = bufferedResponse.getBufferAsByteArray();
    if (log.isDebugEnabled()) {
        log.debug("Buffer returned with " + buffer.length + " bytes.");
    }

    String bufferString = new String(buffer, servletResponse.getCharacterEncoding());

    return bufferString;
}

From source file:bachelorthesis.captchabuilder.builder.NoiseParser.java

private static CaptchaBuilder parseNoiseProducer(NoiseProducerType noiseProducerType,
        String[] noiseProducerOptions, CaptchaBuilder builder) throws ParseException {
    NoiseProducerBuilder noiseProducerBuilder = new NoiseProducerBuilder(noiseProducerType);

    if (noiseProducerOptions.length == 0) {
        //return builder.addNoise(noiseProducerBuilder.create());
        builder.addBuildSequence(noiseProducerBuilder);
        return builder;
    }/* w w  w .  j  a  v a  2  s .c o m*/

    if (noiseProducerOptions.length > NoiseProducerOptions.values().length) {
        throw new ParseException(
                "NoiseProducer takes a max of " + NoiseProducerOptions.values().length + " arguments");
    }

    for (String noiseProducerOption : noiseProducerOptions) {
        String[] optionArgs = noiseProducerOption.split(CaptchaConstants.buildSequencelvl4Delim);
        try {
            NoiseProducerOptions noiseProducerOptionType = NoiseProducerOptions.valueOf(optionArgs[0]);
            String[] noiseProducerOptionArgs = Arrays.copyOfRange(optionArgs, 1, optionArgs.length);
            noiseProducerBuilder = parseNoiseProducerOption(noiseProducerOptionType, noiseProducerOptionArgs,
                    noiseProducerBuilder);
        } catch (IllegalArgumentException e) {
            throw new ParseException(e.getMessage());
        }
    }

    //return builder.addNoise(noiseProducerBuilder.create());
    builder.addBuildSequence(noiseProducerBuilder);
    return builder;
}

From source file:bachelorthesis.captchabuilder.builder.NoiseParser.java

/**
 * Parses the string arguments for rendering noise, creates a
 * NoiseProducer and passes it to the CaptchaBuilder
 *
 * @param buildSequenceOptions the string arguments for building noise
 * @param builder              the CaptchaBuilder Object to be modified
 * <p/>//from ww w  .j av a 2s .co  m
 * @return a modified CaptchaBuilder object
 * <p/>
 * @throws org.apache.commons.cli.ParseException
 * @see CaptchaBuilder
 */
public static CaptchaBuilder parse(String[] buildSequenceOptions, CaptchaBuilder builder)
        throws ParseException {
    if (buildSequenceOptions.length == 0) {
        //return builder.addNoise();
        builder.addBuildSequence(new NoiseProducerBuilder(NoiseProducerType.CURVEDLINE));
        return builder;
    }

    if (buildSequenceOptions.length > NoiseOptions.values().length) {
        throw new ParseException("Noise takes a max of " + NoiseOptions.values().length + " arguments");
    }

    for (String noiseOption : buildSequenceOptions) {
        if (!noiseOption.isEmpty()) {
            try {
                String[] optionArgs = noiseOption.split(CaptchaConstants.buildSequencelvl3Delim);
                NoiseProducerType bgProdBuilder = NoiseProducerType.valueOf(optionArgs[0]);
                String[] noiseOptions = Arrays.copyOfRange(optionArgs, 1, optionArgs.length);
                return parseNoiseProducer(bgProdBuilder, noiseOptions, builder);
            } catch (IllegalArgumentException e) {
                throw new ParseException(e.getMessage());
            }
        }
    }

    return builder;
}

From source file:bachelorthesis.captchabuilder.builder.BackgroundParser.java

/**
 * Parses the string arguments for rendering a background, creates a
 * BackgroundProducer and passes it to the CaptchaBuilder
 *
 * @param buildSequenceOptions the string arguments for building a
 *                             background
 * @param builder              the CaptchaBuilder Object to be modified
 * <p/>//from ww  w.  ja  va 2  s .  com
 * @return a modified CaptchaBuilder object
 * <p/>
 * @throws org.apache.commons.cli.ParseException
 * @see CaptchaBuilder
 */
public static CaptchaBuilder parse(String[] buildSequenceOptions, CaptchaBuilder builder)
        throws ParseException {
    if (buildSequenceOptions.length == 0) {
        //return builder.addBackground();
        builder.addBuildSequence(new BackgroundProducerBuilder(BackgroundProducerType.TRANSPARENT));
        return builder;
    }

    if (buildSequenceOptions.length > 1) {
        throw new ParseException("Background takes a max of 1 arguments");
    }

    for (String backgroundOption : buildSequenceOptions) {
        if (!backgroundOption.isEmpty()) {
            try {
                String[] optionArgs = backgroundOption.split(CaptchaConstants.buildSequencelvl3Delim);
                BackgroundProducerType backgroundProducerType = BackgroundProducerType.valueOf(optionArgs[0]);
                String[] backgroundOptionArgs = Arrays.copyOfRange(optionArgs, 1, optionArgs.length);
                return parseBackgroundProducer(backgroundProducerType, backgroundOptionArgs, builder);
            } catch (IllegalArgumentException e) {
                throw new ParseException(e.getMessage());
            }
        }
    }

    return builder;
}

From source file:bachelorthesis.captchabuilder.builder.BorderParser.java

private static CaptchaBuilder parseBorderProducer(BorderProducerType borderProducerType,
        String[] borderProducerOptions, CaptchaBuilder builder) throws ParseException {
    BorderProducerBuilder borderProducerBuilder = new BorderProducerBuilder(borderProducerType);

    if (borderProducerOptions.length == 0) {
        //return builder.addBorder(borderProducerBuilder.create());
        builder.addBuildSequence(borderProducerBuilder);
        return builder;
    }/*from   w  w  w  .  j  ava2s  . c om*/

    if (borderProducerOptions.length > BorderProducerOptions.values().length) {
        throw new ParseException(
                "BorderProducer takes a max of " + BorderProducerOptions.values().length + " arguments");
    }

    for (String boderproducerOption : borderProducerOptions) {
        if (!boderproducerOption.isEmpty()) {
            try {
                String[] optionArgs = boderproducerOption.split(CaptchaConstants.buildSequencelvl4Delim);
                BorderProducerOptions borderProducerOptionType = BorderProducerOptions.valueOf(optionArgs[0]);
                String[] borderProducerOptionArgs = Arrays.copyOfRange(optionArgs, 1, optionArgs.length);
                borderProducerBuilder = parseBorderProducerOption(borderProducerOptionType,
                        borderProducerOptionArgs, borderProducerBuilder);
            } catch (IllegalArgumentException e) {
                throw new ParseException(e.getMessage());
            }
        }

    }

    //return builder.addBorder(borderProducerBuilder.create());
    builder.addBuildSequence(borderProducerBuilder);
    return builder;
}

From source file:bachelorthesis.captchabuilder.builder.BackgroundParser.java

private static CaptchaBuilder parseBackgroundProducer(BackgroundProducerType backgroundProducerType,
        String[] backgroundProducerOptions, CaptchaBuilder builder) throws ParseException {
    BackgroundProducerBuilder backgroundProducerBuilder = new BackgroundProducerBuilder(backgroundProducerType);

    if (backgroundProducerOptions.length == 0) {
        //return builder.addBackground(backgroundProducerBuilder.create());
        builder.addBuildSequence(backgroundProducerBuilder);
        return builder;
    }/*from   ww w  . j  a v  a  2s  .c  om*/

    if (backgroundProducerOptions.length > BackgroundProducerOptions.values().length) {
        throw new ParseException("BackgroundProducer takes a max of "
                + BackgroundProducerOptions.values().length + " arguments");
    }

    for (String backgroundProducerOption : backgroundProducerOptions) {
        if (!backgroundProducerOption.isEmpty()) {
            try {
                String[] optionArgs = backgroundProducerOption.split(CaptchaConstants.buildSequencelvl4Delim);
                BackgroundProducerOptions backgroundProducerOptionType = BackgroundProducerOptions
                        .valueOf(optionArgs[0]);
                String[] backgroundProducerOptionArgs = Arrays.copyOfRange(optionArgs, 1, optionArgs.length);
                backgroundProducerBuilder = parseBackgroundProducerOption(backgroundProducerOptionType,
                        backgroundProducerOptionArgs, backgroundProducerBuilder);
            } catch (IllegalArgumentException e) {
                throw new ParseException(e.getMessage());
            }
        }
    }

    //return builder.addBackground(backgroundProducerBuilder.create());
    builder.addBuildSequence(backgroundProducerBuilder);
    return builder;
}