use of org.mule.runtime.core.internal.transformer.ResolverException in project mule by mulesoft.
the class GraphTransformerResolver method resolve.
@Override
public Transformer resolve(DataType source, DataType result) throws ResolverException {
String cacheKey = getDataTypeSourceResultPairHash(source, result);
readWriteLock.readLock().lock();
try {
if (cache.containsKey(cacheKey)) {
return (Converter) cache.get(cacheKey);
}
} finally {
readWriteLock.readLock().unlock();
}
List<Converter> converters = converterFilter.filter(lookupStrategyTransformation.lookupConverters(source, result), source, result);
if (converters.size() > 1) {
throw new ResolverException(CoreMessages.transformHasMultipleMatches(source.getType(), result.getType(), converters));
}
Transformer converter = (converters.size() == 0) ? null : converters.get(0);
readWriteLock.writeLock().lock();
try {
cache.put(cacheKey, converter);
} finally {
readWriteLock.writeLock().unlock();
}
return converter;
}
use of org.mule.runtime.core.internal.transformer.ResolverException in project mule by mulesoft.
the class ExceptionHelperTestCase method getNonMuleExceptionCause.
@Test
public void getNonMuleExceptionCause() {
assertThat(getNonMuleException(new ResolverException(failedToBuildMessage(), null)), nullValue());
assertThat(getNonMuleException(new ResolverException(failedToBuildMessage(), new ConfigurationException(failedToBuildMessage(), null))), nullValue());
assertThat(getNonMuleException(new ResolverException(failedToBuildMessage(), new ConfigurationException(failedToBuildMessage(), new IllegalArgumentException()))), instanceOf(IllegalArgumentException.class));
assertThat(getNonMuleException(new ResolverException(failedToBuildMessage(), new ConfigurationException(failedToBuildMessage(), new IllegalArgumentException(new NullPointerException())))), instanceOf(IllegalArgumentException.class));
assertThat(getNonMuleException(new IllegalArgumentException()), instanceOf(IllegalArgumentException.class));
}
use of org.mule.runtime.core.internal.transformer.ResolverException in project mule by mulesoft.
the class TypeBasedTransformerResolver method resolve.
public Transformer resolve(DataType source, DataType result) throws ResolverException {
Transformer transformer = exactTransformerCache.get(source.toString() + result.toString());
if (transformer != null) {
return transformer;
}
MuleRegistry registry = ((MuleContextWithRegistries) muleContext).getRegistry();
List<Transformer> trans = registry.lookupTransformers(source, result);
Transformer compositeTransformer = graphTransformerResolver.resolve(source, result);
if (compositeTransformer != null) {
// Needs to create a new list because the lookup returns a cached instance
trans = new LinkedList<>(trans);
trans.add(compositeTransformer);
}
transformer = getNearestTransformerMatch(trans, source.getType(), result.getType());
// If an exact mach is not found, we have a 'second pass' transformer that can be used to converting to String or
// byte[]
Transformer secondPass;
if (transformer == null) {
// using Object.class and then convert to String or byte[] using the second pass transformer
if (String.class.equals(result.getType())) {
secondPass = objectToString;
} else if (byte[].class.equals(result.getType())) {
secondPass = objectToByteArray;
} else {
return null;
}
// Perform a more general search
trans = registry.lookupTransformers(source, DataType.OBJECT);
transformer = getNearestTransformerMatch(trans, source.getType(), result.getType());
if (transformer != null) {
transformer = new TransformerChain(transformer, secondPass);
try {
registry.registerTransformer(transformer);
} catch (MuleException e) {
throw new ResolverException(e.getI18nMessage(), e);
}
}
}
if (transformer != null) {
exactTransformerCache.put(source.toString() + result.toString(), transformer);
}
return transformer;
}
use of org.mule.runtime.core.internal.transformer.ResolverException in project mule by mulesoft.
the class MuleRegistryHelper method resolveTransformer.
protected Transformer resolveTransformer(DataType source, DataType result) throws TransformerException {
Lock readLock = transformerResolversLock.readLock();
readLock.lock();
try {
for (TransformerResolver resolver : transformerResolvers) {
try {
Transformer trans = resolver.resolve(source, result);
if (trans != null) {
return trans;
}
} catch (ResolverException e) {
throw new TransformerException(CoreMessages.noTransformerFoundForMessage(source, result), e);
}
}
} finally {
readLock.unlock();
}
return null;
}
Aggregations