@Test public void testGetValueFromMessage_NotXml() throws Exception { XpathCacheValueTranslator translator = createTranslator(); AdaptrisMessage message = createMessage(); message.setContent("This is not XML", null); try { translator.getValueFromMessage(message); fail(); } catch (CoreException expected) { } }
@Override public String getValueFromMessage(AdaptrisMessage msg) throws CoreException { NamespaceContext ctx = SimpleNamespaceContext.create(getNamespaceContext(), msg); DocumentBuilderFactoryBuilder builder = documentFactoryBuilder(ctx); String result = null; try { XPath xp = XPath.newXPathInstance(builder, ctx); Document d = XmlHelper.createDocument(msg, builder); result = xp.selectSingleTextItem(d, msg.resolve(getXpath())); } catch (Exception e) { throw ExceptionHelper.wrapCoreException(e); } return result; }
XpathCacheValueTranslator implements CacheValueTranslator<String>, CacheKeyTranslator { @Override public String getValueFromMessage(AdaptrisMessage msg) throws CoreException { NamespaceContext ctx = SimpleNamespaceContext.create(getNamespaceContext(), msg); DocumentBuilderFactoryBuilder builder = documentFactoryBuilder(ctx); String result = null; try { XPath xp = XPath.newXPathInstance(builder, ctx); Document d = XmlHelper.createDocument(msg, builder); result = xp.selectSingleTextItem(d, msg.resolve(getXpath())); } catch (Exception e) { throw ExceptionHelper.wrapCoreException(e); } return result; } }
XpathCacheValueTranslator implements CacheValueTranslator<String>, CacheKeyTranslator { @Override public String getValueFromMessage(AdaptrisMessage msg) throws CoreException { NamespaceContext ctx = SimpleNamespaceContext.create(getNamespaceContext(), msg); DocumentBuilderFactoryBuilder builder = documentFactoryBuilder(ctx); String result = null; try { XPath xp = XPath.newXPathInstance(builder, ctx); Document d = XmlHelper.createDocument(msg, builder); result = xp.selectSingleTextItem(d, msg.resolve(getXpath())); } catch (Exception e) { throw ExceptionHelper.wrapCoreException(e); } return result; } XpathCacheValueTranslator();  XpathCacheValueTranslator(String xpath); }
XpathCacheValueTranslator implements CacheValueTranslator<String>, CacheKeyTranslator { @Override public String getValueFromMessage(AdaptrisMessage msg) throws CoreException { NamespaceContext ctx = SimpleNamespaceContext.create(getNamespaceContext(), msg); DocumentBuilderFactoryBuilder builder = documentFactoryBuilder(ctx); String result = null; try { XPath xp = XPath.newXPathInstance(builder, ctx); Document d = XmlHelper.createDocument(msg, builder); result = xp.selectSingleTextItem(d, msg.resolve(getXpath())); } catch (Exception e) { throw ExceptionHelper.wrapCoreException(e); } return result; } XpathCacheValueTranslator();  XpathCacheValueTranslator(String xpath); @Override String getValueFromMessage(AdaptrisMessage msg); void setXpath(String s); String getXpath(); void setNamespaceContext(KeyValuePairSet namespaceContext); KeyValuePairSet getNamespaceContext(); DocumentBuilderFactoryBuilder getXmlDocumentFactoryConfig(); void setXmlDocumentFactoryConfig(DocumentBuilderFactoryBuilder xml); @Override String getKeyFromMessage(AdaptrisMessage msg); }
XpathCacheValueTranslator implements CacheValueTranslator<String>, CacheKeyTranslator { @Override public String getValueFromMessage(AdaptrisMessage msg) throws CoreException { NamespaceContext ctx = SimpleNamespaceContext.create(getNamespaceContext(), msg); DocumentBuilderFactoryBuilder builder = documentFactoryBuilder(ctx); String result = null; try { XPath xp = XPath.newXPathInstance(builder, ctx); Document d = XmlHelper.createDocument(msg, builder); result = xp.selectSingleTextItem(d, msg.resolve(getXpath())); } catch (Exception e) { throw ExceptionHelper.wrapCoreException(e); } return result; } XpathCacheValueTranslator();  XpathCacheValueTranslator(String xpath); @Override String getValueFromMessage(AdaptrisMessage msg); void setXpath(String s); String getXpath(); void setNamespaceContext(KeyValuePairSet namespaceContext); KeyValuePairSet getNamespaceContext(); DocumentBuilderFactoryBuilder getXmlDocumentFactoryConfig(); void setXmlDocumentFactoryConfig(DocumentBuilderFactoryBuilder xml); @Override String getKeyFromMessage(AdaptrisMessage msg);  }