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();
}
});
}
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();
}
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;
}
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());
}
}
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);
}
}
Aggregations