io.micronaut.core.convert.value.ConvertibleValues Java Examples

The following examples show how to use io.micronaut.core.convert.value.ConvertibleValues. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EC2ServiceInstance.java    From micronaut-aws with Apache License 2.0 6 votes vote down vote up
/**
 * Container to hold AWS EC2 Instance info.
 * @param id if of the instance
 * @param uri uri to access this instance
 */
public EC2ServiceInstance(String id, URI uri) {
    this.id = id;

    String userInfo = uri.getUserInfo();
    if (StringUtils.isNotEmpty(userInfo)) {
        try {
            this.uri = new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment());
            this.metadata = ConvertibleValues.of(Collections.singletonMap(
                HttpHeaders.AUTHORIZATION_INFO, userInfo
            ));
        } catch (URISyntaxException e) {
            throw new IllegalStateException("ServiceInstance URI is invalid: " + e.getMessage(), e);
        }
    } else {
        this.uri = uri;
    }
}
 
Example #2
Source File: GrpcServerInstance.java    From micronaut-grpc with Apache License 2.0 6 votes vote down vote up
/**
 * Default constructor.
 * @param embeddedServer The embedded server
 * @param id The ID
 * @param uri The URI
 * @param metadata The metadata
 * @param metadataContributors The metadata contributors
 */
GrpcServerInstance(
        EmbeddedServer embeddedServer,
        String id,
        URI uri,
        @Nullable Map<String, String> metadata,
        @javax.annotation.Nullable List<ServiceInstanceMetadataContributor> metadataContributors) {
    this.embeddedServer = embeddedServer;
    this.id = id;
    this.uri = uri;
    if (metadata == null) {
        metadata = new LinkedHashMap<>(5);
    }

    if (CollectionUtils.isNotEmpty(metadataContributors)) {
        for (ServiceInstanceMetadataContributor contributor : metadataContributors) {
            contributor.contribute(this, metadata);
        }
    }

    this.metadata = ConvertibleValues.of(metadata);
}
 
Example #3
Source File: GrpcServerInstance.java    From micronaut-grpc with Apache License 2.0 6 votes vote down vote up
/**
 * Default constructor.
 * @param embeddedServer The embedded server
 * @param id The ID
 * @param uri The URI
 * @param metadata The metadata
 * @param metadataContributors The metadata contributors
 */
GrpcServerInstance(
        EmbeddedServer embeddedServer,
        String id,
        URI uri,
        @Nullable Map<String, String> metadata,
        @javax.annotation.Nullable List<ServiceInstanceMetadataContributor> metadataContributors) {
    this.embeddedServer = embeddedServer;
    this.id = id;
    this.uri = uri;
    if (metadata == null) {
        metadata = new LinkedHashMap<>(5);
    }

    if (CollectionUtils.isNotEmpty(metadataContributors)) {
        for (ServiceInstanceMetadataContributor contributor : metadataContributors) {
            contributor.contribute(this, metadata);
        }
    }

    this.metadata = ConvertibleValues.of(metadata);
}
 
Example #4
Source File: GoogleFunctionHttpRequest.java    From micronaut-gcp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public <T> Optional<T> getBody(@Nonnull Argument<T> arg) {
    if (arg != null) {
        final Class<T> type = arg.getType();
        final MediaType contentType = getContentType().orElse(MediaType.APPLICATION_JSON_TYPE);
        if (body == null) {

            if (isFormSubmission(contentType)) {
                body = getParameters();
                if (ConvertibleValues.class == type) {
                    return (Optional<T>) Optional.of(body);
                } else {
                    return Optional.empty();
                }
            } else {

                final MediaTypeCodec codec = codecRegistry.findCodec(contentType, type).orElse(null);
                if (codec != null) {
                    try (InputStream inputStream = googleRequest.getInputStream()) {
                        if (ConvertibleValues.class == type) {
                            final Map map = codec.decode(Map.class, inputStream);
                            body = ConvertibleValues.of(map);
                            return (Optional<T>) Optional.of(body);
                        } else {
                            final T value = codec.decode(arg, inputStream);
                            body = value;
                            return Optional.ofNullable(value);
                        }
                    } catch (IOException e) {
                        throw new CodecException("Error decoding request body: " + e.getMessage(), e);
                    }

                }
            }
        } else {
            if (type.isInstance(body)) {
                return (Optional<T>) Optional.of(body);
            } else {
                if (body != httpParameters) {
                    final T result = ConversionService.SHARED.convertRequired(body, arg);
                    return Optional.ofNullable(result);
                }
            }

        }
    }
    return Optional.empty();
}
 
Example #5
Source File: EC2ServiceInstance.java    From micronaut-aws with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the metadata information gathered from AWS for this instance.
 * @return The metadata
 */
@Override
public ConvertibleValues<String> getMetadata() {
    return metadata;
}
 
Example #6
Source File: GrpcServerInstance.java    From micronaut-grpc with Apache License 2.0 4 votes vote down vote up
@Override
public ConvertibleValues<String> getMetadata() {
    return metadata;
}
 
Example #7
Source File: GrpcServerInstance.java    From micronaut-grpc with Apache License 2.0 4 votes vote down vote up
@Override
public ConvertibleValues<String> getMetadata() {
    return metadata;
}