Search in sources :

Example 76 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class AddToCacheService method doService.

@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
    try {
        Cache cache = retrieveCache();
        for (CacheEntryEvaluator ceg : getCacheEntryEvaluators()) {
            String key = ceg.getKey(msg);
            Object value = ceg.getValue(msg);
            if (key == null || value == null) {
                log.warn("{} generated null values for either the key or value, not storing in cache", ceg.friendlyName());
                continue;
            }
            if (enforceSerializable() && !(value instanceof Serializable)) {
                throw new ServiceException("Cache value " + value + " should be Serializable, but is of type " + value.getClass());
            }
            cache.put(key, value);
        }
    } catch (Exception e) {
        throw ExceptionHelper.wrapServiceException(e);
    }
}
Also used : Serializable(java.io.Serializable) ServiceException(com.adaptris.core.ServiceException) ServiceException(com.adaptris.core.ServiceException) Cache(com.adaptris.core.cache.Cache)

Example 77 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class AddValueToCache method doService.

@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
    try {
        Cache cache = retrieveCache();
        Optional<Expiry> hasExpiry = buildExpiry(msg);
        String cacheKey = msg.resolve(getKey());
        // should be hasExpiry.ifPresentOrElse() once we goto J11...
        if (hasExpiry.isPresent()) {
            TimeInterval expiryInterval = hasExpiry.get().expiresIn();
            log.trace("[{}] will expire in {}", cacheKey, expiryInterval);
            cache.put(cacheKey, getValueTranslator().getValueFromMessage(msg), hasExpiry.get().expiresIn());
        } else {
            log.trace("Expiry for [{}] taken from cache settings", cacheKey);
            cache.put(cacheKey, getValueTranslator().getValueFromMessage(msg));
        }
    } catch (Exception e) {
        throw ExceptionHelper.wrapServiceException(e);
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) CacheExpiry(com.adaptris.core.cache.CacheExpiry) Expiry(com.adaptris.core.cache.CacheExpiry.Expiry) ServiceException(com.adaptris.core.ServiceException) UnresolvedMetadataException(com.adaptris.core.UnresolvedMetadataException) Cache(com.adaptris.core.cache.Cache)

Example 78 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class GetValueFromCache method doService.

@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
    try {
        Cache cache = retrieveCache();
        String key = msg.resolve(getKey());
        Object value = cache.get(key);
        if (value != null || !exceptionIfNotFound()) {
            getValueTranslator().addValueToMessage(msg, value);
        } else {
            throw new ServiceException(String.format("%s not found in cache", key));
        }
    } catch (Exception e) {
        throw ExceptionHelper.wrapServiceException(e);
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) ServiceException(com.adaptris.core.ServiceException) Cache(com.adaptris.core.cache.Cache)

Example 79 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class RemoveFromCacheService method doService.

/**
 * Retrieves the item from the cache, stores it against the message and then removes it from the cache
 *
 * @see com.adaptris.core.services.cache.RetrieveFromCacheService#doService(com.adaptris.core.AdaptrisMessage)
 */
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
    try {
        Cache cache = retrieveCache();
        for (CacheEntryEvaluator ceg : getCacheEntryEvaluators()) {
            String key = ceg.getKey(msg);
            if (isEmpty(key)) {
                log.warn("{} generated null values for the key, nothing to do", ceg.friendlyName());
                continue;
            }
            addCacheValueToMessage(msg, key, ceg.valueTranslator(), !exceptionIfNotFound());
            cache.remove(key);
        }
    } catch (Exception e) {
        throw ExceptionHelper.wrapServiceException(e);
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) Cache(com.adaptris.core.cache.Cache)

Example 80 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class RemoveKeyFromCache method doService.

@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
    try {
        Cache cache = retrieveCache();
        cache.remove(msg.resolve(getKey()));
    } catch (Exception e) {
        throw ExceptionHelper.wrapServiceException(e);
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) Cache(com.adaptris.core.cache.Cache)

Aggregations

ServiceException (com.adaptris.core.ServiceException)236 Test (org.junit.Test)172 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)161 CoreException (com.adaptris.core.CoreException)45 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)26 StandaloneProducer (com.adaptris.core.StandaloneProducer)18 MetadataElement (com.adaptris.core.MetadataElement)17 ValidationStage (com.adaptris.transform.validate.ValidationStage)16 Cache (com.adaptris.core.cache.Cache)15 DefectiveMessageFactory (com.adaptris.core.stubs.DefectiveMessageFactory)13 TimeInterval (com.adaptris.util.TimeInterval)13 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)11 Connection (java.sql.Connection)10 File (java.io.File)9 IOException (java.io.IOException)9 OutputStream (java.io.OutputStream)9 SQLException (java.sql.SQLException)9 InputStream (java.io.InputStream)8 Document (org.w3c.dom.Document)8 Channel (com.adaptris.core.Channel)7