org.eclipse.microprofile.rest.client.inject.RegisterRestClient Java Examples

The following examples show how to use org.eclipse.microprofile.rest.client.inject.RegisterRestClient. 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: ConfigFacade.java    From cxf with Apache License 2.0 7 votes vote down vote up
public static <T> Optional<T> getOptionalValue(String propertyNameFormat, Class<?> clientIntf, Class<T> clazz) {
    Optional<Config> c = config();
    if (c.isPresent()) {
        String propertyName = String.format(propertyNameFormat, clientIntf.getName());
        T value = c.get().getOptionalValue(propertyName, clazz).orElseGet(() -> {
            RegisterRestClient anno = clientIntf.getAnnotation(RegisterRestClient.class);
            if (anno != null && !StringUtils.isEmpty(anno.configKey())) {
                String configKeyPropName = String.format(propertyNameFormat, anno.configKey());
                return c.get().getOptionalValue(configKeyPropName, clazz).orElse(null);
            }
            return null;
        });
        return Optional.ofNullable(value);
    }

    return Optional.empty();
}
 
Example #2
Source File: ConfigFacade.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static <T> T getValue(String propertyNameFormat, Class<?> clientIntf, Class<T> clazz) {
    Optional<Config> c = config();
    T value = null;
    if (c.isPresent()) {
        String propertyName = String.format(propertyNameFormat, clientIntf.getName());
        value = c.get().getOptionalValue(propertyName, clazz).orElseGet(() -> {
            RegisterRestClient anno = clientIntf.getAnnotation(RegisterRestClient.class);
            if (anno != null && !StringUtils.isEmpty(anno.configKey())) {
                String configKeyPropName = String.format(propertyNameFormat, anno.configKey());
                return c.get().getValue(configKeyPropName, clazz);
            }
            return null;
        });
    }

    return value;
}
 
Example #3
Source File: ConfigFacade.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static OptionalLong getOptionalLong(String propNameFormat, Class<?> clientIntf) {
    Optional<Config> c = config();
    if (c.isPresent()) {
        String propertyName = String.format(propNameFormat, clientIntf.getName());
        Long value = c.get().getOptionalValue(propertyName, Long.class).orElseGet(() -> {
            RegisterRestClient anno = clientIntf.getAnnotation(RegisterRestClient.class);
            if (anno != null && !StringUtils.isEmpty(anno.configKey())) {
                String configKeyPropName = String.format(propNameFormat, anno.configKey());
                return c.get().getOptionalValue(configKeyPropName, Long.class).orElse(null);
            }
            return null;
        });
        return value == null ? OptionalLong.empty() : OptionalLong.of(value);
    }
    return OptionalLong.empty();
}
 
Example #4
Source File: RestClientBean.java    From cxf with Apache License 2.0 6 votes vote down vote up
private String getBaseUri() {
    String interfaceName = clientInterface.getName();
    String baseURI = ConfigFacade
        .getOptionalValue(REST_URI_FORMAT, clientInterface, String.class)
        .orElseGet(() -> ConfigFacade.getOptionalValue(REST_URL_FORMAT, clientInterface,
                                                       String.class).orElse(null));

    if (baseURI == null) {
        // last, if baseUrl/Uri is not specified via MP Config, check the @RegisterRestClient annotation
        RegisterRestClient anno = clientInterface.getAnnotation(RegisterRestClient.class);
        if (anno != null) {
            String annoUri = anno.baseUri();
            if (annoUri != null && !"".equals(anno.baseUri())) {
                baseURI = annoUri;
            }
        }
    }

    if (baseURI == null) {
        throw new IllegalStateException("Unable to determine base URI from configuration for "
                                        + interfaceName);
    }
    return baseURI;
}
 
Example #5
Source File: RestClientExtension.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void findClients(@Observes @WithAnnotations({RegisterRestClient.class}) ProcessAnnotatedType<?> pat) {
    Class<?> restClient = pat.getAnnotatedType().getJavaClass();
    if (restClient.isInterface()) {
        restClientClasses.add(restClient);
        pat.veto();
    } else {
        errors.add(new IllegalArgumentException("The class " + restClient
                + " is not an interface"));
    }
}
 
Example #6
Source File: TomEEOpenAPIExtension.java    From tomee with Apache License 2.0 5 votes vote down vote up
<T> void findEndpointsAndApplication(@Observes final ProcessBean<T> event) {
    final String typeName = event.getAnnotated().getBaseType().getTypeName();
    if (classes == null && !skipScan && event.getAnnotated().isAnnotationPresent(Path.class) &&
            !event.getAnnotated().isAnnotationPresent(RegisterRestClient.class) &&
            !typeName.startsWith("org.apache.geronimo.microprofile.openapi.") &&
            (packages == null || packages.stream().anyMatch(typeName::startsWith))) {
        endpoints.add(event.getBean());
    }
}