Search in sources :

Example 16 with ValueResolver

use of org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver in project mule by mulesoft.

the class OAuthConnectionProviderObjectBuilder method getCustomParameters.

private Map<String, String> getCustomParameters(CoreEvent event) {
    Map<String, String> oauthParams = new HashMap<>();
    withCustomParameters((parameter, property) -> {
        String alias = property.getRequestAlias();
        if (StringUtils.isBlank(alias)) {
            alias = parameter.getName();
        }
        ValueResolver resolver = resolverSet.getResolvers().get(alias);
        if (resolver != null) {
            try {
                oauthParams.put(alias, resolveString(event, resolver));
            } catch (MuleException e) {
                throw new MuleRuntimeException(e);
            }
        }
    });
    return oauthParams;
}
Also used : HashMap(java.util.HashMap) MapValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.MapValueResolver) ValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleException(org.mule.runtime.api.exception.MuleException)

Example 17 with ValueResolver

use of org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver in project mule by mulesoft.

the class OAuthConnectionProviderObjectBuilder method staticOnly.

private MapValueResolver staticOnly(MapValueResolver resolver) throws MuleException {
    List<ValueResolver> staticKeyResolvers = new ArrayList<>(resolver.getKeyResolvers().size());
    List<ValueResolver> staticValueResolvers = new ArrayList<>(resolver.getValueResolvers().size());
    Iterator<ValueResolver> keyResolvers = resolver.getKeyResolvers().iterator();
    Iterator<ValueResolver> valueResolvers = resolver.getValueResolvers().iterator();
    while (keyResolvers.hasNext() && valueResolvers.hasNext()) {
        ValueResolver keyResolver = keyResolvers.next();
        ValueResolver valueResolver = valueResolvers.next();
        if (!keyResolver.isDynamic() && !valueResolver.isDynamic()) {
            staticKeyResolvers.add(keyResolver);
            staticValueResolvers.add(valueResolver);
        }
    }
    MapValueResolver result = new MapValueResolver(HashMap.class, staticKeyResolvers, staticValueResolvers, getReflectionCache(), muleContext);
    initialiseIfNeeded(result, muleContext);
    return result;
}
Also used : MapValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.MapValueResolver) ValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver) MapValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.MapValueResolver) ArrayList(java.util.ArrayList)

Example 18 with ValueResolver

use of org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver in project mule by mulesoft.

the class SourceAdapter method getNonCallbackParameterValue.

private <T> Optional<T> getNonCallbackParameterValue(String fieldName, Class<T> type) {
    ValueResolver<T> valueResolver = (ValueResolver<T>) nonCallbackParameters.getResolvers().get(fieldName);
    if (valueResolver == null) {
        return empty();
    }
    T object;
    CoreEvent initialiserEvent = null;
    try {
        initialiserEvent = getInitialiserEvent(muleContext);
        object = valueResolver.resolve(from(initialiserEvent));
    } catch (MuleException e) {
        throw new MuleRuntimeException(createStaticMessage("Unable to get the " + type.getSimpleName() + " value for Message Source"), e);
    } finally {
        if (initialiserEvent != null) {
            ((BaseEventContext) initialiserEvent.getContext()).success();
        }
    }
    if (!(type.isInstance(object))) {
        throw new IllegalStateException("The resolved value is not a " + type.getSimpleName());
    }
    return of(object);
}
Also used : BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleException(org.mule.runtime.api.exception.MuleException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException)

Aggregations

ValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver)18 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)6 StaticValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.StaticValueResolver)6 HashMap (java.util.HashMap)5 MuleException (org.mule.runtime.api.exception.MuleException)5 ExpressionBasedParameterResolverValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionBasedParameterResolverValueResolver)4 ExpressionTypedValueValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionTypedValueValueResolver)4 NativeQueryParameterValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.NativeQueryParameterValueResolver)4 ProcessorChainValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ProcessorChainValueResolver)4 StaticLiteralValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.StaticLiteralValueResolver)4 TypeSafeExpressionValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.TypeSafeExpressionValueResolver)4 Map (java.util.Map)3 Optional (java.util.Optional)3 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)3 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)3 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)2