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:mod.org.dcm4che2.tool.DcmQR.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    CommandLine cl = parse(args);/*www. ja  v a  2 s. co m*/
    DcmQR dcmqr = new DcmQR(cl.hasOption("device") ? cl.getOptionValue("device") : "DCMQR");
    final List<String> argList = cl.getArgList();
    String remoteAE = argList.get(0);
    String[] calledAETAddress = split(remoteAE, '@');
    dcmqr.setCalledAET(calledAETAddress[0], cl.hasOption("reuseassoc"));
    if (calledAETAddress[1] == null) {
        dcmqr.setRemoteHost("127.0.0.1");
        dcmqr.setRemotePort(104);
    } else {
        String[] hostPort = split(calledAETAddress[1], ':');
        dcmqr.setRemoteHost(hostPort[0]);
        dcmqr.setRemotePort(toPort(hostPort[1]));
    }
    if (cl.hasOption("L")) {
        String localAE = cl.getOptionValue("L");
        String[] localPort = split(localAE, ':');
        if (localPort[1] != null) {
            dcmqr.setLocalPort(toPort(localPort[1]));
        }
        String[] callingAETHost = split(localPort[0], '@');
        dcmqr.setCalling(callingAETHost[0]);
        if (callingAETHost[1] != null) {
            dcmqr.setLocalHost(callingAETHost[1]);
        }
    }
    if (cl.hasOption("username")) {
        String username = cl.getOptionValue("username");
        UserIdentity userId;
        if (cl.hasOption("passcode")) {
            String passcode = cl.getOptionValue("passcode");
            userId = new UserIdentity.UsernamePasscode(username, passcode.toCharArray());
        } else {
            userId = new UserIdentity.Username(username);
        }
        userId.setPositiveResponseRequested(cl.hasOption("uidnegrsp"));
        dcmqr.setUserIdentity(userId);
    }
    if (cl.hasOption("connectTO"))
        dcmqr.setConnectTimeout(parseInt(cl.getOptionValue("connectTO"),
                "illegal argument of option -connectTO", 1, Integer.MAX_VALUE));
    if (cl.hasOption("reaper"))
        dcmqr.setAssociationReaperPeriod(parseInt(cl.getOptionValue("reaper"),
                "illegal argument of option -reaper", 1, Integer.MAX_VALUE));
    if (cl.hasOption("cfindrspTO"))
        dcmqr.setDimseRspTimeout(parseInt(cl.getOptionValue("cfindrspTO"),
                "illegal argument of option -cfindrspTO", 1, Integer.MAX_VALUE));
    if (cl.hasOption("cmoverspTO"))
        dcmqr.setRetrieveRspTimeout(parseInt(cl.getOptionValue("cmoverspTO"),
                "illegal argument of option -cmoverspTO", 1, Integer.MAX_VALUE));
    if (cl.hasOption("cgetrspTO"))
        dcmqr.setRetrieveRspTimeout(parseInt(cl.getOptionValue("cgetrspTO"),
                "illegal argument of option -cgetrspTO", 1, Integer.MAX_VALUE));
    if (cl.hasOption("acceptTO"))
        dcmqr.setAcceptTimeout(parseInt(cl.getOptionValue("acceptTO"), "illegal argument of option -acceptTO",
                1, Integer.MAX_VALUE));
    if (cl.hasOption("releaseTO"))
        dcmqr.setReleaseTimeout(parseInt(cl.getOptionValue("releaseTO"),
                "illegal argument of option -releaseTO", 1, Integer.MAX_VALUE));
    if (cl.hasOption("soclosedelay"))
        dcmqr.setSocketCloseDelay(parseInt(cl.getOptionValue("soclosedelay"),
                "illegal argument of option -soclosedelay", 1, 10000));
    if (cl.hasOption("rcvpdulen"))
        dcmqr.setMaxPDULengthReceive(
                parseInt(cl.getOptionValue("rcvpdulen"), "illegal argument of option -rcvpdulen", 1, 10000)
                        * KB);
    if (cl.hasOption("sndpdulen"))
        dcmqr.setMaxPDULengthSend(
                parseInt(cl.getOptionValue("sndpdulen"), "illegal argument of option -sndpdulen", 1, 10000)
                        * KB);
    if (cl.hasOption("sosndbuf"))
        dcmqr.setSendBufferSize(
                parseInt(cl.getOptionValue("sosndbuf"), "illegal argument of option -sosndbuf", 1, 10000) * KB);
    if (cl.hasOption("sorcvbuf"))
        dcmqr.setReceiveBufferSize(
                parseInt(cl.getOptionValue("sorcvbuf"), "illegal argument of option -sorcvbuf", 1, 10000) * KB);
    if (cl.hasOption("filebuf"))
        dcmqr.setFileBufferSize(
                parseInt(cl.getOptionValue("filebuf"), "illegal argument of option -filebuf", 1, 10000) * KB);
    dcmqr.setPackPDV(!cl.hasOption("pdv1"));
    dcmqr.setTcpNoDelay(!cl.hasOption("tcpdelay"));
    dcmqr.setMaxOpsInvoked(cl.hasOption("async")
            ? parseInt(cl.getOptionValue("async"), "illegal argument of option -async", 0, 0xffff)
            : 1);
    dcmqr.setMaxOpsPerformed(cl.hasOption("cstoreasync")
            ? parseInt(cl.getOptionValue("cstoreasync"), "illegal argument of option -cstoreasync", 0, 0xffff)
            : 0);
    if (cl.hasOption("C"))
        dcmqr.setCancelAfter(
                parseInt(cl.getOptionValue("C"), "illegal argument of option -C", 1, Integer.MAX_VALUE));
    if (cl.hasOption("lowprior"))
        dcmqr.setPriority(CommandUtils.LOW);
    if (cl.hasOption("highprior"))
        dcmqr.setPriority(CommandUtils.HIGH);
    if (cl.hasOption("cstore")) {
        String[] storeTCs = cl.getOptionValues("cstore");
        for (String storeTC : storeTCs) {
            String cuid;
            String[] tsuids;
            int colon = storeTC.indexOf(':');
            if (colon == -1) {
                cuid = storeTC;
                tsuids = DEF_TS;
            } else {
                cuid = storeTC.substring(0, colon);
                String ts = storeTC.substring(colon + 1);
                try {
                    tsuids = TS.valueOf(ts).uids;
                } catch (IllegalArgumentException e) {
                    tsuids = ts.split(",");
                }
            }
            try {
                cuid = CUID.valueOf(cuid).uid;
            } catch (IllegalArgumentException e) {
                // assume cuid already contains UID
            }
            dcmqr.addStoreTransferCapability(cuid, tsuids);
        }
        if (cl.hasOption("cstoredest"))
            dcmqr.setStoreDestination(cl.getOptionValue("cstoredest"));
    }
    dcmqr.setCFind(!cl.hasOption("nocfind"));
    dcmqr.setCGet(cl.hasOption("cget"));
    if (cl.hasOption("cmove"))
        dcmqr.setMoveDest(cl.getOptionValue("cmove"));
    if (cl.hasOption("evalRetrieveAET"))
        dcmqr.setEvalRetrieveAET(true);
    dcmqr.setQueryLevel(cl.hasOption("P") ? QueryRetrieveLevel.PATIENT
            : cl.hasOption("S") ? QueryRetrieveLevel.SERIES
                    : cl.hasOption("I") ? QueryRetrieveLevel.IMAGE : QueryRetrieveLevel.STUDY);
    if (cl.hasOption("noextneg"))
        dcmqr.setNoExtNegotiation(true);
    if (cl.hasOption("rel"))
        dcmqr.setRelationQR(true);
    if (cl.hasOption("datetime"))
        dcmqr.setDateTimeMatching(true);
    if (cl.hasOption("fuzzy"))
        dcmqr.setFuzzySemanticPersonNameMatching(true);
    if (!cl.hasOption("P")) {
        if (cl.hasOption("retall"))
            dcmqr.addPrivate(UID.PrivateStudyRootQueryRetrieveInformationModelFIND);
        if (cl.hasOption("blocked"))
            dcmqr.addPrivate(UID.PrivateBlockedStudyRootQueryRetrieveInformationModelFIND);
        if (cl.hasOption("vmf"))
            dcmqr.addPrivate(UID.PrivateVirtualMultiframeStudyRootQueryRetrieveInformationModelFIND);
    }
    if (cl.hasOption("cfind")) {
        String[] cuids = cl.getOptionValues("cfind");
        for (int i = 0; i < cuids.length; i++)
            dcmqr.addPrivate(cuids[i]);
    }
    if (!cl.hasOption("nodefret"))
        dcmqr.addDefReturnKeys();
    if (cl.hasOption("r")) {
        String[] returnKeys = cl.getOptionValues("r");
        for (int i = 0; i < returnKeys.length; i++)
            dcmqr.addReturnKey(Tag.toTagPath(returnKeys[i]));
    }
    if (cl.hasOption("q")) {
        String[] matchingKeys = cl.getOptionValues("q");
        for (int i = 1; i < matchingKeys.length; i++, i++)
            dcmqr.addMatchingKey(Tag.toTagPath(matchingKeys[i - 1]), matchingKeys[i]);
    }

    dcmqr.configureTransferCapability(cl.hasOption("ivrle"));

    int repeat = cl.hasOption("repeat")
            ? parseInt(cl.getOptionValue("repeat"), "illegal argument of option -repeat", 1, Integer.MAX_VALUE)
            : 0;
    int interval = cl.hasOption("repeatdelay")
            ? parseInt(cl.getOptionValue("repeatdelay"), "illegal argument of option -repeatdelay", 1,
                    Integer.MAX_VALUE)
            : 0;
    boolean closeAssoc = cl.hasOption("closeassoc");

    if (cl.hasOption("tls")) {
        String cipher = cl.getOptionValue("tls");
        if ("NULL".equalsIgnoreCase(cipher)) {
            dcmqr.setTlsWithoutEncyrption();
        } else if ("3DES".equalsIgnoreCase(cipher)) {
            dcmqr.setTls3DES_EDE_CBC();
        } else if ("AES".equalsIgnoreCase(cipher)) {
            dcmqr.setTlsAES_128_CBC();
        } else {
            exit("Invalid parameter for option -tls: " + cipher);
        }
        if (cl.hasOption("tls1")) {
            dcmqr.setTlsProtocol(TLS1);
        } else if (cl.hasOption("ssl3")) {
            dcmqr.setTlsProtocol(SSL3);
        } else if (cl.hasOption("no_tls1")) {
            dcmqr.setTlsProtocol(NO_TLS1);
        } else if (cl.hasOption("no_ssl3")) {
            dcmqr.setTlsProtocol(NO_SSL3);
        } else if (cl.hasOption("no_ssl2")) {
            dcmqr.setTlsProtocol(NO_SSL2);
        }
        dcmqr.setTlsNeedClientAuth(!cl.hasOption("noclientauth"));
        if (cl.hasOption("keystore")) {
            dcmqr.setKeyStoreURL(cl.getOptionValue("keystore"));
        }
        if (cl.hasOption("keystorepw")) {
            dcmqr.setKeyStorePassword(cl.getOptionValue("keystorepw"));
        }
        if (cl.hasOption("keypw")) {
            dcmqr.setKeyPassword(cl.getOptionValue("keypw"));
        }
        if (cl.hasOption("truststore")) {
            dcmqr.setTrustStoreURL(cl.getOptionValue("truststore"));
        }
        if (cl.hasOption("truststorepw")) {
            dcmqr.setTrustStorePassword(cl.getOptionValue("truststorepw"));
        }
        long t1 = System.currentTimeMillis();
        try {
            dcmqr.initTLS();
        } catch (Exception e) {
            System.err.println("ERROR: Failed to initialize TLS context:" + e.getMessage());
            System.exit(2);
        }
        long t2 = System.currentTimeMillis();
        LOG.info("Initialize TLS context in {} s", Float.valueOf((t2 - t1) / 1000f));
    }
    try {
        dcmqr.start();
    } catch (Exception e) {
        System.err.println(
                "ERROR: Failed to start server for receiving " + "requested objects:" + e.getMessage());
        System.exit(2);
    }
    try {
        long t1 = System.currentTimeMillis();
        try {
            dcmqr.open();
        } catch (Exception e) {
            LOG.error("Failed to establish association:", e);
            System.exit(2);
        }
        long t2 = System.currentTimeMillis();
        LOG.info("Connected to {} in {} s", remoteAE, Float.valueOf((t2 - t1) / 1000f));

        for (;;) {
            List<DicomObject> result;
            if (dcmqr.isCFind()) {
                result = dcmqr.query();
                long t3 = System.currentTimeMillis();
                LOG.info("Received {} matching entries in {} s", Integer.valueOf(result.size()),
                        Float.valueOf((t3 - t2) / 1000f));
                t2 = t3;
            } else {
                result = Collections.singletonList(dcmqr.getKeys());
            }
            if (dcmqr.isCMove() || dcmqr.isCGet()) {
                if (dcmqr.isCMove())
                    dcmqr.move(result);
                else
                    dcmqr.get(result);
                long t4 = System.currentTimeMillis();
                LOG.info("Retrieved {} objects (warning: {}, failed: {}) in {}s",
                        new Object[] { Integer.valueOf(dcmqr.getTotalRetrieved()),
                                Integer.valueOf(dcmqr.getWarning()), Integer.valueOf(dcmqr.getFailed()),
                                Float.valueOf((t4 - t2) / 1000f) });
            }
            if (repeat == 0 || closeAssoc) {
                try {
                    dcmqr.close();
                } catch (InterruptedException e) {
                    LOG.error(e.getMessage(), e);
                }
                LOG.info("Released connection to {}", remoteAE);
            }
            if (repeat-- == 0)
                break;
            Thread.sleep(interval);
            long t4 = System.currentTimeMillis();
            dcmqr.open();
            t2 = System.currentTimeMillis();
            LOG.info("Reconnect or reuse connection to {} in {} s", remoteAE, Float.valueOf((t2 - t4) / 1000f));
        }
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
    } catch (InterruptedException e) {
        LOG.error(e.getMessage(), e);
    } catch (ConfigurationException e) {
        LOG.error(e.getMessage(), e);
    } finally {
        dcmqr.stop();
    }
}

From source file:org.openscore.content.httpclient.build.Utils.java

public static List<? extends NameValuePair> urlEncodeMultipleParams(String params, boolean urlEncode)
        throws UrlEncodeException {
    List<BasicNameValuePair> list = new ArrayList<>();

    String[] pairs = params.split("&");
    for (String pair : pairs) {
        String[] nameValue = pair.split("=", 2);
        String name = nameValue[0];
        String value = nameValue.length == 2 ? nameValue[1] : null;

        if (!urlEncode) {
            try {
                name = URLDecoder.decode(name, "UTF-8");
                if (value != null) {
                    value = URLDecoder.decode(value, "UTF-8");
                }/*w w w  . jav a2 s.com*/
            } catch (UnsupportedEncodingException e) {
                //never happens
                throw new RuntimeException(e);
            } catch (IllegalArgumentException ie) {
                throw new UrlEncodeException(ie.getMessage(), ie);
            }
        }

        list.add(new BasicNameValuePair(name, value));
    }
    return list;
}

From source file:com.mowitnow.lawnmower.service.InputService.java

private static void checkInput(String input) {
    try {/*from w w w .  j av  a 2 s.c  o  m*/
        logger.log(null);
        Preconditions.checkArgument(StringUtils.isNotBlank(input), "Empty input is not allowed.");
        String lines[] = StringUtils.split(input, System.getProperty("line.separator"));
        Preconditions.checkArgument((lines.length % 2) == 1, "The number of input lines must be odd.");
        Preconditions.checkArgument(lines[0].matches("[0-9]+ [0-9]+"), "Lawn size is invalid.");
        for (int i = 1; i < lines.length - 1; i = i + 2) {
            Preconditions.checkArgument(lines[i].matches("[0-9]+ [0-9]+ [NESW]"),
                    "Invalid position or direction for mower " + (i + 1) / 2 + ".");
            Preconditions.checkArgument(lines[i + 1].matches("[DGA]*"),
                    "Invalid command for mower " + (i + 1) / 2 + ".");
        }
    } catch (IllegalArgumentException iex) {
        logger.log(iex.getMessage());
    }
}

From source file:SocketAddressEncoder.java

public static InetSocketAddress decode(String str) throws UnknownHostException {
    StringTokenizer st = new StringTokenizer(str, ",");
    if (st.countTokens() != 6) {
        throw new Exception("Illegal amount of tokens");
    }/*from  w  ww .ja  va2 s.  co  m*/

    StringBuffer sb = new StringBuffer();
    try {
        sb.append(convertAndValidateNumber(st.nextToken()));
        sb.append('.');
        sb.append(convertAndValidateNumber(st.nextToken()));
        sb.append('.');
        sb.append(convertAndValidateNumber(st.nextToken()));
        sb.append('.');
        sb.append(convertAndValidateNumber(st.nextToken()));
    } catch (IllegalArgumentException e) {
        throw new Exception(e.getMessage());
    }

    InetAddress dataAddr = InetAddress.getByName(sb.toString());

    // get data server port
    int dataPort = 0;
    try {
        int hi = convertAndValidateNumber(st.nextToken());
        int lo = convertAndValidateNumber(st.nextToken());
        dataPort = (hi << 8) | lo;
    } catch (IllegalArgumentException ex) {
        throw new Exception("Invalid data port: " + str);
    }

    return new InetSocketAddress(dataAddr, dataPort);
}

From source file:io.cloudslang.content.httpclient.build.Utils.java

public static String urlEncodeQueryParams(String params, boolean urlEncode) throws UrlEncodeException {
    String encodedParams = params;
    if (!urlEncode) {
        try {/*  w  ww.j  a v  a2  s .co  m*/
            encodedParams = URLDecoder.decode(params, DEFAULT_CHARACTER_SET);
        } catch (UnsupportedEncodingException e) {
            //                never happens
            throw new RuntimeException(e);
        } catch (IllegalArgumentException ie) {
            throw new UrlEncodeException(ie.getMessage(), ie);
        }
    }
    return encodedParams;
}

From source file:com.xx_dev.apn.proxy.utils.HostNamePortUtil.java

public static int getPort(HttpRequest httpRequest) {
    int originalPort = 80;

    if (httpRequest.getMethod().equals(HttpMethod.CONNECT)) {
        originalPort = 443;/*from w  w  w . ja va2 s  .c  om*/
    }

    String originalHostHeader = httpRequest.headers().get(HttpHeaders.Names.HOST);

    if (StringUtils.isBlank(originalHostHeader) && httpRequest.getMethod().equals(HttpMethod.CONNECT)) {
        originalHostHeader = httpRequest.getUri();
    }

    if (StringUtils.isNotBlank(originalHostHeader)) {
        if (StringUtils.split(originalHostHeader, ": ").length == 2) {
            originalPort = Integer.parseInt(StringUtils.split(originalHostHeader, ": ")[1]);
        }
    } else {
        String uriStr = httpRequest.getUri();
        try {
            URI uri = URI.create(uriStr);

            if (uri.getPort() > 0) {
                originalPort = uri.getPort();
            }
        } catch (IllegalArgumentException e) {
            logger.error(e.getMessage(), e);
            originalPort = -1;
        }
    }

    return originalPort;
}

From source file:fr.paris.lutece.plugins.rss.web.FeedUtil.java

/**
 * Gets an XML for the given resource./*from w w  w.j  a v a2s  .  c  om*/
 * @param resource resource
 * @param strFeedType feed type
 * @param strEncoding encoding
 * @param nMaxItems max items
 * @return the xml generated
 */
public static String getFeed(IFeedResource resource, String strFeedType, String strEncoding, int nMaxItems) {
    if (resource.getItems().isEmpty()) {
        return StringUtils.EMPTY;
    }

    // WireFeed does not contain enough data, but can be passed for output generation.
    WireFeed wireFeed = FeedTypeManager.getManager().getWireFeed(strFeedType, resource, strEncoding, nMaxItems);

    WireFeedOutput output = new WireFeedOutput();
    String strXML = StringUtils.EMPTY;

    try {
        strXML = output.outputString(wireFeed);
    } catch (IllegalArgumentException e) {
        AppLogService.error(e.getMessage(), e);
    } catch (FeedException e) {
        AppLogService.error(e.getMessage(), e);
    }

    return strXML;
}

From source file:io.cloudslang.content.httpclient.build.Utils.java

public static List<? extends NameValuePair> urlEncodeMultipleParams(String params, boolean urlEncode)
        throws UrlEncodeException {
    List<BasicNameValuePair> list = new ArrayList<>();

    String[] pairs = params.split("&");
    for (String pair : pairs) {
        String[] nameValue = pair.split("=", 2);
        String name = nameValue[0];
        String value = nameValue.length == 2 ? nameValue[1] : null;

        if (!urlEncode) {
            try {
                name = URLDecoder.decode(name, DEFAULT_CHARACTER_SET);
                if (value != null) {
                    value = URLDecoder.decode(value, DEFAULT_CHARACTER_SET);
                }/* w  w  w  . j  ava  2s. co  m*/
            } catch (UnsupportedEncodingException e) {
                //never happens
                throw new RuntimeException(e);
            } catch (IllegalArgumentException ie) {
                throw new UrlEncodeException(ie.getMessage(), ie);
            }
        }
        list.add(new BasicNameValuePair(name, value));
    }
    return list;
}

From source file:de.mpg.escidoc.services.util.SchematronUtil.java

public static boolean isChild(String ou) throws Exception {
    if (ou != null) {
        HttpClient httpClient = new HttpClient();
        GetMethod getMethod = new GetMethod(PropertyReader.getProperty("escidoc.framework_access.framework.url")
                + "/oum/organizational-unit/" + ou.trim() + "/resources/path-list");
        try {/* w  ww  .  j  a va  2  s .c  o  m*/
            httpClient.executeMethod(getMethod);
            if (getMethod.getStatusCode() == 200) {
                if (getMethod.getResponseBodyAsString().contains("\"/oum/organizational-unit/"
                        + PropertyReader.getProperty("escidoc.pubman.root.organisation.id") + "\"")) {
                    return true;
                } else {
                    return false;
                }
            } else {
                LOGGER.warn("Error while checking organizational-unit path: Return code "
                        + getMethod.getStatusCode() + "\n" + getMethod.getResponseBodyAsString());
                return false;
            }
        } catch (IllegalArgumentException e) {
            LOGGER.warn("Error while checking organizational-unit path: " + e.getMessage());
            LOGGER.debug("Error", e);
            return false;
        }
    } else {
        return false;
    }
}

From source file:name.martingeisse.common.security.SecurityTokenUtil.java

/**
 * Validates the specified security token. Returns the subject if the token is valid.
 * Throws an {@link IllegalArgumentException} if invalid. This exception contains
 * an error message about the problem.//  w w w .  ja va  2  s.  c o m
 * 
 * @param token the token
 * @param minTimestamp the maximum allowed value for the token's timestamp
 * @param secret the secret used to generate the HMAC
 * @return the token's subject
 */
public static String validateToken(String token, ReadableInstant minTimestamp, String secret) {

    // split the token into segments
    String[] tokenSegments = StringUtils.split(token, '|');
    if (tokenSegments.length != 3) {
        throw new IllegalArgumentException("malformed token (has " + tokenSegments.length + " segments)");
    }

    // validate the signature
    String payload = (tokenSegments[0] + '|' + tokenSegments[1]);
    String expectedSignatureBase64 = HmacUtil.generateHmacBase64(payload, secret, HmacUtil.ALGORITHM_SHA256);
    if (!expectedSignatureBase64.equals(tokenSegments[2])) {
        throw new IllegalArgumentException("invalid token signature");
    }

    // validate the timestamp
    ReadableInstant timestamp;
    try {
        timestamp = dateTimeFormatter.parseDateTime(tokenSegments[1]);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("malformed timestamp: " + e.getMessage());
    }
    if (timestamp.isBefore(minTimestamp)) {
        throw new IllegalArgumentException("token has expired");
    }

    // return the subject
    return tokenSegments[0];

}