private ConcurrentMap<LinkKey, Link_1_0<S,T>> getLinkRegistry(final Role role) { ConcurrentMap<LinkKey, Link_1_0<S,T>> linkRegistry; if (Role.SENDER == role) { linkRegistry = _sendingLinkRegistry; } else if (Role.RECEIVER == role) { linkRegistry = _receivingLinkRegistry; } else { throw new ServerScopedRuntimeException(String.format("Unsupported link role %s", role)); } return linkRegistry; }
throw new ServerScopedRuntimeException(e); throw new ServerScopedRuntimeException(cause); throw new ServerScopedRuntimeException(e);
throw new ServerScopedRuntimeException(e); throw new ServerScopedRuntimeException(cause); throw new ServerScopedRuntimeException(e);
public static byte[] getMD5(byte[] data) { MessageDigest md = null; try { md = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new ServerScopedRuntimeException("MD5 not supported although Java compliance requires it"); } for (byte b : data) { md.update(b); } return md.digest(); }
break; default: throw new ServerScopedRuntimeException(String.format( "Unexpected jms message type annotation %s", jmsMessageTypeAnnotation));
@Override protected String createStoredPassword(final String password) { byte[] data = password.getBytes(StandardCharsets.UTF_8); MessageDigest md = null; try { md = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new ServerScopedRuntimeException("MD5 not supported although Java compliance requires it"); } md.update(data); return Base64.getEncoder().encodeToString(md.digest()); }
public static String getInstalledProtocolsAsString() { Set<Protocol> installedProtocols = getInstalledProtocols(); ObjectMapper mapper = new ObjectMapper(); try(StringWriter output = new StringWriter()) { mapper.writeValue(output, installedProtocols); return output.toString(); } catch (IOException e) { throw new ServerScopedRuntimeException(e); } }
private synchronized void update() { if (_groupFile != null) { try { writeGroupFile(_groupFile); } catch (IOException e) { throw new ServerScopedRuntimeException("Unable to persist change to file " + _groupFile,e); } } }
throw new ServerScopedRuntimeException(exceptionMessage, e); throw new ServerScopedRuntimeException(exceptionMessage, e); throw new ServerScopedRuntimeException(exceptionMessage, e); throw new ServerScopedRuntimeException(exceptionMessage, e);
throw new ServerScopedRuntimeException(exceptionMessage, e); throw new ServerScopedRuntimeException(exceptionMessage, e); throw new ServerScopedRuntimeException(exceptionMessage, e); throw new ServerScopedRuntimeException(exceptionMessage, e);
private Class<? extends ConfiguredObject> calculateBestFitInterface() { Set<Class<? extends ConfiguredObject>> candidates = new HashSet<Class<? extends ConfiguredObject>>(); findBestFitInterface(getClass(), candidates); switch(candidates.size()) { case 0: throw new ServerScopedRuntimeException("The configured object class " + getClass().getSimpleName() + " does not seem to implement an interface"); case 1: return candidates.iterator().next(); default: ArrayList<Class<? extends ConfiguredObject>> list = new ArrayList<>(candidates); throw new ServerScopedRuntimeException("The configured object class " + getClass().getSimpleName() + " implements no single common interface which extends ConfiguredObject" + " Identified candidates were : " + Arrays.toString(list.toArray())); } }
private <X extends ConfiguredObject> void processDerivedAttribute(final Class<X> clazz, final SortedSet<ConfiguredObjectAttribute<?, ?>> attributeSet, final Method m) { DerivedAttribute annotation = m.getAnnotation(DerivedAttribute.class); if (!clazz.isInterface() || !ConfiguredObject.class.isAssignableFrom(clazz)) { throw new ServerScopedRuntimeException("Can only define DerivedAttributes on interfaces which extend " + ConfiguredObject.class.getSimpleName() + ". " + clazz.getSimpleName() + " does not meet these criteria."); } ConfiguredObjectAttribute<?, ?> attribute = new ConfiguredDerivedMethodAttribute<>(clazz, m, annotation); if (attributeSet.contains(attribute)) { attributeSet.remove(attribute); } attributeSet.add(attribute); }
private <X extends ConfiguredObject> void processManagedAttribute(final Class<X> clazz, final SortedSet<ConfiguredObjectAttribute<?, ?>> attributeSet, final Method m) { ManagedAttribute annotation = m.getAnnotation(ManagedAttribute.class); if (!clazz.isInterface() || !ConfiguredObject.class.isAssignableFrom(clazz)) { throw new ServerScopedRuntimeException("Can only define ManagedAttributes on interfaces which extend " + ConfiguredObject.class.getSimpleName() + ". " + clazz.getSimpleName() + " does not meet these criteria."); } ConfiguredObjectAttribute<?, ?> attribute = new ConfiguredAutomatedAttribute<>(clazz, m, annotation); if (attributeSet.contains(attribute)) { attributeSet.remove(attribute); } attributeSet.add(attribute); }
private static Class getRawType(Type t) { if(t instanceof Class) { return (Class)t; } else if(t instanceof ParameterizedType) { return (Class)((ParameterizedType)t).getRawType(); } else if(t instanceof TypeVariable) { Type[] bounds = ((TypeVariable)t).getBounds(); if(bounds.length == 1) { return getRawType(bounds[0]); } } throw new ServerScopedRuntimeException("Unable to process type when constructing configuration model: " + t); }
private <X extends ConfiguredObject> void processManagedStatistic(final Class<X> clazz, final SortedSet<ConfiguredObjectStatistic<?, ?>> statisticSet, final Method m) { ManagedStatistic statAnnotation = m.getAnnotation(ManagedStatistic.class); if (!clazz.isInterface() || !ConfiguredObject.class.isAssignableFrom(clazz)) { throw new ServerScopedRuntimeException("Can only define ManagedStatistics on interfaces which extend " + ConfiguredObject.class.getSimpleName() + ". " + clazz.getSimpleName() + " does not meet these criteria."); } ConfiguredObjectStatistic statistic = new ConfiguredObjectMethodStatistic(clazz, m, statAnnotation); if (statisticSet.contains(statistic)) { statisticSet.remove(statistic); } statisticSet.add(statistic); }
public static String buildRequestQuery(final Map<String, String> requestBodyParameters) { try { final String charset = StandardCharsets.UTF_8.name(); StringBuilder bodyBuilder = new StringBuilder(); Iterator<Map.Entry<String, String>> iterator = requestBodyParameters.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, String> entry = iterator.next(); bodyBuilder.append(URLEncoder.encode(entry.getKey(), charset)); bodyBuilder.append("="); bodyBuilder.append(URLEncoder.encode(entry.getValue(), charset)); if (iterator.hasNext()) { bodyBuilder.append("&"); } } return bodyBuilder.toString(); } catch (UnsupportedEncodingException e) { throw new ServerScopedRuntimeException("Failed to encode as UTF-8", e); } }
private <C extends Pluggable> Iterable<C> instancesOf(Class<C> clazz, boolean atLeastOne) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Iterator<C> serviceLoaderIterator = ServiceLoader.load(clazz, classLoader).iterator(); // create a new list so we can log the count List<C> serviceImplementations = new ArrayList<C>(); while(serviceLoaderIterator.hasNext()) { C next = serviceLoaderIterator.next(); if(!isDisabled(clazz, next) && isAvailable(next)) { serviceImplementations.add(next); } } if(atLeastOne && serviceImplementations.isEmpty()) { throw new ServerScopedRuntimeException("At least one implementation of " + clazz + " expected"); } LOGGER.debug("Found {} implementations of {}", serviceImplementations.size(), clazz); return serviceImplementations; }
HashedUser(String[] data, AuthenticationProvider<?> authenticationProvider) { if (data.length != 2) { throw new IllegalArgumentException("User Data should be length 2, username, password"); } _name = data[0]; byte[] encoded_password; try { encoded_password = data[1].getBytes(Base64MD5PasswordFilePrincipalDatabase.DEFAULT_ENCODING); } catch (UnsupportedEncodingException e) { throw new ServerScopedRuntimeException("MD5 encoding not supported, even though the Java standard requires it",e); } _encodedPassword = encoded_password; byte[] decoded = Strings.decodeBase64(data[1]); _password = new char[decoded.length]; int index = 0; for (byte c : decoded) { _password[index++] = (char) c; } _authenticationProvider = authenticationProvider; }
throw new ServerScopedRuntimeException(e.getCause());