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);
}
}
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);
}
}
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);
}
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);
}
}
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";
}
}
Aggregations