use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class MessageMetricsInterceptorTest method testRestartProducerAfterProduceFailure.
@Test
public void testRestartProducerAfterProduceFailure() throws Exception {
doThrow(new ProduceException("Expected.")).when(mockStandaloneProducer).produce(any());
ProducingStatisticManager producingStatisticManager = new ProducingStatisticManager();
producingStatisticManager.setMarshaller(mockMarshaller);
producingStatisticManager.setProducer(mockStandaloneProducer);
metricsInterceptor.setStatisticManager(producingStatisticManager);
LifecycleHelper.init(metricsInterceptor);
LifecycleHelper.start(metricsInterceptor);
AdaptrisMessage message = DefaultMessageFactory.getDefaultInstance().newMessage();
// A minus time will expire the time slice immediately after the first message
metricsInterceptor.setTimesliceDuration(new TimeInterval(-1L, TimeUnit.SECONDS));
assertEquals(0, metricsInterceptor.getStats().size());
submitMessage(message);
assertEquals(1, metricsInterceptor.getStats().size());
submitMessage(message);
verify(mockMarshaller).marshal(any());
verify(mockStandaloneProducer).produce(any());
// test the restart.
verify(mockStandaloneProducer).requestStop();
}
use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class SimpleHttpProducer method doRequest.
@Override
protected AdaptrisMessage doRequest(AdaptrisMessage msg, String destination, long timeout) throws ProduceException {
AdaptrisMessage reply = defaultIfNull(getMessageFactory()).newMessage();
OutputStream out = null;
try {
HttpClientConnection c = retrieveConnection(HttpClientConnection.class);
HttpClientTransport client = c.initialiseClient(destination);
client.setMethod(getMethod());
HttpMessage m = HttpMessageFactory.getDefaultInstance().create();
applyHeaders(getAdditionalHeaders(msg), m);
if (getContentTypeKey() != null && msg.containsKey(getContentTypeKey())) {
m.getHeaders().put(Http.CONTENT_TYPE, msg.getMetadataValue(getContentTypeKey()));
}
if (getAuthorisation() != null) {
m.getHeaders().put(Http.AUTHORIZATION, getAuthorisation());
}
if (getEncoder() != null) {
getEncoder().writeMessage(msg, m);
} else {
out = m.getOutputStream();
out.write(msg.getPayload());
out.flush();
}
HttpSession httpSession = client.send(m, new Long(timeout).intValue(), handleRedirection());
readResponse(httpSession, reply);
httpSession.close();
} catch (HttpException e) {
throw new ProduceException(e);
} catch (IOException e) {
throw new ProduceException(e);
} catch (CoreException e) {
throw new ProduceException(e);
}
return reply;
}
use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class JmsProducer method request.
public AdaptrisMessage request(AdaptrisMessage msg, String dest, long timeout) throws ProduceException {
AdaptrisMessage translatedReply = defaultIfNull(getMessageFactory()).newMessage();
Destination replyTo = null;
MessageConsumer receiver = null;
try {
setupSession(msg);
JmsDestination target = buildDestination(dest, msg, true);
replyTo = target.getReplyToDestination();
// Listen for the reply.
receiver = currentSession().createConsumer(replyTo);
produce(msg, target);
translatedReply = waitForReply(receiver, timeout);
// BUG#915
commit();
} catch (Exception e) {
logLinkedException("", e);
rollback();
throw ExceptionHelper.wrapProduceException(e);
} finally {
JmsUtils.closeQuietly(receiver);
JmsUtils.deleteTemporaryDestination(replyTo);
}
return mergeReply(translatedReply, msg);
}
use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class DefinedJmsProducer method doProduce.
protected void doProduce(AdaptrisMessage msg, String dest, Destination replyTo) throws ProduceException {
Destination jmsDest = null;
try {
Args.notNull(dest, "destination");
// First of all directly try to get a Destination object if available.
jmsDest = retrieveObjectDestination(dest, msg);
if (jmsDest == null) {
jmsDest = createDestination(dest);
}
Args.notNull(jmsDest, "destination");
doProduce(msg, jmsDest, replyTo);
commit();
} catch (Exception e) {
log.warn("Error producing to destination [{}]", dest);
logLinkedException("Produce", e);
rollback();
throw ExceptionHelper.wrapProduceException(e);
}
}
use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class DefinedJmsProducer method request.
public AdaptrisMessage request(AdaptrisMessage msg, String dest, long timeout) throws ProduceException {
AdaptrisMessage translatedReply = defaultIfNull(getMessageFactory()).newMessage();
Destination replyTo = null;
MessageConsumer receiver = null;
try {
setupSession(msg);
getMessageTranslator().registerSession(producerSession().getSession());
if (msg.headersContainsKey(JMS_ASYNC_STATIC_REPLY_TO)) {
replyTo = createDestination(msg.getMetadataValue(JMS_ASYNC_STATIC_REPLY_TO));
} else {
replyTo = createTemporaryDestination();
}
receiver = currentSession().createConsumer(replyTo);
doProduce(msg, dest, replyTo);
Message jmsReply = receiver.receive(timeout);
translatedReply = Optional.ofNullable(MessageTypeTranslatorImp.translate(getMessageTranslator(), jmsReply)).orElseThrow(() -> new JMSException("No Reply Received within " + timeout + "ms"));
acknowledge(jmsReply);
// BUG#915
commit();
} catch (Exception e) {
logLinkedException("", e);
rollback();
throw new ProduceException(e);
} finally {
JmsUtils.closeQuietly(receiver);
JmsUtils.deleteTemporaryDestination(replyTo);
}
return mergeReply(translatedReply, msg);
}
Aggregations