List of usage examples for org.springframework.messaging MessagingException MessagingException
public MessagingException(Message<?> message, Throwable cause)
From source file:biz.c24.io.spring.integration.validation.C24ValidatingMessageProcessor.java
@Override public Map<String, ?> processMessage(Message<?> message) { Map<String, Object> result = new HashMap<String, Object>(); Object payload = message.getPayload(); ComplexDataObject cdo;/*w w w . j ava 2 s . c o m*/ try { cdo = (ComplexDataObject) payload; } catch (ClassCastException e) { throw new MessagingException( "Cannot validate payload of type [" + payload != null ? payload.getClass().getName() : "null" + "]. Only ComplexDataObject is supported.", e); } ValidationManager manager = new ValidationManager(); ValidationEventCollector vec = new ValidationEventCollector(); manager.addValidationListener(vec); if (manager.validateByEvents(cdo)) { result.put(VALID, Boolean.TRUE); } else { result.put(VALID, Boolean.FALSE); } if (isAddFailEvents()) { result.put(FAIL_EVENTS, new ArrayList<ValidationEvent>(Arrays.asList(vec.getFailEvents()))); } if (isAddPassEvents()) { result.put(PASS_EVENTS, new ArrayList<ValidationEvent>(Arrays.asList(vec.getPassEvents()))); } if (isAddStatistics()) { result.put(STATISTICS, manager.getStatistics()); } return result; }
From source file:biz.c24.io.spring.integration.selector.AbstractXPathMessageSelector.java
final public boolean accept(Message<?> message) { Object payload = message.getPayload(); ComplexDataObject cdo;/* ww w . j a v a 2 s .c om*/ try { cdo = (ComplexDataObject) payload; } catch (ClassCastException e) { throw new MessagingException("Cannot evaluate payload of type [" + payload.getClass().getName() + "]. Only ComplexDataObject is supported.", e); } try { return doAcceptPayload(cdo); } catch (IOXPathException e) { throw new XPathException("Exception thrown trying to evaluate [" + statement + "]", e); } }
From source file:biz.c24.io.spring.integration.transformer.C24MarshallingTransformer.java
@Override protected Object transformPayload(Object payload) throws Exception { ComplexDataObject cdo;//ww w . j ava 2s . c o m try { cdo = (ComplexDataObject) payload; } catch (ClassCastException e) { throw new MessagingException("Cannot marshal payload of type [" + payload.getClass().getName() + "]. Only ComplexDataObject is supported.", e); } Sink sink = outputType.getSink(sinkFactory); sink.writeObject(cdo); Object outputPayload = outputType.getOutput(sink); return outputPayload; }
From source file:biz.c24.io.spring.integration.selector.C24ValidatingMessageSelector.java
public boolean accept(Message<?> message) { Object payload = message.getPayload(); ComplexDataObject cdo;/* www . j a va 2 s .c om*/ try { cdo = (ComplexDataObject) payload; } catch (ClassCastException e) { throw new MessagingException("Cannot validate payload of type [" + payload.getClass().getName() + "]. Only ComplexDataObject is supported.", e); } boolean result; if (!throwExceptionOnRejection || failFast) { result = validateFailFast(cdo, message); } else { result = validateAllEvents(cdo); } return result; }
From source file:biz.c24.io.spring.integration.router.C24XPathRouter.java
protected IOXPath createXPath() { try {/*w w w . j a v a2 s .c o m*/ return IOXPathFactory.getInstance(statement); } catch (IOXPathException e) { throw new MessagingException( "Exception when trying to instantiate the Xpath statement [" + statement + "].", e); } }
From source file:biz.c24.io.spring.integration.router.C24XPathRouter.java
@Override protected List<Object> getChannelKeys(Message<?> message) { ComplexDataObject cdo;// w w w . java 2s . c o m try { cdo = (ComplexDataObject) message.getPayload(); } catch (ClassCastException e) { Object payload = message.getPayload(); throw new MessagingException("Cannot route based on payloads of type [" + payload == null ? "<null>" : payload.getClass().getName() + "]. Only ComplexDataObject is supported.", e); } IOXPath xPath = createXPath(); String channel; try { channel = xPath.getString(cdo); } catch (IOXPathException e) { throw new MessagingException("Exception when trying to evaluate the Xpath statement [" + statement + "] on the object [" + cdo + "] to a String.", e); } return Collections.singletonList((Object) channel); }
From source file:com.consol.citrus.samples.bookstore.validation.XmlSchemaValidatingChannelInterceptor.java
/** * Validates the payload of the message/*from w ww. j a v a 2 s . c o m*/ * * @param message * @param channel */ public void validateSchema(Message<?> message, MessageChannel channel) { try { SAXParseException[] exceptions = xmlValidator.validate(converter.convertToSource(message.getPayload())); if (exceptions.length > 0) { StringBuilder msg = new StringBuilder("Invalid XML message on channel "); if (channel != null) { msg.append(channel.toString()); } else { msg.append("<unknown>"); } msg.append(":\n"); for (SAXParseException e : exceptions) { msg.append("\t").append(e.getMessage()); msg.append(" (line=").append(e.getLineNumber()); msg.append(", col=").append(e.getColumnNumber()).append(")\n"); } log.warn("XSD schema validation failed: ", msg.toString()); throw new XmlSchemaValidationException(message, exceptions[0]); } } catch (IOException ioE) { throw new MessagingException("Exception applying schema validation", ioE); } }
From source file:org.springframework.cloud.aws.messaging.listener.QueueMessageHandler.java
@Override protected void processHandlerMethodException(HandlerMethod handlerMethod, Exception ex, Message<?> message) { super.processHandlerMethodException(handlerMethod, ex, message); throw new MessagingException("An exception occurred while invoking the handler method", ex); }
From source file:org.springframework.cloud.aws.messaging.support.converter.NotificationRequestConverter.java
private static Object getNumberValue(String attributeType, String attributeValue) { String numberType = attributeType.substring(MessageAttributeDataTypes.NUMBER.length() + 1); try {//from ww w .j a va 2 s. co m Class<? extends Number> numberTypeClass = Class.forName(numberType).asSubclass(Number.class); return NumberUtils.parseNumber(attributeValue, numberTypeClass); } catch (ClassNotFoundException e) { throw new MessagingException( String.format( "Message attribute with value '%s' and data type '%s' could not be converted " + "into a Number because target class was not found.", attributeValue, attributeType), e); } }
From source file:org.springframework.integration.config.SourcePollingChannelAdapterFactoryBeanTests.java
@Test public void testInterrupted() throws Exception { final CountDownLatch startLatch = new CountDownLatch(1); MessageSource<Object> ms = () -> { startLatch.countDown();/* ww w . j a va2 s . com*/ try { Thread.sleep(10000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new MessagingException("Interrupted awaiting stopLatch", e); } return null; }; SourcePollingChannelAdapter pollingChannelAdapter = new SourcePollingChannelAdapter(); ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); taskScheduler.setWaitForTasksToCompleteOnShutdown(true); taskScheduler.setAwaitTerminationSeconds(1); taskScheduler.afterPropertiesSet(); pollingChannelAdapter.setTaskScheduler(taskScheduler); MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler(); Log errorHandlerLogger = TestUtils.getPropertyValue(errorHandler, "logger", Log.class); errorHandlerLogger = spy(errorHandlerLogger); DirectFieldAccessor dfa = new DirectFieldAccessor(errorHandler); dfa.setPropertyValue("logger", errorHandlerLogger); pollingChannelAdapter.setErrorHandler(errorHandler); pollingChannelAdapter.setSource(ms); pollingChannelAdapter.setOutputChannel(new NullChannel()); pollingChannelAdapter.setBeanFactory(mock(BeanFactory.class)); pollingChannelAdapter.afterPropertiesSet(); Log adapterLogger = TestUtils.getPropertyValue(pollingChannelAdapter, "logger", Log.class); adapterLogger = spy(adapterLogger); when(adapterLogger.isDebugEnabled()).thenReturn(true); dfa = new DirectFieldAccessor(pollingChannelAdapter); dfa.setPropertyValue("logger", adapterLogger); pollingChannelAdapter.start(); assertTrue(startLatch.await(10, TimeUnit.SECONDS)); pollingChannelAdapter.stop(); taskScheduler.shutdown(); verifyZeroInteractions(errorHandlerLogger); verify(adapterLogger).debug(contains("Poll interrupted - during stop()?")); }