Search in sources :

Example 11 with StringPayloadCacheTranslator

use of com.adaptris.core.services.cache.translators.StringPayloadCacheTranslator in project interlok by adaptris.

the class GetValueFromCacheTest method testDoService_NotFoundWithError.

@Test
public void testDoService_NotFoundWithError() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("Hello World");
    Cache cache = createCacheInstanceForTests();
    GetValueFromCache service = new GetValueFromCache().withExceptionIfNotFound(false).withValueTranslator(new StringPayloadCacheTranslator()).withKey("%message{%uniqueId}").withConnection(new CacheConnection().withCacheInstance(cache));
    try {
        start(service);
        service.doService(msg);
        assertNotEquals("Hello World", msg.getContent());
    } catch (ServiceException expected) {
    } finally {
        stop(service);
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) StringPayloadCacheTranslator(com.adaptris.core.services.cache.translators.StringPayloadCacheTranslator) Cache(com.adaptris.core.cache.Cache) Test(org.junit.Test)

Example 12 with StringPayloadCacheTranslator

use of com.adaptris.core.services.cache.translators.StringPayloadCacheTranslator in project interlok by adaptris.

the class BasicCacheExampleGenerator method createAddToCacheService.

public static AddToCacheService createAddToCacheService() {
    AddToCacheService service = new AddToCacheService();
    CacheEntryEvaluator eval1 = new CacheEntryEvaluator();
    CacheEntryEvaluator eval2 = new CacheEntryEvaluator();
    CacheEntryEvaluator eval3 = new CacheEntryEvaluator();
    CacheEntryEvaluator eval4 = new CacheEntryEvaluator();
    CacheEntryEvaluator eval5 = new CacheEntryEvaluator();
    eval1.setKeyTranslator(new MetadataCacheValueTranslator("A_MetadataKey_Whose_Value_Makes_The_Cache_Key"));
    eval1.setValueTranslator(new MetadataCacheValueTranslator("Another_MetadataKey_Whose_Value_Makes_The_Cache_CacheValue"));
    eval2.setKeyTranslator(new MetadataCacheValueTranslator("A_MetadataKey_Whose_Value_Makes_The_Cache_Key"));
    eval2.setValueTranslator(new StringPayloadCacheTranslator());
    eval3.setKeyTranslator(new MetadataCacheValueTranslator("A_MetadataKey_Whose_Value_Makes_The_Cache_Key"));
    eval3.setValueTranslator(new XpathCacheValueTranslator("/some/xpath/value"));
    eval4.setKeyTranslator(new MetadataCacheValueTranslator("JMSCorrelationID"));
    eval4.setValueTranslator(new JmsReplyToCacheValueTranslator());
    eval5.setKeyTranslator(new MetadataCacheValueTranslator("A_MetadataKey_Whose_Value_Makes_The_Cache_Key"));
    eval5.setValueTranslator(new ObjectMetadataCacheValueTranslator(JmsConstants.OBJ_JMS_REPLY_TO_KEY));
    service.setCacheEntryEvaluators(new ArrayList(Arrays.asList(new CacheEntryEvaluator[] { eval1, eval2, eval3, eval4, eval5 })));
    return service;
}
Also used : ObjectMetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.ObjectMetadataCacheValueTranslator) MetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator) XpathCacheValueTranslator(com.adaptris.core.services.cache.translators.XpathCacheValueTranslator) JmsReplyToCacheValueTranslator(com.adaptris.core.services.cache.translators.JmsReplyToCacheValueTranslator) ArrayList(java.util.ArrayList) CacheEntryEvaluator(com.adaptris.core.services.cache.CacheEntryEvaluator) StringPayloadCacheTranslator(com.adaptris.core.services.cache.translators.StringPayloadCacheTranslator) AddToCacheService(com.adaptris.core.services.cache.AddToCacheService) ObjectMetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.ObjectMetadataCacheValueTranslator)

Aggregations

StringPayloadCacheTranslator (com.adaptris.core.services.cache.translators.StringPayloadCacheTranslator)12 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)10 Test (org.junit.Test)10 ExpiringMapCache (com.adaptris.core.cache.ExpiringMapCache)7 Cache (com.adaptris.core.cache.Cache)5 MyCacheEventListener (com.adaptris.core.cache.MyCacheEventListener)5 ServiceException (com.adaptris.core.ServiceException)3 CacheEntryEvaluator (com.adaptris.core.services.cache.CacheEntryEvaluator)2 JmsReplyToCacheValueTranslator (com.adaptris.core.services.cache.translators.JmsReplyToCacheValueTranslator)2 MetadataCacheValueTranslator (com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator)2 ObjectMetadataCacheValueTranslator (com.adaptris.core.services.cache.translators.ObjectMetadataCacheValueTranslator)2 TimeInterval (com.adaptris.util.TimeInterval)2 ArrayList (java.util.ArrayList)2 AddToCacheService (com.adaptris.core.services.cache.AddToCacheService)1 XpathCacheValueTranslator (com.adaptris.core.services.cache.translators.XpathCacheValueTranslator)1 DefectiveMessageFactory (com.adaptris.core.stubs.DefectiveMessageFactory)1 Date (java.util.Date)1