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:com.googlecode.l10nmavenplugin.validators.property.UrlValidator.java

/**
 * ERROR if URL does not match regexp./*w w  w . j  ava 2  s.  co m*/
 * 
 * ERROR if URL does not support https context and is an HTML import.
 * 
 * Performs a MessageFormat if needed.
 * 
 * @note the {@link org.apache.commons.validator.UrlValidator} from Apache does not seem to support scheme relative URLs.
 * 
 * @param key
 * @param message
 * @param propertyName
 * @return Number of errors
 */
public int validate(Property property, List<L10nReportItem> reportItems) {
    int nbErrors = 0;
    String formattedMessage = property.getMessage();

    try {
        if (formattingParametersExtractor.isParametric(formattedMessage)) {
            formattedMessage = formattingParametersExtractor.defaultFormat(property.getMessage());
        }
        // Unescape HTML in case URL is used in HTML context (ex: &amp; -> &)
        String url = StringEscapeUtils.unescapeHtml(formattedMessage);
        Matcher m = URL_VALIDATION_PATTERN.matcher(url);

        if (!m.matches()) {
            nbErrors++;
            L10nReportItem reportItem = new L10nReportItem(Type.URL_VALIDATION, "Invalid URL syntax.", property,
                    formattedMessage);
            reportItems.add(reportItem);
            logger.log(reportItem);

        } else {
            // If URL path extension is an HTML include (.js, .css, .jpg, ...) check that URL inherits https protocol
            // Context is mandatory for scheme relative URLs
            URL context = new URL("https://");
            URL resultingURL = new URL(context, url);

            String extension = FilenameUtils.getExtension(resultingURL.getPath());
            if (HTML_URL_INCLUDE_EXTESIONS.contains(extension) && !"https".equals(resultingURL.getProtocol())) {
                nbErrors++;
                L10nReportItem reportItem = new L10nReportItem(Type.URL_VALIDATION,
                        "URL for external HTML import [." + extension
                                + "] must be scheme relative to avoid mixed content in HTTPS context.",
                        property, formattedMessage);
                reportItems.add(reportItem);
                logger.log(reportItem);
            }
        }

    } catch (IllegalArgumentException e) {
        // Catch MessageFormat errors in case of malformed message
        nbErrors++;
        L10nReportItem reportItem = new L10nReportItem(Type.MALFORMED_PARAMETER,
                "URL contains malformed parameters: " + e.getMessage(), property, formattedMessage);
        reportItems.add(reportItem);
        logger.log(reportItem);
    } catch (MalformedURLException e) {
        nbErrors++;
        L10nReportItem reportItem = new L10nReportItem(Type.URL_VALIDATION, "Malformed URL: " + e.getMessage(),
                property, formattedMessage);
        reportItems.add(reportItem);
        logger.log(reportItem);
    }

    return nbErrors;
}

From source file:io.servicecomb.foundation.ssl.SSLOptionTest.java

@SuppressWarnings("unused")
@Test/*from ww w.j a v a 2  s.  c  o m*/
public void testSSLOptionNull() {
    try {
        SSLOption option = SSLOption.build(DIR + "/servers.ssl.properties");
    } catch (IllegalArgumentException e) {
        Assert.assertEquals("Bad file name.", e.getMessage());
    }
}

From source file:it.geosolutions.geoserver.sira.security.expression.ExpressionRuleEngine.java

/**
 *
 * @param rule//from   w w w .  jav  a 2  s .  c  om
 * @return
 */
public AccessMode evaluateAccessMode(Rule rule) {
    this.checkRulePreconditions(rule);

    final String result = this.evaluateExpression(rule.getAccessMode(), String.class);
    if (Rule.IGNORERULE.equals(result)) {
        return null;
    } else {
        try {
            return AccessMode.valueOf(result);
        } catch (IllegalArgumentException e) {
            LOGGER.log(Level.SEVERE, e.getMessage());
            throw new IllegalStateException(String.format(
                    "rule.accessMode expression must be evaluable as either READ, WRITE or IGNORERULE, but unknown '%s' was evaluated",
                    result), e);
        }
    }
}

From source file:co.runrightfast.vertx.orientdb.verticle.OrientDBVerticleTest.java

@Test
public void testEventLogRepository() throws Exception {
    final Vertx vertx = vertxService.getVertx();
    final RunRightFastVerticleId verticleManagerId = EventLogRepository.VERTICLE_ID;

    final CompletableFuture<GetEventCount.Response> getEventCountFuture = new CompletableFuture<>();
    final long timeout = 60000L;

    // because the verticles are deployed asynchronously, the EventLogRepository verticle may not yet be deployed yet
    // the message codec for the Verticle only gets registered, while the verticle is starting. Thus, the message codec may not yet be registered.
    while (true) {
        try {/*from  ww  w  .  j  a  v a2 s  .c o  m*/
            vertx.eventBus().send(EventBusAddress.eventBusAddress(verticleManagerId, GetEventCount.class),
                    GetEventCount.Request.getDefaultInstance(), new DeliveryOptions().setSendTimeout(timeout),
                    responseHandler(getEventCountFuture, GetEventCount.Response.class));
            break;
        } catch (final IllegalArgumentException e) {
            if (e.getMessage().contains("No message codec for type")) {
                log.log(WARNING, "Waiting for EventLogRepository ... ", e);
                Thread.sleep(5000L);
            } else {
                throw e;
            }
        }
    }
    final GetEventCount.Response getEventCountResponse = getEventCountFuture.get(timeout,
            TimeUnit.MILLISECONDS);
    assertThat(getEventCountResponse.getCount(), is(0L));

    final CompletableFuture<CreateEvent.Response> createEventFuture = new CompletableFuture<>();
    vertx.eventBus().send(EventBusAddress.eventBusAddress(verticleManagerId, CreateEvent.class),
            CreateEvent.Request.newBuilder().setEvent("testEventLogRepository").build(),
            new DeliveryOptions().setSendTimeout(timeout),
            responseHandler(createEventFuture, CreateEvent.Response.class));
    final CreateEvent.Response createEventResponse = createEventFuture.get(timeout, TimeUnit.MILLISECONDS);
    log.info(String.format("record id = %d::%d", createEventResponse.getId().getClusterId(),
            createEventResponse.getId().getPosition()));

    final CompletableFuture<GetEventCount.Response> getEventCountFuture2 = new CompletableFuture<>();
    vertx.eventBus().send(EventBusAddress.eventBusAddress(verticleManagerId, GetEventCount.class),
            GetEventCount.Request.getDefaultInstance(), new DeliveryOptions().setSendTimeout(timeout),
            responseHandler(getEventCountFuture2, GetEventCount.Response.class));
    final GetEventCount.Response getEventCountResponse2 = getEventCountFuture2.get(timeout,
            TimeUnit.MILLISECONDS);
    assertThat(getEventCountResponse2.getCount(), is(1L));
}

From source file:com.ecyrd.management.SimpleMBean.java

public void setAttribute(Attribute attr)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    Method m;/*from ww  w  .ja va2 s . c  o  m*/

    String mname = "set" + StringUtils.capitalize(attr.getName());
    m = findGetterSetter(getClass(), mname, attr.getValue().getClass());

    if (m == null)
        throw new AttributeNotFoundException(attr.getName());

    Object[] args = { attr.getValue() };

    try {
        m.invoke(this, args);
    } catch (IllegalArgumentException e) {
        throw new InvalidAttributeValueException("Faulty argument: " + e.getMessage());
    } catch (IllegalAccessException e) {
        throw new ReflectionException(e, "Cannot access attribute " + e.getMessage());
    } catch (InvocationTargetException e) {
        throw new ReflectionException(e, "Cannot invoke attribute " + e.getMessage());
    }
}

From source file:org.jolokia.client.request.J4pReadIntegrationTest.java

private void checkNames(String pMethod, List<String>... pNames)
        throws MalformedObjectNameException, J4pException {
    for (int i = 0; i < pNames.length; i++) {
        for (String name : pNames[i]) {
            System.out.println(name);
            ObjectName oName = new ObjectName(name);
            J4pReadRequest req = new J4pReadRequest(oName, "Ok");
            req.setPreferredHttpMethod(pMethod);
            J4pReadResponse resp = j4pClient.execute(req);
            Collection names = resp.getObjectNames();
            assertEquals(1, names.size());
            assertEquals(oName, names.iterator().next());
            assertEquals("OK", resp.getValue());
            Collection<String> attrs = resp.getAttributes();
            assertEquals(1, attrs.size());

            assertNotNull(resp.getValue("Ok"));
            try {
                resp.getValue("Koepke");
                fail();//w  w w. j  a v a2s . co m
            } catch (IllegalArgumentException exp) {
                assertTrue(exp.getMessage().contains("Koepke"));
            }
        }
    }
}

From source file:de.hybris.platform.accountsummaryaddon.document.dao.impl.DefaultPagedB2BDocumentDaoTest.java

@Test
public void shouldGetErrorInvalidPageSize() {

    final AccountSummaryDocumentQuery query = new B2BDocumentQueryBuilder(0, -1, B2BDocumentModel.OPENAMOUNT,
            true).build();//  ww w  . ja v  a 2s . c o m
    try {
        pagedB2BDocumentDao.findDocuments(query);
        TestCase.fail();
    } catch (final IllegalArgumentException e) {
        //Success
        TestCase.assertEquals("pageableData page size must be greater than zero", e.getMessage());
    }
}

From source file:io.cloudslang.worker.execution.reflection.ReflectionAdapterImpl.java

@Override
public Object executeControlAction(ControlActionMetadata actionMetadata, Map<String, ?> actionData) {
    Validate.notNull(actionMetadata, "Action metadata is null");
    if (logger.isDebugEnabled())
        logger.debug("Executing control action [" + actionMetadata.getClassName() + '.'
                + actionMetadata.getMethodName() + ']');
    try {/*from   w ww.  j a va 2s  . c om*/
        Object actionBean = getActionBean(actionMetadata);
        Method actionMethod = getActionMethod(actionMetadata);
        Object[] arguments = buildParametersArray(actionMethod, actionData);
        if (logger.isTraceEnabled())
            logger.trace("Invoking...");
        Object result = actionMethod.invoke(actionBean, arguments);
        clearStateAfterInvocation(actionData);
        if (logger.isDebugEnabled())
            logger.debug("Control action [" + actionMetadata.getClassName() + '.'
                    + actionMetadata.getMethodName() + "] done");
        return result;
    } catch (IllegalArgumentException ex) {
        String message = "Failed to run the action! Wrong arguments were passed to class: "
                + actionMetadata.getClassName() + ", method: " + actionMetadata.getMethodName() + ", reason: "
                + ex.getMessage();
        throw new FlowExecutionException(message, ex);
    } catch (InvocationTargetException ex) {
        String message = ex.getTargetException() == null ? ex.getMessage()
                : ex.getTargetException().getMessage();
        logger.error(getExceptionMessage(actionMetadata) + ", reason: " + message, ex);
        throw new FlowExecutionException(message, ex);
    } catch (Exception ex) {
        throw new FlowExecutionException(getExceptionMessage(actionMetadata) + ", reason: " + ex.getMessage(),
                ex);
    }
}

From source file:de.hybris.platform.accountsummaryaddon.document.dao.impl.DefaultPagedB2BDocumentDaoTest.java

@Test
public void shouldGetErrorInvalidPage() {

    final AccountSummaryDocumentQuery query = new B2BDocumentQueryBuilder(-1, 10, B2BDocumentModel.OPENAMOUNT,
            true).build();/*from  w  ww.j a v  a2 s.c om*/
    try {
        pagedB2BDocumentDao.findDocuments(query);
        TestCase.fail();
    } catch (final IllegalArgumentException e) {
        //Success
        TestCase.assertEquals("pageableData current page must be zero or greater", e.getMessage());
    }
}

From source file:de.uni_koblenz.west.splendid.tools.NXVoidGenerator.java

private void postProcess(Node context) throws RDFHandlerException {
    if (context == null)
        return; // nothing to do

    URI dataset = vf.createURI(context.toString());

    // general void information
    writer.handleStatement(vf.createStatement(dataset, RDF.TYPE, DATASET));
    writer.handleStatement(vf.createStatement(dataset, TRIPLES, vf.createLiteral(String.valueOf(tripleCount))));
    writer.handleStatement(// ww w.  j  a v  a 2 s  . c  om
            vf.createStatement(dataset, PROPERTIES, vf.createLiteral(String.valueOf(predCount.size()))));

    List<Node> keys = new ArrayList<Node>(pMap.keySet());
    Collections.sort(keys);
    for (Node n : keys) {
        try {
            URI predicate = vf.createURI(n.toString());
            writePredicateStatToVoid(dataset, predicate, predCount.countMap.get(pMap.get(n)), 0, 0);
        } catch (IllegalArgumentException e) {
            System.err.println("bad predicate: " + e.getMessage());
            continue;
        }
    }

    keys = new ArrayList<Node>(typeCount.countMap.keySet());
    Collections.sort(keys);
    for (Node n : keys) {
        try {
            URI type = vf.createURI(n.toString());
            writeTypeStatToVoid(dataset, type, typeCount.countMap.get(n));
        } catch (IllegalArgumentException e) {
            System.err.println("bad type: " + e.getMessage());
            continue;
        }
    }

    //      writer.handleStatement(vf.createStatement(dataset, vf.createURI(VOID2.classes.toString()), vf.createLiteral(String.valueOf(typeCountMap.size()))));
    //      writer.handleStatement(vf.createStatement(dataset, vf.createURI(VOID2.entities.toString()), vf.createLiteral(String.valueOf(entityCount))));

    //      System.out.println("Context [" + contextCount + "] " + context + " has " + predCount.size() + " distinct predicates, " + tripleCount + " triples.");

    // reset counters etc.
    tripleCount = 0;
    predCount = new Counter<Integer>();
    pMap = new HashMap<Node, Integer>();
}