Search in sources :

Example 6 with PlatformException

use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.

the class DefaultAuthToken method parse.

public boolean parse(String token) {
    if (!StringUtility.hasText(token)) {
        return false;
    }
    String[] parts = token.split(Pattern.quote("" + partsDelimiter()));
    if (parts == null || parts.length < 3) {
        return false;
    }
    try {
        String userId = new String(HexUtility.decode(parts[0]), StandardCharsets.UTF_8);
        long validUntil = Long.parseLong(parts[1], 16);
        String[] customArgs = null;
        if (parts.length > 3) {
            customArgs = Arrays.copyOfRange(parts, 2, parts.length - 1);
            for (int i = 0; i < customArgs.length; i++) {
                customArgs[i] = new String(HexUtility.decode(customArgs[i]), StandardCharsets.UTF_8);
            }
        }
        if (customArgs != null && customArgs.length == 0) {
            customArgs = null;
        }
        byte[] signature;
        try {
            // NOSONAR
            signature = HexUtility.decode(parts[parts.length - 1]);
        } catch (RuntimeException e) {
            LOG.debug("Could not decode hex string", e);
            signature = new byte[0];
        }
        m_userId = userId;
        m_validUntil = validUntil;
        m_customArgs = (customArgs == null ? null : Arrays.copyOf(customArgs, customArgs.length));
        m_signature = signature;
        return true;
    } catch (Exception ex) {
        throw new PlatformException("unexpected behaviour", ex);
    }
}
Also used : PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) IOException(java.io.IOException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException)

Example 7 with PlatformException

use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.

the class DefaultAuthToken method init.

/**
 * Init this auth-token with explicit values
 *
 * @param userId
 * @param customArgs
 */
public void init(String userId, String... customArgs) {
    long tokenTTL = CONFIG.getPropertyValue(AuthTokenTimeToLiveProperty.class);
    m_userId = userId;
    m_validUntil = System.currentTimeMillis() + tokenTTL;
    if (customArgs != null && customArgs.length == 0) {
        customArgs = null;
    }
    m_customArgs = (customArgs == null ? null : Arrays.copyOf(customArgs, customArgs.length));
    try {
        m_signature = sign();
    } catch (Exception e) {
        throw new PlatformException("Invalid signature setup", e);
    }
}
Also used : PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) IOException(java.io.IOException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException)

Example 8 with PlatformException

use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.

the class AbstractConfigProperty method read.

protected P_ParsedPropertyValueEntry<DATA_TYPE> read(String namespace) {
    DATA_TYPE parsedValue = null;
    PlatformException ex = null;
    try {
        RAW_TYPE value = readFromSource(namespace);
        if (value == null) {
            parsedValue = getDefaultValue();
        } else {
            parsedValue = parse(value);
        }
    } catch (PlatformException t) {
        ex = t;
    } catch (Exception e) {
        ex = new PlatformException(e.getMessage(), e);
    }
    fireConfigChangedEvent(new ConfigPropertyChangeEvent(this, null, parsedValue, namespace, ConfigPropertyChangeEvent.TYPE_VALUE_INITIALIZED));
    return new P_ParsedPropertyValueEntry<>(parsedValue, ex);
}
Also used : PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException)

Example 9 with PlatformException

use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.

the class HandlerDelegate method injectInitParams.

/**
 * Injects the given 'init-params' into the given handler.
 */
protected void injectInitParams(final Handler<CONTEXT> handler, final Map<String, String> initParams) {
    for (final Field field : handler.getClass().getDeclaredFields()) {
        if (field.getAnnotation(Resource.class) != null && field.getType().isAssignableFrom(initParams.getClass())) {
            try {
                LOG.info("Inject 'initParams' to JAX-WS handler [path={}#{}]", handler.getClass().getName(), field.getName());
                field.setAccessible(true);
                field.set(handler, initParams);
                return;
            } catch (final ReflectiveOperationException e) {
                throw new PlatformException("Failed to inject 'InitParams' for handler '{}'", handler.getClass().getName(), e);
            }
        }
    }
    if (!initParams.isEmpty()) {
        LOG.warn("'InitParams' could not be injected into handler because no field found that is of type Map<String, String> and annotated with @Resource [handler={}, initParams={}]", handler.getClass().getName(), initParams);
    }
}
Also used : Field(java.lang.reflect.Field) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException)

Example 10 with PlatformException

use of org.eclipse.scout.rt.platform.exception.PlatformException in project scout.rt by eclipse.

the class JaxWsRISpecifics method getVersionInfo.

@Override
public String getVersionInfo() {
    try {
        final Class<?> versionClass = Class.forName("com.sun.xml.internal.ws.util.RuntimeVersion");
        final String version = versionClass.getDeclaredField("VERSION").get(null).toString();
        return String.format("%s (http://jax-ws.java.net, %s, bundled with JRE)", version, versionClass.getPackage().getImplementationVendor());
    } catch (final ClassNotFoundException e) {
        // NOSONAR
        throw new PlatformException("Application configured to run with JAX-WS RI (bundled with JRE), but implementor could not be found on classpath.");
    } catch (final ReflectiveOperationException e) {
        LOG.warn("Failed to read version information of JAX-WS implementor", e);
        return "JAX-WS RI bundled with JRE";
    }
}
Also used : PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException)

Aggregations

PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)35 Test (org.junit.Test)13 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)9 IOException (java.io.IOException)8 FileInputStream (java.io.FileInputStream)4 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)4 VetoException (org.eclipse.scout.rt.platform.exception.VetoException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStream (java.io.InputStream)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 TestLookupCall (org.eclipse.scout.rt.client.ui.form.fields.smartfield.fixture.TestLookupCall)3 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)3 ILookupCall (org.eclipse.scout.rt.shared.services.lookup.ILookupCall)3 File (java.io.File)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 BeanMetaData (org.eclipse.scout.rt.platform.BeanMetaData)2