List of usage examples for org.springframework.jms.listener.adapter ListenerExecutionFailedException ListenerExecutionFailedException
public ListenerExecutionFailedException(String msg, Throwable cause)
From source file:org.apache.servicemix.jms.endpoints.JmsJcaConsumerEndpoint.java
public synchronized void start() throws Exception { if (bootstrapContext == null) { Executor executor = getServiceUnit().getComponent().getExecutor(); WorkManager wm = new WorkManagerWrapper(executor); bootstrapContext = new SimpleBootstrapContext(wm); }/*from w w w .j av a 2 s. co m*/ resourceAdapter.start(bootstrapContext); activationSpec.setResourceAdapter(resourceAdapter); if (endpointFactory == null) { TransactionManager tm = (TransactionManager) getContext().getTransactionManager(); endpointFactory = new SingletonEndpointFactory(new MessageListener() { public void onMessage(Message message) { try { JmsJcaConsumerEndpoint.this.onMessage(message, null); } catch (JMSException e) { throw new ListenerExecutionFailedException("Unable to handle message", e); } } }, tm); } resourceAdapter.endpointActivation(endpointFactory, activationSpec); super.start(); }
From source file:org.fcrepo.fixity.service.FixityService.java
/** * Consume a fixity message published to the JMS queue and act on fixity * check requests//from w w w. j a v a 2s.c o m * * @param uri the text of the {@link Message} which is supposed to be a * object uri */ public void consumeFixityMessage(String uri) throws JMSException { LOG.debug("received fixity request for object {}", uri); try { /* * queue a fixity check and retrieve the new results from the * repository */ final ObjectFixityResult result = this.checkObjectFixity(uri); /* save the new result to the database */ if (result != null) { this.databaseService.addResult(result); } } catch (IOException e) { /* rethrow the exception as a Spring JMS Exception */ LOG.error(e.getMessage(), e); throw new ListenerExecutionFailedException(e.getMessage(), e); } }
From source file:org.apache.servicemix.jms.endpoints.AbstractConsumerEndpoint.java
protected void processExchange(final MessageExchange exchange, final Session session, final JmsContext context) throws Exception { // Ignore DONE exchanges if (exchange.getStatus() == ExchangeStatus.DONE) { return;//from ww w .j av a2 s . c o m } // Create session if needed if (session == null) { template.execute(new SessionCallback() { public Object doInJms(Session session) throws JMSException { try { processExchange(exchange, session, context); } catch (Exception e) { throw new ListenerExecutionFailedException("Exchange processing failed", e); } return null; } }); return; } // Handle exchanges Message msg = null; Destination dest = null; if (exchange.getStatus() == ExchangeStatus.ACTIVE) { if (exchange.getFault() != null) { msg = marshaler.createFault(exchange, exchange.getFault(), session, context); dest = getReplyDestination(exchange, exchange.getFault(), session, context); } else if (exchange.getMessage("out") != null) { msg = marshaler.createOut(exchange, exchange.getMessage("out"), session, context); dest = getReplyDestination(exchange, exchange.getMessage("out"), session, context); } if (msg == null) { throw new IllegalStateException("Unable to send back answer or fault"); } setCorrelationId(context.getMessage(), msg); try { send(msg, session, dest); done(exchange); } catch (Exception e) { fail(exchange, e); throw e; } } else if (exchange.getStatus() == ExchangeStatus.ERROR) { Exception error = exchange.getError(); if (error == null) { error = new JBIException("Exchange in ERROR state, but no exception provided"); } msg = marshaler.createError(exchange, error, session, context); dest = getReplyDestination(exchange, error, session, context); setCorrelationId(context.getMessage(), msg); send(msg, session, dest); } else { throw new IllegalStateException("Unrecognized exchange status"); } }
From source file:org.apache.servicemix.jms.endpoints.AbstractConsumerEndpoint.java
protected void sendError(final MessageExchange exchange, final Exception error, Session session, final JmsContext context) throws Exception { // Create session if needed if (session == null) { template.execute(new SessionCallback() { public Object doInJms(Session session) throws JMSException { try { sendError(exchange, error, session, context); } catch (Exception e) { throw new ListenerExecutionFailedException("Exchange processing failed", e); }/* ww w . j a v a 2 s.co m*/ return null; } }); return; } Message msg = marshaler.createError(exchange, error, session, context); Destination dest = getReplyDestination(exchange, error, session, context); setCorrelationId(context.getMessage(), msg); send(msg, session, dest); }
From source file:org.springframework.jms.listener.adapter.MessageListenerAdapter.java
/** * Invoke the specified listener method. * @param methodName the name of the listener method * @param arguments the message arguments to be passed in * @return the result returned from the listener method * @throws JMSException if thrown by JMS API methods * @see #getListenerMethodName/*from ww w. j a v a 2 s . c om*/ * @see #buildListenerArguments */ protected Object invokeListenerMethod(String methodName, Object[] arguments) throws JMSException { try { MethodInvoker methodInvoker = new MethodInvoker(); methodInvoker.setTargetObject(getDelegate()); methodInvoker.setTargetMethod(methodName); methodInvoker.setArguments(arguments); methodInvoker.prepare(); return methodInvoker.invoke(); } catch (InvocationTargetException ex) { Throwable targetEx = ex.getTargetException(); if (targetEx instanceof JMSException) { throw (JMSException) targetEx; } else { throw new ListenerExecutionFailedException("Listener method '" + methodName + "' threw exception", targetEx); } } catch (Throwable ex) { throw new ListenerExecutionFailedException("Failed to invoke target method '" + methodName + "' with arguments " + ObjectUtils.nullSafeToString(arguments), ex); } }