Search in sources :

Example 26 with ProcessingException

use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.

the class AbstractWizard method start.

@Override
public void start() {
    assertClosed();
    if (m_blockingCondition.isBlocking()) {
        throw new ProcessingException("The wizard " + getClass().getSimpleName() + " has already been started");
    }
    m_blockingCondition.setBlocking(true);
    setClosedInternal(false);
    setCloseTypeInternal(CloseType.Unknown);
    // Run the initialization on behalf of this Form.
    runWithinContainerForm(new IRunnable() {

        @Override
        public void run() throws Exception {
            interceptStart();
            if (m_containerForm.isFormStartable()) {
                m_containerForm.startWizard();
            }
            interceptPostStart();
        }
    });
}
Also used : IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 27 with ProcessingException

use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.

the class UriBuilder method getQueryString.

private String getQueryString(String encoding) {
    Assertions.assertNotNull(encoding);
    if (m_parameters.isEmpty()) {
        return null;
    }
    StringBuilder query = new StringBuilder();
    for (Map.Entry<String, String> param : m_parameters.entrySet()) {
        if (!StringUtility.hasText(param.getKey())) {
            LOG.warn("ignoring parameter with empty key");
            continue;
        }
        if (query.length() > 0) {
            query.append("&");
        }
        try {
            query.append(URLEncoder.encode(param.getKey(), encoding));
            query.append("=");
            query.append(URLEncoder.encode(param.getValue(), encoding));
        } catch (UnsupportedEncodingException e) {
            throw new ProcessingException("Unsupported encoding '" + encoding + "'", e);
        }
    }
    return query.toString();
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) Map(java.util.Map) HashMap(java.util.HashMap) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 28 with ProcessingException

use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.

the class UriUtility method getQueryParameters.

/**
 * Parses the given URI's query string using the given encoding and extracts the query parameter.
 *
 * @param uri
 * @param encoding
 *          encoding of the query parameter. If <code>null</code> UTF-8 is used.
 * @return map with parsed query parameters. Never <code>null</code>.
 */
public static Map<String, String> getQueryParameters(URI uri, String encoding) {
    if (uri == null || uri.getQuery() == null) {
        return new HashMap<>(0);
    }
    if (encoding == null) {
        encoding = DEFAULT_ENCODING;
    }
    String[] params = getQueryString(uri).split("&");
    Map<String, String> result = new HashMap<>(params.length);
    for (String param : params) {
        String[] parts = StringUtility.split(param, "=");
        if (parts.length != 2) {
            throw new ProcessingException("invalid query parameter: '" + param + "'");
        }
        try {
            String key = URLDecoder.decode(parts[0], encoding);
            String value = URLDecoder.decode(parts[1], encoding);
            String existingMapping = result.put(key, value);
            if (existingMapping != null) {
                LOG.warn("parameter key is used multiple times [key='{}', oldValue='{}', newValue='{}'", key, existingMapping, value);
            }
        } catch (UnsupportedEncodingException e) {
            throw new ProcessingException("unsupported encoding '" + encoding + "'", e);
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 29 with ProcessingException

use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.

the class CsvHelperTest method testExceptionInDataConsumer.

@Test
public void testExceptionInDataConsumer() throws Exception {
    Object[][] data = new Object[][] { { "a", "a", 123.34, "a", "a" }, { "b", "b", 123.34, "b", "b" }, { "d", "d", 123.34, "d", "d" } };
    export(data);
    IDataConsumer dataConsumer = mock(IDataConsumer.class);
    ProcessingException pe = new ProcessingException();
    // Throw an exception in the 2nd line
    doThrow(pe).when(dataConsumer).processRow(eq(2), ArgumentMatchers.anyList());
    try (Reader reader = new FileReader(m_testFile)) {
        m_csvHelper.importData(dataConsumer, reader, true, true, 1);
        fail("No exception was thrown! Expected ProcessingException");
    } catch (ProcessingException e) {
        Set<String> contextInfos = CollectionUtility.hashSet(e.getContextInfos());
        assertTrue(contextInfos.remove("lineNr=2"));
        String fullMessage = e.getDisplayMessage() + " " + Arrays.asList(e.getStackTrace());
        assertEquals("expected a single context message: " + contextInfos + " full Exception Message : " + fullMessage, 0, contextInfos.size());
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) BomInputStreamReader(org.eclipse.scout.rt.platform.util.BomInputStreamReader) Reader(java.io.Reader) FileReader(java.io.FileReader) FileReader(java.io.FileReader) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) Test(org.junit.Test)

Example 30 with ProcessingException

use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.

the class DefaultValuesFilterService method loadFilter.

protected synchronized void loadFilter() {
    try {
        // Build a list of default values configs
        List<URL> urls = getDefaultValuesConfigurationUrls();
        long newestModified = 0;
        List<JSONObject> defaultValuesConfigurations = new ArrayList<JSONObject>();
        for (URL url : urls) {
            URLConnection conn = url.openConnection();
            long lastModified = conn.getLastModified();
            if (lastModified > newestModified) {
                newestModified = lastModified;
            }
            String jsonData;
            try (InputStream in = conn.getInputStream()) {
                jsonData = IOUtility.readStringUTF8(in);
            }
            jsonData = JsonUtility.stripCommentsFromJson(jsonData);
            JSONObject json = new JSONObject(jsonData);
            defaultValuesConfigurations.add(json);
        }
        m_lastModified = newestModified;
        // Combine configs into "defaults" and "objectTypeHierarchy"
        JSONObject combinedDefaultValuesConfiguration = new JSONObject();
        for (JSONObject defaultValuesConfiguration : defaultValuesConfigurations) {
            JsonObjectUtility.mergeProperties(combinedDefaultValuesConfiguration, defaultValuesConfiguration);
        }
        // Build combined string (suitable to send to UI)
        m_combinedDefaultValuesConfiguration = JsonObjectUtility.toString(combinedDefaultValuesConfiguration);
        // Build filter
        DefaultValuesFilter filter = BEANS.get(DefaultValuesFilter.class);
        filter.importConfiguration(combinedDefaultValuesConfiguration);
        m_filter = filter;
    } catch (Exception e) {
        throw new ProcessingException("Unexpected error while initializing default values filter", e);
    }
}
Also used : JSONObject(org.json.JSONObject) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) URL(java.net.URL) URLConnection(java.net.URLConnection) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Aggregations

ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)142 IOException (java.io.IOException)48 MessagingException (javax.mail.MessagingException)21 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)17 File (java.io.File)14 VetoException (org.eclipse.scout.rt.platform.exception.VetoException)12 Folder (javax.mail.Folder)10 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)9 RemoteFile (org.eclipse.scout.rt.shared.services.common.file.RemoteFile)9 NoSuchProviderException (java.security.NoSuchProviderException)8 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)8 FileInputStream (java.io.FileInputStream)7 InputStream (java.io.InputStream)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 FileOutputStream (java.io.FileOutputStream)6 Message (javax.mail.Message)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 OutputStream (java.io.OutputStream)5 HashMap (java.util.HashMap)5