@Test public void testDoService_WithError() throws Exception { AdaptrisMessage msg = new DefectiveMessageFactory(EnumSet.of(WhenToBreak.METADATA_GET)).newMessage("Hello World"); msg.addMetadata("metadataKey", "value"); Cache cache = createCacheInstanceForTests(); AddValueToCache service = new AddValueToCache().withValueTranslator(new StringPayloadCacheTranslator()) .withKey("%message{metadataKey}").withConnection(new CacheConnection().withCacheInstance(cache)); try { start(service); service.doService(msg); fail(); } catch (ServiceException expected) { } finally { stop(service); } }
@Override public void doService(AdaptrisMessage msg) throws ServiceException { try { Cache cache = retrieveCache(); Optional<Expiry> hasExpiry = buildExpiry(msg); String cacheKey = msg.resolve(getKey()); 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); } }
AddValueToCache extends SingleKeyValueCacheImpl { @Override public void doService(AdaptrisMessage msg) throws ServiceException { try { Cache cache = retrieveCache(); Optional<Expiry> hasExpiry = buildExpiry(msg); String cacheKey = msg.resolve(getKey()); 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); } } }
AddValueToCache extends SingleKeyValueCacheImpl { @Override public void doService(AdaptrisMessage msg) throws ServiceException { try { Cache cache = retrieveCache(); Optional<Expiry> hasExpiry = buildExpiry(msg); String cacheKey = msg.resolve(getKey()); 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); } }  }
AddValueToCache extends SingleKeyValueCacheImpl { @Override public void doService(AdaptrisMessage msg) throws ServiceException { try { Cache cache = retrieveCache(); Optional<Expiry> hasExpiry = buildExpiry(msg); String cacheKey = msg.resolve(getKey()); 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); } }  @Override void doService(AdaptrisMessage msg); T withExpiry(String s); String getExpiry(); void setExpiry(String s); }
AddValueToCache extends SingleKeyValueCacheImpl { @Override public void doService(AdaptrisMessage msg) throws ServiceException { try { Cache cache = retrieveCache(); Optional<Expiry> hasExpiry = buildExpiry(msg); String cacheKey = msg.resolve(getKey()); 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); } }  @Override void doService(AdaptrisMessage msg); T withExpiry(String s); String getExpiry(); void setExpiry(String s);  }