use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.
the class UploadRequestHandler method handleUploadFileRequest.
protected void handleUploadFileRequest(IUiSession uiSession, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String targetAdapterId) throws IOException, FileUploadException {
// If client sent ACK#, cleanup response history accordingly
uiSession.confirmResponseProcessed(getAckSequenceNo(httpServletRequest));
IBinaryResourceConsumer binaryResourceConsumer = resolveJsonAdapter(uiSession, targetAdapterId);
if (binaryResourceConsumer == null) {
// Request was already processed and adapter does not exist anymore
return;
}
if (httpServletRequest.getParameter("legacy") != null) {
httpServletResponse.setContentType("text/plain");
}
// Read uploaded data
Map<String, String> uploadProperties = new HashMap<String, String>();
List<BinaryResource> uploadResources = new ArrayList<>();
try {
readUploadData(httpServletRequest, binaryResourceConsumer.getMaximumBinaryResourceUploadSize(), uploadProperties, uploadResources);
} catch (PlatformException ex) {
// NOSONAR
writeJsonResponse(httpServletResponse, m_jsonRequestHelper.createUnsafeUploadResponse());
return;
}
// GUI requests for the same session must be processed consecutively
final ReentrantLock uiSessionLock = uiSession.uiSessionLock();
uiSessionLock.lock();
try {
if (uiSession.isDisposed()) {
writeJsonResponse(httpServletResponse, m_jsonRequestHelper.createSessionTimeoutResponse());
return;
}
JSONObject jsonResp = uiSession.processFileUpload(httpServletRequest, httpServletResponse, binaryResourceConsumer, uploadResources, uploadProperties);
if (jsonResp == null) {
jsonResp = m_jsonRequestHelper.createEmptyResponse();
}
writeJsonResponse(httpServletResponse, jsonResp);
} finally {
uiSessionLock.unlock();
}
}
use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.
the class RunContextExceptionTranslationTest method test.
@Test
public void test() {
final Exception error = new Exception("expected JUnit test exception");
IRunnable runnableWithError = new IRunnable() {
@Override
public void run() throws Exception {
throw error;
}
};
// Test with DefaultRuntimeExceptionTranslator
try {
RunContexts.empty().run(runnableWithError);
fail();
} catch (PlatformException e) {
assertSame(error, e.getCause());
}
// Test with DefaultRuntimeExceptionTranslator
try {
RunContexts.empty().run(runnableWithError, DefaultRuntimeExceptionTranslator.class);
fail();
} catch (PlatformException e) {
assertSame(error, e.getCause());
}
// Test with DefaultExceptionTranslator
try {
RunContexts.empty().run(runnableWithError, DefaultExceptionTranslator.class);
fail();
} catch (RuntimeException e) {
fail();
} catch (Exception e) {
assertSame(error, e);
}
// Test with PlatformExceptionTranslator
try {
RunContexts.empty().run(runnableWithError, PlatformExceptionTranslator.class);
fail();
} catch (PlatformException e) {
assertSame(error, e.getCause());
}
}
use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.
the class PlatformImplementorTest method testAwaitPlatformStartedFailsInPlatformStopping.
@Test
public void testAwaitPlatformStartedFailsInPlatformStopping() throws Exception {
final CountDownLatch stoppingLatch = new CountDownLatch(1);
final CountDownLatch continueStoppingLatch = new CountDownLatch(1);
// crate platform listener that signals stopping state
BeanMetaData bean = new BeanMetaData(IPlatformListener.class).withApplicationScoped(true).withInitialInstance(new IPlatformListener() {
@Override
public void stateChanged(PlatformEvent event) {
if (event.getState() == State.PlatformStopping) {
stoppingLatch.countDown();
try {
continueStoppingLatch.await();
} catch (InterruptedException e) {
// nop
}
}
}
});
final TestingPlatformImplementor platform = new TestingPlatformImplementor(bean);
platform.start();
// expect platform started
platform.awaitPlatformStarted();
Future<?> platformStopFuture = s_executor.submit(new Runnable() {
@Override
public void run() {
platform.stop();
}
});
stoppingLatch.await();
try {
platform.awaitPlatformStarted();
} catch (PlatformException e) {
assertEquals("The platform is stopping.", e.getMessage());
}
continueStoppingLatch.countDown();
platformStopFuture.get();
}
use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.
the class JandexInventoryBuilder method readIndex.
/**
* @param indexUri
* @return index or null
*/
protected Index readIndex(URI indexUri, InputStream in) {
try {
Index index = new IndexReader(in).read();
LOG.debug("Found pre-built {}", indexUri);
return index;
} catch (Exception ex) {
throw new PlatformException("Error reading index '{}'", indexUri, ex);
}
}
use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.
the class JaxWsPlatformListener method installImplementorSpecifics.
protected void installImplementorSpecifics(final IBeanManager beanManager) {
final String jaxwsImplementor = CONFIG.getPropertyValue(JaxWsImplementorProperty.class);
if (jaxwsImplementor == null) {
return;
}
try {
final Class<?> jaxwsImplementorClazz = Class.forName(jaxwsImplementor);
Assertions.assertTrue(JaxWsImplementorSpecifics.class.isAssignableFrom(jaxwsImplementorClazz), "Implementor class must be of type '{}'.", JaxWsImplementorSpecifics.class.getName());
// Unregister the Bean first, so it can be registered with @Replace annotation anew.
beanManager.unregisterClass(jaxwsImplementorClazz);
beanManager.registerBean(new BeanMetaData(jaxwsImplementorClazz).withReplace(true));
LOG.info("JAX-WS implementor specific class installed: {}", jaxwsImplementorClazz.getName());
} catch (final ClassNotFoundException e) {
throw new PlatformException("Configured JAX-WS implementor specific class", e);
}
}
Aggregations