@Test public void testDoService_NoErrorOnEmpty_NoValue() throws Exception { AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(JmsConstants.JMS_CORRELATION_ID, CORRELATION_ID) })); Cache cache = createCacheInstanceForTests(); AddToCacheService service = createServiceForTests(); CacheEntryEvaluator eval = service.getCacheEntryEvaluators().get(0); eval.setErrorOnEmptyValue(false); eval.setValueTranslator(new MetadataCacheValueTranslator(SRC_KEY)); try { service.setConnection(new CacheConnection(cache)); start(service); service.doService(msg); assertNull(cache.get(SRC_VALUE)); } finally { stop(service); } }
@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); } }
AddToCacheService extends CacheServiceBase { @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); } } }
AddToCacheService extends CacheServiceBase { @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); } } AddToCacheService(); }
AddToCacheService extends CacheServiceBase { @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); } } AddToCacheService(); @Override void doService(AdaptrisMessage msg); void setEnforceSerializable(Boolean bool); Boolean getEnforceSerializable(); boolean enforceSerializable(); }
AddToCacheService extends CacheServiceBase { @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); } } AddToCacheService(); @Override void doService(AdaptrisMessage msg); void setEnforceSerializable(Boolean bool); Boolean getEnforceSerializable(); boolean enforceSerializable();  }