List of usage examples for com.google.common.base VerifyException VerifyException
public VerifyException(@Nullable String message, @Nullable Throwable cause)
From source file:google.registry.keyring.api.DummyKeyringModule.java
/** Always returns a {@link InMemoryKeyring} instance. */ @Provides// w w w . ja v a2s.com static Keyring provideKeyring() { PGPKeyPair dummyKey; try (InputStream publicInput = PGP_PUBLIC_KEYRING.openStream(); InputStream privateInput = PGP_PRIVATE_KEYRING.openStream()) { PGPPublicKeyRingCollection publicKeys = new BcPGPPublicKeyRingCollection( PGPUtil.getDecoderStream(publicInput)); PGPSecretKeyRingCollection privateKeys = new BcPGPSecretKeyRingCollection( PGPUtil.getDecoderStream(privateInput)); dummyKey = lookupKeyPair(publicKeys, privateKeys, EMAIL_ADDRESS, ENCRYPT_SIGN); } catch (PGPException | IOException e) { throw new VerifyException("Failed to load PGP keys from jar", e); } // Use the same dummy PGP keypair for all required PGP keys -- a real production system would // have different values for these keys. Pass dummy values for all Strings. return new InMemoryKeyring(dummyKey, dummyKey, dummyKey.getPublicKey(), dummyKey, dummyKey.getPublicKey(), "not a real key", "not a real key", "not a real password", "not a real login", "not a real password", "not a real login", "not a real credential", "not a real key"); }
From source file:google.registry.request.RequestModule.java
@Provides @JsonPayload/*from ww w . j a v a 2 s.co m*/ @SuppressWarnings("unchecked") static Map<String, Object> provideJsonPayload(@Header("Content-Type") MediaType contentType, @Payload String payload) { if (!JSON_UTF_8.is(contentType.withCharset(UTF_8))) { throw new UnsupportedMediaTypeException( String.format("Expected %s Content-Type", JSON_UTF_8.withoutParameters())); } try { return (Map<String, Object>) JSONValue.parseWithException(payload); } catch (ParseException e) { throw new BadRequestException("Malformed JSON", new VerifyException("Malformed JSON:\n" + payload, e)); } }
From source file:org.lenskit.eval.traintest.metrics.MetricLoaderHelper.java
/** * Look up the class implementing a metric by name. * @param name The metric name./* w ww .j a v a 2s . c om*/ * @return The metric class. */ @Nullable public Class<?> findClass(String name) { if (propFiles.containsKey(name.toLowerCase())) { String className = (String) propFiles.get(name.toLowerCase()); logger.debug("resolving metric {} to class {}", name, className); try { return ClassUtils.getClass(loader, className); } catch (ClassNotFoundException e) { throw new VerifyException("class " + className + " not found", e); } } else { try { logger.debug("trying to look up metric {} as class", name); return ClassUtils.getClass(loader, name); } catch (ClassNotFoundException e) { logger.debug("no metric {} found", name); return null; } } }
From source file:org.lenskit.eval.traintest.metrics.MetricLoaderHelper.java
@Nullable public <T> T createMetric(Class<T> type, JsonNode node) { ObjectMapper mapper = new ObjectMapper(); String typeName = getMetricTypeName(node); if (typeName == null) { return null; }/*from w w w . ja v a 2 s . co m*/ if (!node.isObject()) { node = JsonNodeFactory.instance.objectNode().set("type", node); } Class<?> metric = findClass(typeName); if (metric == null) { logger.warn("could not find metric {} for ", typeName, type); return null; } for (Constructor<?> ctor : metric.getConstructors()) { if (ctor.getAnnotation(JsonCreator.class) != null) { return type.cast(mapper.convertValue(node, metric)); } } // ok, just instantiate try { return type.cast(metric.newInstance()); } catch (InstantiationException | IllegalAccessException e) { throw new VerifyException("Cannot instantiate " + metric, e); } }