use of org.springframework.messaging.MessageHandlingException in project spring-integration by spring-projects.
the class UriVariableTests method testInt2720XmppUriVariables.
@Test
public void testInt2720XmppUriVariables() throws Exception {
willThrow(new WebServiceIOException("intentional")).given(this.xmppConnection).sendStanza(Mockito.any(Stanza.class));
Message<?> message = MessageBuilder.withPayload("<spring/>").setHeader("to", "user").build();
try {
this.inputXmpp.send(message);
} catch (MessageHandlingException e) {
// expected
Class<?> causeType = e.getCause().getClass();
// offline
assertTrue(WebServiceIOException.class.equals(causeType));
}
ArgumentCaptor<Stanza> argument = ArgumentCaptor.forClass(Stanza.class);
Mockito.verify(this.xmppConnection).sendStanza(argument.capture());
assertEquals("user@jabber.org", argument.getValue().getTo().toString());
assertEquals("xmpp:user@jabber.org", this.interceptor.getLastUri().toString());
}
use of org.springframework.messaging.MessageHandlingException in project spring-integration by spring-projects.
the class UnicastSendingMessageHandler method handleMessageInternal.
@Override
public void handleMessageInternal(Message<?> message) throws MessageHandlingException, MessageDeliveryException {
if (this.acknowledge) {
Assert.state(this.isRunning(), "When 'acknowledge' is enabled, adapter must be running");
startAckThread();
}
CountDownLatch countdownLatch = null;
String messageId = message.getHeaders().getId().toString();
try {
boolean waitForAck = this.waitForAck;
if (waitForAck) {
countdownLatch = new CountDownLatch(this.ackCounter);
this.ackControl.put(messageId, countdownLatch);
}
convertAndSend(message);
if (waitForAck) {
try {
if (!countdownLatch.await(this.ackTimeout, TimeUnit.MILLISECONDS)) {
throw new MessagingException(message, "Failed to receive UDP Ack in " + this.ackTimeout + " millis");
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
} catch (MessagingException e) {
throw e;
} catch (Exception e) {
closeSocketIfNeeded();
throw new MessageHandlingException(message, "failed to send UDP packet", e);
} finally {
if (countdownLatch != null) {
this.ackControl.remove(messageId);
}
}
}
use of org.springframework.messaging.MessageHandlingException in project spring-integration by spring-projects.
the class DatagramPacketMessageMapper method getPayloadAsBytes.
private byte[] getPayloadAsBytes(Message<?> message) {
byte[] bytes = null;
Object payload = message.getPayload();
if (payload instanceof byte[]) {
bytes = (byte[]) payload;
} else if (payload instanceof String) {
try {
bytes = ((String) payload).getBytes(this.charset);
} catch (UnsupportedEncodingException e) {
throw new MessageHandlingException(message, e);
}
} else {
throw new MessageHandlingException(message, "The datagram packet mapper expects " + "either a byte array or String payload, but received: " + payload.getClass());
}
return bytes;
}
use of org.springframework.messaging.MessageHandlingException in project spring-integration by spring-projects.
the class TcpMessageMapper method getPayloadAsBytes.
/**
* Extracts the payload as a byte array.
*/
private byte[] getPayloadAsBytes(Message<?> message) {
byte[] bytes = null;
Object payload = message.getPayload();
if (payload instanceof byte[]) {
bytes = (byte[]) payload;
} else if (payload instanceof String) {
try {
bytes = ((String) payload).getBytes(this.charset);
} catch (UnsupportedEncodingException e) {
throw new MessageHandlingException(message, e);
}
} else {
throw new MessageHandlingException(message, "When using a byte array serializer, the socket mapper expects " + "either a byte array or String payload, but received: " + payload.getClass());
}
return bytes;
}
use of org.springframework.messaging.MessageHandlingException in project spring-integration by spring-projects.
the class TcpSendingMessageHandler method obtainConnection.
protected TcpConnection obtainConnection(Message<?> message) {
TcpConnection connection = null;
Assert.notNull(this.clientConnectionFactory, "'clientConnectionFactory' cannot be null");
try {
connection = this.clientConnectionFactory.getConnection();
} catch (Exception e) {
logger.error("Error creating connection", e);
throw new MessageHandlingException(message, "Failed to obtain a connection", e);
}
return connection;
}
Aggregations