use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class HexUtility method decode.
/**
* Decodes the supplied Hex encoded string.
*
* @param hex
* The Hex encoded string that is to be decoded.
* @return A <code>byte[]</code> containing the decoded data block.
*/
public static byte[] decode(String hex) {
if (hex == null) {
return null;
}
int length = hex.length();
if (length == 0) {
return new byte[0];
}
ByteArrayOutputStream out = new ByteArrayOutputStream(length / 2);
try (HexInputStream h = new HexInputStream(new StringReader(hex))) {
int b;
while ((b = h.read()) >= 0) {
out.write(b);
}
out.close();
} catch (IOException e) {
throw new ProcessingException("Unexpected behaviour", e);
}
return out.toByteArray();
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class ServiceOperationInvoker method interceptException.
/**
* Method invoked to intercept a service exception before being put into the {@link ServiceTunnelResponse} to be sent
* to the client. This method must not throw an exception.
* <p>
* <p>
* Security: do not send back original error and stack trace with implementation details.
* <p>
* The default implementation returns an empty exception, or in case of a {@link VetoException} only its title,
* message, htmlMessage, error code and severity.
*/
protected Throwable interceptException(Throwable t) {
Throwable p;
if (t instanceof VetoException) {
VetoException ve = (VetoException) t;
p = new VetoException(ve.getStatus().getBody()).withTitle(ve.getStatus().getTitle()).withHtmlMessage(ve.getHtmlMessage()).withCode(ve.getStatus().getCode()).withSeverity(ve.getStatus().getSeverity());
} else {
p = new ProcessingException(TEXTS.get("RequestProblem"));
}
p.setStackTrace(new StackTraceElement[0]);
return p;
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class ServiceOperationInvokerTest method testInvokeInvalidWithoutSession.
// exception is handled with JUnitExceptionHandler
@Test(expected = ProcessingException.class)
public void testInvokeInvalidWithoutSession() {
String exceptionMessage = "xxx";
when(m_pingSvc.ping(any(String.class))).thenThrow(new ProcessingException(exceptionMessage));
ServiceTunnelResponse res = invokePingService(ServerRunContexts.empty());
assertProcessingException(res, exceptionMessage);
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class FileService method getFiles.
private String[][] getFiles(String folderBase, FilenameFilter filter, boolean useServerFolderStructureOnClient) {
File path = getFileLocation(useServerFolderStructureOnClient ? folderBase : "", null, false);
String[] dirs = path.list(filter);
if (dirs == null || dirs.length < 1) {
return new String[][] {};
}
List<String> dirList = new ArrayList<String>();
List<String> fileList = new ArrayList<String>();
for (int i = 0; i < dirs.length; i++) {
try {
File file = new File(path.getCanonicalPath() + "/" + dirs[i]);
if (file.isDirectory()) {
String[][] tmp = getFiles((folderBase == null ? dirs[i] : folderBase + "/" + dirs[i]), filter, true);
for (String[] f : tmp) {
dirList.add(f[0]);
fileList.add(f[1]);
}
} else {
dirList.add(folderBase);
fileList.add(dirs[i]);
}
} catch (IOException e) {
throw new ProcessingException("FileService.getFiles:", e);
}
}
String[][] retVal = new String[dirList.size()][2];
for (int i = 0; i < dirList.size(); i++) {
retVal[i][0] = dirList.get(i);
retVal[i][1] = fileList.get(i);
}
return retVal;
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class AbstractForm method startInternal.
/**
* This method is called from the implemented handler methods in a explicit form subclass
*/
protected IForm startInternal(final IFormHandler handler) {
ClientRunContexts.copyCurrent().withForm(this).run(new IRunnable() {
@Override
public void run() throws Exception {
if (isBlockingInternal()) {
throw new IllegalStateException("The form " + getFormId() + " has already been started");
}
// Ensure that boolean is set not only once by the constructor
setFormLoading(true);
setHandler(handler);
m_closeType = IButton.SYSTEM_TYPE_NONE;
m_blockingCondition.setBlocking(true);
try {
initForm();
loadStateInternal();
// if form was disposed during initForm() or loadStateInternal()
if (!isBlockingInternal()) {
return;
}
if (getHandler().isGuiLess()) {
// make sure the form is storing since it is not showing
storeStateInternal();
markSaved();
doFinally();
disposeFormInternal();
return;
}
} catch (RuntimeException | PlatformError e) {
disposeFormInternal();
PlatformException pe = BEANS.get(PlatformExceptionTranslator.class).translate(e).withContextInfo("form", AbstractForm.this.getClass().getName());
if (pe instanceof VetoException) {
VetoException ve = (VetoException) pe;
interceptOnVetoException(ve, ve.getStatus().getCode());
}
throw pe;
}
setButtonsArmed(true);
setCloseTimerArmed(true);
setFormStarted(true);
// Notify the UI to display this form.
if (isShowOnStart()) {
IDesktop desktop = getDesktop();
if (desktop == null || !desktop.isOpened()) {
throw new ProcessingException("There is no desktop or it is not open in the UI.");
} else {
desktop.showForm(AbstractForm.this);
}
}
}
});
return this;
}
Aggregations