use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.
the class SmartFieldLookupTest method testTextLookupWithExceptions.
@SuppressWarnings("unchecked")
@Test(expected = PlatformException.class)
public void testTextLookupWithExceptions() {
m_field.setLookupCall(new TestLookupCall());
when(m_mock_service.getDataByText(any(ILookupCall.class))).thenThrow(new PlatformException("lookup error"));
m_field.callTextLookup("test", 10);
}
use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.
the class SmartFieldLookupTest method testTextLookupExceptions_InBackground.
@SuppressWarnings("unchecked")
@Test
public void testTextLookupExceptions_InBackground() throws InterruptedException {
m_field.setLookupCall(new TestLookupCall());
final String errorText = "lookup error";
when(m_mock_service.getDataByText(any(ILookupCall.class))).thenThrow(new PlatformException(errorText));
final IBlockingCondition bc = Jobs.newBlockingCondition(true);
ILookupRowFetchedCallback callback = new ILookupRowFetchedCallback<Long>() {
@Override
public void onSuccess(List<? extends ILookupRow<Long>> rows) {
Assert.fail("no exception thrown");
bc.setBlocking(false);
}
@Override
public void onFailure(RuntimeException exception) {
assertTrue(exception instanceof PlatformException);
assertEquals(errorText, exception.getMessage());
bc.setBlocking(false);
}
};
m_field.callTextLookupInBackground("", 10, callback);
bc.waitFor();
}
use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.
the class SmartFieldLookupTest method testSubtreeLookupExceptions_InBackground.
@SuppressWarnings("unchecked")
@Test
public void testSubtreeLookupExceptions_InBackground() throws InterruptedException {
final IBlockingCondition bc = Jobs.newBlockingCondition(true);
m_field.setLookupCall(new TestLookupCall());
when(m_mock_service.getDataByRec(any(ILookupCall.class))).thenThrow(new PlatformException("lookup error"));
IFuture<List<ILookupRow<Long>>> rows = m_field.callSubTreeLookupInBackground(1L, TriState.TRUE, false);
rows.whenDone(new IDoneHandler<List<ILookupRow<Long>>>() {
@Override
public void onDone(DoneEvent<List<ILookupRow<Long>>> event) {
assertTrue(event.getException() instanceof RuntimeException);
assertEquals("lookup error", event.getException().getMessage());
bc.setBlocking(false);
}
}, ClientRunContexts.copyCurrent());
bc.waitFor();
}
use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.
the class JmsMomImplementor method createDefaultMarshaller.
@SuppressWarnings("unchecked")
protected IMarshaller createDefaultMarshaller(final Map<Object, Object> properties) {
Object prop = properties.get(MARSHALLER);
if (prop instanceof IMarshaller) {
return (IMarshaller) prop;
} else {
Class<? extends IMarshaller> marshallerClass;
String marshallerClassName = ObjectUtility.toString(prop);
if (marshallerClassName != null) {
try {
marshallerClass = (Class<? extends IMarshaller>) Class.forName(marshallerClassName);
} catch (final ClassNotFoundException | ClassCastException e) {
throw new PlatformException("Failed to load class specified by environment property '{}' [value={}]", MARSHALLER, marshallerClassName, e);
}
} else {
marshallerClass = CONFIG.getPropertyValue(DefaultMarshallerProperty.class);
}
return BEANS.get(marshallerClass);
}
}
use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.
the class MalwareScanner method scan.
/**
* This {@link MalwareScanner} copies the resource to be scanned into the TEMP folder, reads it back in and verifies
* the equality of the two streams.
* <p>
* Override this {@link Bean} in order to implement another scanning strategy.
*
* @throws PlatformException
* if the resource is valid and the scanner did not find any issues
*/
public void scan(BinaryResource res) {
if (res == null) {
return;
}
File f = null;
try {
byte[] expected = res.getContent();
if (expected == null || expected.length == 0) {
return;
}
f = IOUtility.createTempFile("malware-scan", ".tmp", expected);
byte[] actual;
try (FileInputStream in = new FileInputStream(f)) {
actual = IOUtility.readBytes(in, expected.length);
}
if (!Arrays.equals(expected, actual)) {
throwUnsafeResource(res);
}
} catch (Exception e) {
// NOSONAR each on-site malware scanner may behave differently, e.g. StreamCorruptedException, FileNotFoundException, ...
throwUnsafeResource(res);
} finally {
IOUtility.deleteFile(f);
}
}
Aggregations