private void setPrivateKey(final KeyStore keystore, final PrivateKey privateKey, final Certificate... certs) { try { keystore.setKeyEntry("key", privateKey, new char[0], certs); } catch (final KeyStoreException e) { throw fatalError("Engine failed to configure client key") .cause(e) .build(); } }
@Override protected PolicyTooLargeException newInvalidSizeException(final long maxSize, final long actualSize, final DittoHeaders headers) { return PolicyTooLargeException.newBuilder(actualSize, maxSize).dittoHeaders(headers).build(); }
static DittoRuntimeException attributesNotFound(final String thingId, final DittoHeaders dittoHeaders) { return AttributesNotAccessibleException.newBuilder(thingId) .dittoHeaders(dittoHeaders) .build(); }
@Override protected MessagePayloadSizeTooLargeException newInvalidSizeException(final long maxSize, final long actualSize, final DittoHeaders headers) { return MessagePayloadSizeTooLargeException.newBuilder(actualSize, maxSize).dittoHeaders(headers).build(); }
private static void validateAddress(final String address, final boolean wildcardAllowed, final DittoHeaders dittoHeaders) { validateMqttTopic(address, wildcardAllowed, errorMessage -> { final String message = MessageFormat.format(INVALID_TOPIC_FORMAT, address, errorMessage); return ConnectionConfigurationInvalidException.newBuilder(message) .dittoHeaders(dittoHeaders) .build(); }); }
@Override public Thing setAccessControlList(final AccessControlList accessControlList) { if (policyId != null) { throw AclInvalidException.newBuilder(thingId) .description("Could not set v1 ACL to Thing already containing v2 Policy") .build(); } else if (Objects.equals(acl, accessControlList)) { return this; } return new ImmutableThing(thingId, accessControlList, null, attributes, features, lifecycle, revision, modified); }
private static void ensureThingIdPresence(final Thing newThing, final DittoHeaders dittoHeaders) { if (!newThing.getId().isPresent()) { throw ThingIdInvalidException.newBuilder("") .message("Thing ID must be present in 'CreateThing' payload") .dittoHeaders(dittoHeaders) .build(); } }
private KeyStore newKeystore() { try { return TrustManagerFactory.emptyKeyStore(); } catch (final Exception e) { throw fatalError("Cannot initialize client-side security for connection") .cause(e) .build(); } }
private static JsonPointer checkAttributePointer(final JsonPointer pointer, final DittoHeaders dittoHeaders) { checkNotNull(pointer, "key of the attribute to be modified"); if (pointer.isEmpty()) { throw AttributePointerInvalidException.newBuilder(pointer) .dittoHeaders(dittoHeaders) .build(); } return pointer; }
@Override protected DittoRuntimeException fallback(final ThingCommand command) { return ThingNotModifiableException.newBuilder(command.getThingId()) .dittoHeaders(command.getDittoHeaders()) .build(); }
@Nonnull @Override public ThingErrorResponse featuresNotAccessibleError() { return errorResponse(command.getThingId(), FeaturesNotAccessibleException.newBuilder(command.getThingId()) .dittoHeaders(command.getDittoHeaders()) .build()); } }
@Nonnull @Override public ThingErrorResponse featuresNotAccessibleError() { return errorResponse(command.getThingId(), FeaturesNotAccessibleException.newBuilder(command.getThingId()) .dittoHeaders(command.getDittoHeaders()) .build()); }
@Nonnull @Override public ThingErrorResponse thingNotAccessibleError() { return errorResponse(command.getThingId(), ThingNotAccessibleException.newBuilder(command.getThingId()) .dittoHeaders(command.getDittoHeaders()) .build()); }
@Nonnull @Override public ThingErrorResponse attributesNotAccessibleError() { final DittoRuntimeException exception = AttributesNotAccessibleException.newBuilder(command.getThingId()) .dittoHeaders(command.getDittoHeaders()) .build(); return errorResponse(command.getThingId(), exception); }
@Nonnull @Override public ThingErrorResponse attributesNotModifiableError() { final DittoRuntimeException exception = AttributesNotModifiableException.newBuilder(command.getThingId()) .dittoHeaders(command.getDittoHeaders()) .build(); return errorResponse(command.getThingId(), exception); } }
@Nonnull @Override public ThingErrorResponse featurePropertiesNotModifiableError() { return errorResponse(command.getThingId(), FeaturePropertiesNotModifiableException.newBuilder(command.getThingId(), command.getFeatureId()) .dittoHeaders(command.getDittoHeaders()) .build()); } }
@Nonnull @Override public ThingErrorResponse featureNotModifiableError() { return errorResponse(command.getThingId(), FeatureNotModifiableException.newBuilder(command.getThingId(), command.getFeatureId()) .dittoHeaders(command.getDittoHeaders()) .build()); } }
private static FeaturePropertiesNotAccessibleException commandToFeaturePropertiesException( final ThingCommand command) { return FeaturePropertiesNotAccessibleException.newBuilder(command.getThingId(), ((WithFeatureId) command).getFeatureId()) .dittoHeaders(command.getDittoHeaders()) .build(); }
@Nonnull @Override public ThingErrorResponse featurePropertiesNotModifiableError() { return errorResponse(command.getThingId(), FeaturePropertiesNotModifiableException.newBuilder(command.getThingId(), command.getFeatureId()) .dittoHeaders(command.getDittoHeaders()) .build()); } }
@Nonnull @Override public ThingErrorResponse featureDefinitionNotAccessibleError() { return errorResponse(command.getThingId(), FeatureDefinitionNotAccessibleException.newBuilder(command.getThingId(), command.getFeatureId()) .dittoHeaders(command.getDittoHeaders()) .build()); }