private static void throwInvalidCompositeRuleName(final String compositRuleName) { throw new SmooksException("A rule must be specified in the format <ruleProviderName>.<ruleName>." + " Please check you configuration and make sure that you are referencing the rule in a correct manner."); }
private static URL systemIdToURL(final String systemId) { try { return new URL(systemId); } catch (MalformedURLException e) { throw new SmooksException("Invalid System ID on StreamSource: '" + systemId + "'. Must be a valid URL.", e); } }
public void replay(ContentHandler handler) throws SmooksException { try { handler.endElement(uri, localName, qName); } catch (SAXException e) { throw new SmooksException("Error replaying endElement event.", e); } } }
public void replay(ContentHandler handler) throws SmooksException { try { handler.startElement(uri, localName, qName, atts); } catch (SAXException e) { throw new SmooksException("Error replaying startElement event.", e); } } }
public void apply(Object contextObject, Writer outputWriter) { try { template.process(contextObject, outputWriter); } catch (TemplateException e) { throw new SmooksException("Failed to apply template.", e); } catch (IOException e) { throw new IllegalStateException("Unexpected IOException.", e); } }
private static Reader streamToReader(InputStream inputStream, String contentEncoding) { try { if (contentEncoding != null) { return new InputStreamReader(inputStream, contentEncoding); } else { return new InputStreamReader(inputStream, "UTF-8"); } } catch (UnsupportedEncodingException e) { throw new SmooksException("Unable to decode input stream.", e); } }
public void apply(Object contextObject, Writer outputWriter) { try { template.process(contextObject, outputWriter); } catch (TemplateException e) { throw new SmooksException("Failed to apply template.", e); } catch (IOException e) { throw new IllegalStateException("Unexpected IOException.", e); } }
private void createTempDir() { if (tmpDir == null) { try { File tmpFile = File.createTempFile("tmp", "tmp"); tmpFile.delete(); tmpDir = new File(tmpFile.getParentFile(), UUID.randomUUID().toString()); DeleteOnExitHook.add(tmpDir); } catch (IOException e) { throw new SmooksException("Unable to crete temp directory for archive.", e); } } }
private void createTempDir() { if (tmpDir == null) { try { File tmpFile = File.createTempFile("tmp", "tmp"); tmpFile.delete(); tmpDir = new File(tmpFile.getParentFile(), UUID.randomUUID().toString()); DeleteOnExitHook.add(tmpDir); } catch (IOException e) { throw new SmooksException("Unable to crete temp directory for archive.", e); } } }
private static InputStream systemIdToStream(String systemId) { try { return systemIdToURL(systemId).openStream(); } catch (IOException e) { throw new SmooksException("Invalid System ID on StreamSource: '" + systemId + "'. Unable to open stream to resource.", e); } }
private Class<?> getClassForType(final String type) { try { return ClassUtil.forName(type, Exports.class); } catch (ClassNotFoundException e) { throw new SmooksException("Could not load class for type [" + type + "]."); } }
public Message createJMSMessage(String beanId, ExecutionContext context, Session jmsSession) throws SmooksException { final Object bean = context.getBeanContext().getBean( beanId ); if(bean == null) { throw new SmooksException("Bean beandId '" + beanId + "' not available in the bean repository of this execution context. Check the order in which your resources are being applied (in Smooks configuration)."); } if(bean instanceof Map == false) { throw new SmooksException("The bean unde beanId '" + beanId + "' with type " + bean.getClass().getName() + "' can't be send with an JMS MapMessage because it doesn't implement a Map interface."); } return createMapMessage( (Map<?, ?>) bean, jmsSession ); }
private void applyTemplate(Template template, SAXElement element, ExecutionContext executionContext, Writer writer) throws SmooksException { try { Map<String, Object> model = FreeMarkerUtils.getMergedModel(executionContext); template.process(model, writer); writer.flush(); } catch (TemplateException e) { throw new SmooksException("Failed to apply FreeMarker template to fragment '" + SAXUtil.getXPath(element) + "'. Resource: " + config, e); } catch (IOException e) { throw new SmooksException("Failed to apply FreeMarker template to fragment '" + SAXUtil.getXPath(element) + "'. Resource: " + config, e); } }
@Uninitialize public void uninitialize() { try { producerTemplate.stop(); } catch (final Exception e) { throw new SmooksException(e.getMessage(), e); } }
public void visitBefore(Element element, ExecutionContext executionContext) throws SmooksException { SmooksResourceConfiguration config; try { config = ExtensionContext.getExtensionContext(executionContext).getResourceStack().peek(); } catch (EmptyStackException e) { throw new SmooksException("No SmooksResourceConfiguration available in ExtensionContext stack. Unable to set SmooksResourceConfiguration property '" + setOn + "' with static value."); } logger.debug("Setting property '" + setOn + "' on resource configuration to a value of '" + value + "'."); ResourceConfigUtil.setProperty(config, setOn, value, executionContext); } }
public void visitBefore(Element element, ExecutionContext executionContext) throws SmooksException { SmooksResourceConfiguration config; try { config = ExtensionContext.getExtensionContext(executionContext).getResourceStack().peek(); } catch (EmptyStackException e) { throw new SmooksException("No SmooksResourceConfiguration available in ExtensionContext stack. Unable to set SmooksResourceConfiguration property '" + setOn + "' with static value."); } logger.debug("Setting property '" + setOn + "' on resource configuration to a value of '" + value + "'."); ResourceConfigUtil.setProperty(config, setOn, value, executionContext); } }
private String extractTextContent(Node node, ExecutionContext executionContext) { if(node.getNodeType() == Node.TEXT_NODE) { return node.getTextContent(); } else if(node.getNodeType() == Node.ELEMENT_NODE && ContextObjectSerializationUnit.isContextObjectElement((Element) node)) { String contextKey = ContextObjectSerializationUnit.getContextKey((Element) node); return (String) executionContext.getAttribute(contextKey); } else if(node.getNodeType() == Node.ELEMENT_NODE && TextSerializationUnit.isTextElement((Element) node)) { return TextSerializationUnit.getText((Element) node); } else { throw new SmooksException("Unsupported 'bindTo' or toOutStream templating action. The bind data must be attached to a DOM Text node, or already bound to a <context-object> element."); } }
public RuleEvalResult evaluate(String ruleName, CharSequence selectedData, ExecutionContext context) throws SmooksException { ExpressionEvaluator evaluator = rules.get(ruleName); if (evaluator == null) { throw new SmooksException("Unknown rule name '" + ruleName + "' on MVEL RuleProvider '" + name + "'."); } try { return new MVELRuleEvalResult(evaluator.eval(context.getBeanContext().getBeanMap()), ruleName, name, selectedData.toString()); } catch(Throwable t) { return new MVELRuleEvalResult(t, ruleName, name, selectedData.toString()); } }
public RuleEvalResult evaluate(String ruleName, CharSequence selectedData, ExecutionContext context) throws SmooksException { ExpressionEvaluator evaluator = rules.get(ruleName); if (evaluator == null) { throw new SmooksException("Unknown rule name '" + ruleName + "' on MVEL RuleProvider '" + name + "'."); } try { return new MVELRuleEvalResult(evaluator.eval(context.getBeanContext().getBeanMap()), ruleName, name, selectedData.toString()); } catch(Throwable t) { return new MVELRuleEvalResult(t, ruleName, name, selectedData.toString()); } }
private void setCorrelationID(ExecutionContext execContext, Message message) { Map<String, Object> beanMap = FreeMarkerUtils.getMergedModel(execContext); String correlationId = correlationIdTemplate.apply(beanMap); try { message.setJMSCorrelationID(correlationId); } catch (JMSException e) { throw new SmooksException("Failed to set CorrelationID '" + correlationId + "' on message.", e); } }