Example usage for java.lang IllegalStateException getMessage

List of usage examples for java.lang IllegalStateException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:ezbake.services.graph.TitanGraphStore.java

private TransactionId getTransactionId() throws InvalidRequestException {
    try {//w w w . ja va 2  s.  co m
        return transIdGenerator.nextId();
    } catch (final IllegalStateException ex) {
        throw new InvalidRequestException("Transaction ID generator failed: " + ex.getMessage());
    }
}

From source file:it.greenvulcano.gvesb.api.controller.GvConfigurationControllerRest.java

@POST
@Path("/configuration/{configId}/{description}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@RolesAllowed({ Authority.ADMINISTRATOR, Authority.MANAGER })
public void installConfiguration(@PathParam("configId") String id, @PathParam("description") String description,
        @Multipart(value = "gvconfiguration") Attachment config) {

    try {/*from w  w w .  j  a  v a  2 s .  c  o m*/
        Properties descriptions = getConfDescriptionProperties();

        File currentConfig = new File(XMLConfig.getBaseConfigPath());
        if (id.equals(currentConfig.getName()) && !id.endsWith("-debug")) {
            throw new WebApplicationException(Response.status(Response.Status.CONFLICT).build());
        }

        MediaType contentType = Optional.ofNullable(config.getContentType())
                .orElse(MediaType.APPLICATION_OCTET_STREAM_TYPE);

        switch (contentType.getSubtype()) {

        case "zip":
        case "x-zip-compressed":

            try (InputStream inputData = config.getDataHandler().getInputStream()) {

                gvConfigurationManager.install(id, IOUtils.toByteArray(inputData));
                descriptions.setProperty(id, description);
                saveConfDescriptionProperties(descriptions);

            } catch (IllegalStateException e) {
                LOG.error("Failed to install configuraton, operation already in progress", e);
                throw new WebApplicationException(
                        Response.status(Response.Status.SERVICE_UNAVAILABLE).entity(e.getMessage()).build());

            } catch (Exception e) {
                LOG.error("Failed to install configuraton, something bad appened", e);
                throw new WebApplicationException(
                        Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build());

            }

            break;

        default:
            throw new WebApplicationException(Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE).build());

        }
    } catch (FileNotFoundException e) {
        //TODO: perhaps it is better to allow uploading even if the descriptions data are not found
        LOG.error("Failed to upload configuraton, something bad appened", e);
    } catch (IOException e) {
        //TODO: perhaps it is better to allow uploading even if the descriptions data are not found
        LOG.error("Failed to upload configuraton, something bad appened", e);
    }

}

From source file:org.finra.herd.service.helper.DefaultNotificationMessageBuilderTest.java

@Test
public void testBuildSystemMonitorResponseInvalidXpathProperties() throws Exception {
    // Override configuration to set an invalid XPath properties format (this happens when an invalid unicode character is found).
    Map<String, Object> overrideMap = new HashMap<>();
    overrideMap.put(ConfigurationValue.HERD_NOTIFICATION_SQS_SYS_MONITOR_RESPONSE_VELOCITY_TEMPLATE.getKey(),
            SYSTEM_MONITOR_NOTIFICATION_MESSAGE_VELOCITY_TEMPLATE_XML);
    overrideMap.put(ConfigurationValue.HERD_NOTIFICATION_SQS_SYS_MONITOR_REQUEST_XPATH_PROPERTIES.getKey(),
            "key=\\uxxxx");
    modifyPropertySourceInEnvironment(overrideMap);

    try {//from w  ww  . j  a  va  2 s . c  o  m
        // When the XPath properties are not a valid format, an IllegalStateException should be thrown.
        defaultNotificationMessageBuilder.buildSystemMonitorResponse(getTestSystemMonitorIncomingMessage());
        fail();
    } catch (IllegalStateException e) {
        assertEquals(
                String.format("Unable to load XPath properties from configuration with key '%s'",
                        ConfigurationValue.HERD_NOTIFICATION_SQS_SYS_MONITOR_REQUEST_XPATH_PROPERTIES.getKey()),
                e.getMessage());
    } finally {
        // Restore the property sources so we don't affect other tests.
        restorePropertySourceInEnvironment();
    }
}

From source file:org.finra.dm.dao.S3DaoTest.java

/**
 * Test S3 file copy with an invalid KMS Id that throws an IllegalStateException because no AmazonServiceException was found.
 *//*from   w w w  .  j  a  v  a2  s.  co  m*/
@Test
public void testCopyFileInvalidKmsIdIllegalStateException() throws InterruptedException {
    try {
        S3FileCopyRequestParamsDto transferDto = new S3FileCopyRequestParamsDto();
        transferDto.setSourceBucketName(getS3LoadingDockBucketName());
        transferDto.setTargetBucketName(getS3ExternalBucketName());
        transferDto.setS3KeyPrefix("testKeyPrefix");
        transferDto.setKmsKeyId(MockS3OperationsImpl.MOCK_KMS_ID_FAILED_TRANSFER_NO_EXCEPTION);
        s3Dao.copyFile(transferDto);
        fail("An IllegalStateException was expected but not thrown.");
    } catch (IllegalStateException ex) {
        assertEquals(
                "Invalid IllegalStateException message returned.", "The transfer operation \""
                        + MockS3OperationsImpl.MOCK_TRANSFER_DESCRIPTION + "\" failed for an unknown reason.",
                ex.getMessage());
    }
}

From source file:org.finra.herd.service.helper.notification.BusinessObjectDefinitionDescriptionSuggestionChangeMessageBuilderTest.java

@Test
public void testBuildBusinessObjectDefinitionDescriptionSuggestionChangeMessagesInvalidMessageType()
        throws Exception {
    // Create a namespace entity.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(BDEF_NAMESPACE);

    // Create a business object definition description suggestion key.
    BusinessObjectDefinitionDescriptionSuggestionKey businessObjectDefinitionDescriptionSuggestionKey = new BusinessObjectDefinitionDescriptionSuggestionKey(
            BDEF_NAMESPACE, BDEF_NAME, USER_ID);

    // Create a business object definition description suggestion.
    BusinessObjectDefinitionDescriptionSuggestion businessObjectDefinitionDescriptionSuggestion = new BusinessObjectDefinitionDescriptionSuggestion(
            ID, businessObjectDefinitionDescriptionSuggestionKey, DESCRIPTION_SUGGESTION,
            BusinessObjectDefinitionDescriptionSuggestionStatusEntity.BusinessObjectDefinitionDescriptionSuggestionStatuses.PENDING
                    .name(),/*from  ww  w  . java2 s . c  om*/
            CREATED_BY, CREATED_ON);

    // Override configuration.
    ConfigurationEntity configurationEntity = new ConfigurationEntity();
    configurationEntity.setKey(
            ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_DEFINITION_DESCRIPTION_SUGGESTION_CHANGE_MESSAGE_DEFINITIONS
                    .getKey());
    configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions(
            Collections.singletonList(new NotificationMessageDefinition(INVALID_VALUE, MESSAGE_DESTINATION,
                    BUSINESS_OBJECT_DEFINITION_DESCRIPTION_SUGGESTION_CHANGE_NOTIFICATION_MESSAGE_VELOCITY_TEMPLATE,
                    NO_MESSAGE_HEADER_DEFINITIONS)))));
    configurationDao.saveAndRefresh(configurationEntity);

    // Try to build a notification message.
    try {
        businessObjectDefinitionDescriptionSuggestionChangeMessageBuilder.buildNotificationMessages(
                new BusinessObjectDefinitionDescriptionSuggestionChangeNotificationEvent(
                        businessObjectDefinitionDescriptionSuggestion, UPDATED_BY, UPDATED_ON,
                        namespaceEntity.getCode()));
        fail();
    } catch (IllegalStateException e) {
        assertEquals(String.format(
                "Only \"%s\" notification message type is supported. Please update \"%s\" configuration entry.",
                MESSAGE_TYPE_SNS,
                ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_DEFINITION_DESCRIPTION_SUGGESTION_CHANGE_MESSAGE_DEFINITIONS
                        .getKey()),
                e.getMessage());
    }
}

From source file:com.rakesh.d4ty.YTDownloadThread.java

boolean downloadone(String sURL) {
    boolean rc = false;
    boolean rc204 = false;
    boolean rc302 = false;

    this.iRecursionCount++;

    // stop recursion
    try {/* w  ww.j  a va2  s.  c  o  m*/
        if (sURL.equals(""))
            return (false);
    } catch (NullPointerException npe) {
        return (false);
    }
    if (JFCMainClient.getbQuitrequested())
        return (false); // try to get information about application shutdown

    debugoutput("start.");

    // TODO GUI option for proxy?
    // http://wiki.squid-cache.org/ConfigExamples/DynamicContent/YouTube
    // using local squid to save download time for tests

    try {
        // determine http_proxy environment variable
        if (!this.getProxy().equals("")) {

            String sproxy = JFCMainClient.sproxy.toLowerCase().replaceFirst("http://", "");
            this.proxy = new HttpHost(sproxy.replaceFirst(":(.*)", ""),
                    Integer.parseInt(sproxy.replaceFirst("(.*):", "")), "http");

            SchemeRegistry supportedSchemes = new SchemeRegistry();
            supportedSchemes.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
            supportedSchemes.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

            HttpParams params = new BasicHttpParams();
            HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
            HttpProtocolParams.setContentCharset(params, "UTF-8");
            HttpProtocolParams.setUseExpectContinue(params, true);

            ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, supportedSchemes);

            // with proxy
            this.httpclient = new DefaultHttpClient(ccm, params);
            this.httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, this.proxy);
            this.httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);
        } else {
            // without proxy
            this.httpclient = new DefaultHttpClient();
            this.httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);
        }
        this.httpget = new HttpGet(getURI(sURL));
        if (sURL.toLowerCase().startsWith("https"))
            this.target = new HttpHost(getHost(sURL), 443, "https");
        else
            this.target = new HttpHost(getHost(sURL), 80, "http");
    } catch (Exception e) {
        debugoutput(e.getMessage());
    }

    debugoutput("executing request: ".concat(this.httpget.getRequestLine().toString()));
    debugoutput("uri: ".concat(this.httpget.getURI().toString()));
    debugoutput("host: ".concat(this.target.getHostName()));
    debugoutput("using proxy: ".concat(this.getProxy()));

    // we dont need cookies at all because the download runs even without it (like my wget does) - in fact it blocks downloading videos from different webpages, because we do not handle the bcs for every URL (downloading of one video with different resolutions does work)
    /*
    this.localContext = new BasicHttpContext();
    if (this.bcs == null) this.bcs = new BasicCookieStore(); // make cookies persistent, otherwise they would be stored in a HttpContext but get lost after calling org.apache.http.impl.client.AbstractHttpClient.execute(HttpHost target, HttpRequest request, HttpContext context)
    ((DefaultHttpClient) httpclient).setCookieStore(this.bcs); // cast to AbstractHttpclient would be best match because DefaultHttpClass is a subclass of AbstractHttpClient
    */

    // TODO maybe we save the video IDs+res that were downloaded to avoid downloading the same video again?

    try {
        this.response = this.httpclient.execute(this.target, this.httpget, this.localContext);
    } catch (ClientProtocolException cpe) {
        debugoutput(cpe.getMessage());
    } catch (UnknownHostException uhe) {
        output((JFCMainClient.isgerman() ? "Fehler bei der Verbindung zu: " : "error connecting to: ")
                .concat(uhe.getMessage()));
        debugoutput(uhe.getMessage());
    } catch (IOException ioe) {
        debugoutput(ioe.getMessage());
    } catch (IllegalStateException ise) {
        debugoutput(ise.getMessage());
    }

    /*
    CookieOrigin cookieOrigin = (CookieOrigin) localContext.getAttribute( ClientContext.COOKIE_ORIGIN);
    CookieSpec cookieSpec = (CookieSpec) localContext.getAttribute( ClientContext.COOKIE_SPEC);
    CookieStore cookieStore = (CookieStore) localContext.getAttribute( ClientContext.COOKIE_STORE) ;
    try { debugoutput("HTTP Cookie store: ".concat( cookieStore.getCookies().toString( )));
    } catch (NullPointerException npe) {} // useless if we don't set our own CookieStore before calling httpclient.execute
    try {
       debugoutput("HTTP Cookie origin: ".concat(cookieOrigin.toString()));
       debugoutput("HTTP Cookie spec used: ".concat(cookieSpec.toString()));
       debugoutput("HTTP Cookie store (persistent): ".concat(this.bcs.getCookies().toString()));
    } catch (NullPointerException npe) {
    }
    */

    try {
        debugoutput("HTTP response status line:".concat(this.response.getStatusLine().toString()));
        //for (int i = 0; i < response.getAllHeaders().length; i++) {
        //   debugoutput(response.getAllHeaders()[i].getName().concat("=").concat(response.getAllHeaders()[i].getValue()));
        //}

        // abort if HTTP response code is != 200, != 302 and !=204 - wrong URL?
        if (!(rc = this.response.getStatusLine().toString().toLowerCase().matches("^(http)(.*)200(.*)"))
                & !(rc204 = this.response.getStatusLine().toString().toLowerCase()
                        .matches("^(http)(.*)204(.*)"))
                & !(rc302 = this.response.getStatusLine().toString().toLowerCase()
                        .matches("^(http)(.*)302(.*)"))) {
            debugoutput(this.response.getStatusLine().toString().concat(" ").concat(sURL));
            output(this.response.getStatusLine().toString().concat(" \"").concat(this.sTitle).concat("\""));
            return (rc & rc204 & rc302);
        }
        if (rc204) {
            debugoutput("last response code==204 - download: ".concat(this.sNextVideoURL.get(0)));
            rc = downloadone(this.sNextVideoURL.get(0));
            return (rc);
        }
        if (rc302)
            debugoutput(
                    "location from HTTP Header: ".concat(this.response.getFirstHeader("Location").toString()));

    } catch (NullPointerException npe) {
        // if an IllegalStateException was catched while calling httpclient.execute(httpget) a NPE is caught here because
        // response.getStatusLine() == null
        this.sVideoURL = null;
    }

    HttpEntity entity = null;
    try {
        entity = this.response.getEntity();
    } catch (NullPointerException npe) {
    }

    // try to read HTTP response body
    if (entity != null) {
        try {
            if (this.response.getFirstHeader("Content-Type").getValue().toLowerCase().matches("^text/html(.*)"))
                this.textreader = new BufferedReader(new InputStreamReader(entity.getContent()));
            else
                this.binaryreader = new BufferedInputStream(entity.getContent());
        } catch (IllegalStateException e1) {
            e1.printStackTrace();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        try {
            // test if we got a webpage
            this.sContentType = this.response.getFirstHeader("Content-Type").getValue().toLowerCase();
            if (this.sContentType.matches("^text/html(.*)")) {
                savetextdata();
                // test if we got the binary content
            } else if (this.sContentType.matches("video/(.)*")) {
                if (JFCMainClient.getbNODOWNLOAD())
                    reportheaderinfo();
                else
                    savebinarydata();
            } else { // content-type is not video/
                rc = false;
                this.sVideoURL = null;
            }
        } catch (IOException ex) {
            try {
                throw ex;
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (RuntimeException ex) {
            try {
                throw ex;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } //if (entity != null)

    this.httpclient.getConnectionManager().shutdown();

    debugoutput("done: ".concat(sURL));
    try {
        if (!this.sVideoURL.matches(JFCMainClient.szURLREGEX)) {
            debugoutput("cannot download video - URL does not seem to be valid: ".concat(this.sVideoURL));
            output(JFCMainClient.isgerman() ? "es gab ein Problem die Video URL zu finden!"
                    : "there was a problem getting the video URL!"); // deutsch
            output((JFCMainClient.isgerman() ? "erwge die URL dem Autor mitzuteilen!"
                    : "consider reporting the URL to author! - ").concat(this.sURL));
            rc = false;
        } else {
            debugoutput("try to download video from URL: ".concat(this.sVideoURL));
            rc = downloadone(this.sVideoURL);
        }
        this.sVideoURL = null;

    } catch (NullPointerException npe) {
    }

    return (rc);

}

From source file:org.awesomeapp.messenger.service.RemoteImService.java

private void shutdown() {
    Debug.recordTrail(this, SERVICE_DESTROY_TRAIL_TAG, new Date());

    HeartbeatService.stopBeating(getApplicationContext());

    Log.w(TAG, "ImService stopped.");
    for (ImConnectionAdapter conn : mConnections.values()) {

        if (conn.getState() == ImConnection.LOGGED_IN)
            conn.logout();//w w  w.ja v  a  2s . c o m

    }

    stopForeground(true);

    /* ignore unmount errors and quit ASAP. Threads actively using the VFS will
     * cause IOCipher's VirtualFileSystem.unmount() to throw an IllegalStateException */
    try {
        if (SecureMediaStore.isMounted())
            SecureMediaStore.unmount();
    } catch (IllegalStateException e) {
        Log.e(ImApp.LOG_TAG, "there was a problem unmoiunt secure media store: " + e.getMessage());
    }

    if (mCacheWord != null && (!mCacheWord.isLocked())) {
        mCacheWord.lock();
        mCacheWord.disconnectFromService();
    }

}

From source file:org.finra.herd.service.impl.UploadDownloadServiceImpl.java

/**
 * Asserts that the given target storage entity has valid attributes.
 *
 * @param targetStorageEntity Target storage entity.
 *//* w  ww . j  ava2  s . c o  m*/
private void assertTargetStorageEntityValid(StorageEntity targetStorageEntity) {
    try {
        // Assert that the target storage has a bucket name
        storageHelper.getStorageBucketName(targetStorageEntity);
    } catch (IllegalStateException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }

    try {
        // Assert that the target storage has a KMS key ID
        storageHelper.getStorageKmsKeyId(targetStorageEntity);
    } catch (IllegalStateException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}

From source file:org.finra.dm.dao.S3DaoTest.java

/**
 * Test S3 file copy with an invalid KMS Id that will result in a cancelled transfer.
 *///from   www . j  a v a2s.co m
@Test
public void testCopyFileInvalidKmsIdCancelled() throws InterruptedException {
    try {
        S3FileCopyRequestParamsDto transferDto = new S3FileCopyRequestParamsDto();
        transferDto.setSourceBucketName(getS3LoadingDockBucketName());
        transferDto.setTargetBucketName(getS3ExternalBucketName());
        transferDto.setS3KeyPrefix("testKeyPrefix");
        transferDto.setKmsKeyId(MockS3OperationsImpl.MOCK_KMS_ID_CANCELED_TRANSFER);
        s3Dao.copyFile(transferDto);
        fail("An IllegalStateException was expected but not thrown.");
    } catch (IllegalStateException ex) {
        assertEquals("Invalid IllegalStateException message returned.",
                "The transfer operation \"" + MockS3OperationsImpl.MOCK_TRANSFER_DESCRIPTION
                        + "\" did not complete successfully. " + "Current state: \""
                        + Transfer.TransferState.Canceled + "\".",
                ex.getMessage());
    }
}

From source file:com.ibm.tap.trails.framework.PropertiesLoaderSupport.java

/**
 * Load properties into the given instance.
 * // w  w  w  . j av  a2  s. com
 * @param props
 *            the Properties instance to load into
 * @throws java.io.IOException
 *             in case of I/O errors
 * @see #setLocations
 */
protected void loadProperties(Properties props) throws IOException {
    if (this.locations != null) {
        for (Resource location : this.locations) {
            if (logger.isInfoEnabled()) {
                logger.info("Loading properties file from " + location);
            }
            InputStream is = null;
            try {
                is = location.getInputStream();

                String filename = null;
                try {
                    filename = location.getFilename();
                } catch (IllegalStateException ex) {
                    // resource is not file-based. See SPR-7552.
                }

                if (filename != null && filename.endsWith(XML_FILE_EXTENSION)) {
                    this.propertiesPersister.loadFromXml(props, is);
                } else {
                    if (this.fileEncoding != null) {
                        this.propertiesPersister.load(props, new InputStreamReader(is, this.fileEncoding));
                    } else {
                        this.propertiesPersister.load(props, is);
                    }
                }
            } catch (IOException ex) {
                if (this.ignoreResourceNotFound) {
                    if (logger.isWarnEnabled()) {
                        logger.warn("Could not load properties from " + location + ": " + ex.getMessage());
                    }
                } else {
                    throw ex;
                }
            } finally {
                if (is != null) {
                    is.close();
                }
            }
        }
    }
}