use of org.springframework.messaging.MessagingException in project spring-integration by spring-projects.
the class RedisQueueInboundGateway method receiveAndReply.
@SuppressWarnings("unchecked")
private void receiveAndReply() {
byte[] value = null;
try {
value = this.boundListOperations.rightPop(this.receiveTimeout, TimeUnit.MILLISECONDS);
} catch (Exception e) {
handlePopException(e);
return;
}
String uuid = null;
if (value != null) {
if (!this.active) {
this.boundListOperations.rightPush(value);
return;
}
uuid = stringSerializer.deserialize(value);
try {
value = this.template.boundListOps(uuid).rightPop(this.receiveTimeout, TimeUnit.MILLISECONDS);
} catch (Exception e) {
handlePopException(e);
return;
}
Message<Object> requestMessage = null;
if (value != null) {
if (!this.active) {
this.template.boundListOps(uuid).rightPush(value);
this.boundListOperations.rightPush(stringSerializer.serialize(uuid));
return;
}
if (this.extractPayload) {
Object payload = value;
if (this.serializer != null) {
payload = this.serializer.deserialize(value);
}
requestMessage = this.getMessageBuilderFactory().withPayload(payload).build();
} else {
try {
requestMessage = (Message<Object>) this.serializer.deserialize(value);
} catch (Exception e) {
throw new MessagingException("Deserialization of Message failed.", e);
}
}
Message<?> replyMessage = this.sendAndReceiveMessage(requestMessage);
if (replyMessage != null) {
if (this.extractPayload) {
value = extractReplyPayload(replyMessage);
} else {
if (this.serializer != null) {
value = ((RedisSerializer<Object>) this.serializer).serialize(replyMessage);
}
}
this.template.boundListOps(uuid + QUEUE_NAME_SUFFIX).leftPush(value);
}
}
}
}
use of org.springframework.messaging.MessagingException in project spring-integration by spring-projects.
the class HttpRequestHandlingEndpointSupport method extractRequestBody.
@SuppressWarnings({ "unchecked", "rawtypes" })
private Object extractRequestBody(ServletServerHttpRequest request) throws IOException {
MediaType contentType = request.getHeaders().getContentType();
if (contentType == null) {
contentType = MediaType.APPLICATION_OCTET_STREAM;
}
ResolvableType requestPayloadType = getRequestPayloadType();
Class<?> expectedType;
if (requestPayloadType == null) {
expectedType = "text".equals(contentType.getType()) ? String.class : byte[].class;
} else {
expectedType = requestPayloadType.resolve();
}
for (HttpMessageConverter<?> converter : this.messageConverters) {
if (converter.canRead(expectedType, contentType)) {
return converter.read((Class) expectedType, request);
}
}
throw new MessagingException("Could not convert request: no suitable HttpMessageConverter found for expected type [" + expectedType.getName() + "] and content type [" + contentType + "]");
}
use of org.springframework.messaging.MessagingException in project spring-integration by spring-projects.
the class MailReceivingMessageSource method receive.
@SuppressWarnings("unchecked")
@Override
public Message<Object> receive() {
try {
Object mailMessage = this.mailQueue.poll();
if (mailMessage == null) {
Object[] messages = this.mailReceiver.receive();
if (messages != null) {
this.mailQueue.addAll(Arrays.asList(messages));
}
mailMessage = this.mailQueue.poll();
}
if (mailMessage != null) {
if (this.logger.isDebugEnabled()) {
this.logger.debug("received mail message [" + mailMessage + "]");
}
if (mailMessage instanceof Message) {
return (Message<Object>) mailMessage;
} else {
return getMessageBuilderFactory().withPayload(mailMessage).build();
}
}
} catch (Exception e) {
throw new MessagingException("failure occurred while polling for mail", e);
}
return null;
}
use of org.springframework.messaging.MessagingException in project spring-integration by spring-projects.
the class StringSourceFactory method createStringSourceForDocument.
private StringSource createStringSourceForDocument(Document document) {
try {
StringResult result = new StringResult();
Transformer transformer = getTransformer();
transformer.transform(new DOMSource(document), result);
return new StringSource(result.toString());
} catch (Exception e) {
throw new MessagingException("failed to create StringSource from document", e);
}
}
use of org.springframework.messaging.MessagingException in project spring-integration by spring-projects.
the class MarshallingTransformer method doTransform.
@Override
public Object doTransform(Message<?> message) {
Object source = (this.extractPayload) ? message.getPayload() : message;
Object transformedPayload = null;
Result result = this.getResultFactory().createResult(source);
if (result == null) {
throw new MessagingException("Unable to marshal payload, ResultFactory returned null.");
}
try {
this.marshaller.marshal(source, result);
transformedPayload = result;
} catch (IOException e) {
throw new MessagingException("Failed to marshal payload", e);
}
if (this.resultTransformer != null) {
transformedPayload = this.resultTransformer.transformResult(result);
}
return transformedPayload;
}
Aggregations