Search in sources :

Example 66 with ProcessingException

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();
}
Also used : StringReader(java.io.StringReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 67 with ProcessingException

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;
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 68 with ProcessingException

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);
}
Also used : StringContains.containsString(org.hamcrest.core.StringContains.containsString) ServiceTunnelResponse(org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelResponse) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) Test(org.junit.Test)

Example 69 with ProcessingException

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;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) RemoteFile(org.eclipse.scout.rt.shared.services.common.file.RemoteFile) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 70 with ProcessingException

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;
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) VetoException(org.eclipse.scout.rt.platform.exception.VetoException) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop) 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