Search in sources :

Example 56 with MessagingException

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);
            }
        }
    }
}
Also used : MessagingException(org.springframework.messaging.MessagingException) MessagingException(org.springframework.messaging.MessagingException)

Example 57 with MessagingException

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 + "]");
}
Also used : MessagingException(org.springframework.messaging.MessagingException) MediaType(org.springframework.http.MediaType) ResolvableType(org.springframework.core.ResolvableType)

Example 58 with MessagingException

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;
}
Also used : Message(org.springframework.messaging.Message) MessagingException(org.springframework.messaging.MessagingException) MessagingException(org.springframework.messaging.MessagingException)

Example 59 with MessagingException

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);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) MessagingException(org.springframework.messaging.MessagingException) StringResult(org.springframework.xml.transform.StringResult) StringSource(org.springframework.xml.transform.StringSource) MessagingException(org.springframework.messaging.MessagingException)

Example 60 with MessagingException

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;
}
Also used : MessagingException(org.springframework.messaging.MessagingException) IOException(java.io.IOException) Result(javax.xml.transform.Result)

Aggregations

MessagingException (org.springframework.messaging.MessagingException)143 Test (org.junit.Test)60 IOException (java.io.IOException)25 Message (org.springframework.messaging.Message)23 QueueChannel (org.springframework.integration.channel.QueueChannel)22 ErrorMessage (org.springframework.messaging.support.ErrorMessage)21 CountDownLatch (java.util.concurrent.CountDownLatch)17 BeanFactory (org.springframework.beans.factory.BeanFactory)15 MessageChannel (org.springframework.messaging.MessageChannel)15 MessageHandlingException (org.springframework.messaging.MessageHandlingException)15 GenericMessage (org.springframework.messaging.support.GenericMessage)15 MessageHandler (org.springframework.messaging.MessageHandler)14 File (java.io.File)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 Matchers.containsString (org.hamcrest.Matchers.containsString)12 DirectChannel (org.springframework.integration.channel.DirectChannel)12 ArrayList (java.util.ArrayList)11 PollableChannel (org.springframework.messaging.PollableChannel)11 Lock (java.util.concurrent.locks.Lock)8 MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)8