Example usage for org.springframework.jms.support JmsUtils convertJmsAccessException

List of usage examples for org.springframework.jms.support JmsUtils convertJmsAccessException

Introduction

In this page you can find the example usage for org.springframework.jms.support JmsUtils convertJmsAccessException.

Prototype

public static JmsException convertJmsAccessException(JMSException ex) 

Source Link

Document

Convert the specified checked javax.jms.JMSException JMSException to a Spring runtime org.springframework.jms.JmsException JmsException equivalent.

Usage

From source file:com.santika.hendi.activeMQ.MessageConsumerBean.java

public MessageObject receiveMessage() {
    MapMessage message = (MapMessage) jmsTemplate.receive(destination);
    try {//from ww w .  j av  a2 s .c o m
        MessageObject messageObj = new MessageObject();
        messageObj.setMailId(message.getString("mailId"));
        messageObj.setMessage(message.getString("message"));
        return messageObj;
    } catch (JMSException e) {
        throw JmsUtils.convertJmsAccessException(e);
    }
}

From source file:net.lr.jmsbridge.BridgeServlet.java

/**
 * Forward HTTP request to a jms queue and listen on a temporary queue for the reply.
 * Connects to the jms server by using the username and password from the HTTP basic auth.
 *///from www  .  j  a  va  2 s.  com
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String authHeader = req.getHeader("Authorization");
    if (authHeader == null) {
        resp.setHeader("WWW-Authenticate", "Basic realm=\"Bridge\"");
        resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "auth");
        return;
    }
    UserNameAndPassword auth = extractUserNamePassword(authHeader);
    PrintStream out = new PrintStream(resp.getOutputStream());
    String contextPath = req.getContextPath();
    String uri = req.getRequestURI();
    String queueName = uri.substring(contextPath.length() + 1);
    final StringBuffer reqContent = retrieveRequestContent(req.getReader());

    ConnectionFactory cf = connectionPool.getConnectionFactory(auth);
    JmsTemplate jmsTemplate = new JmsTemplate();
    jmsTemplate.setConnectionFactory(cf);
    jmsTemplate.setReceiveTimeout(10000);
    final Destination replyDest = connectionPool.getReplyDestination(cf, auth);
    jmsTemplate.send(queueName, new MessageCreator() {

        @Override
        public Message createMessage(Session session) throws JMSException {
            TextMessage message = session.createTextMessage(reqContent.toString());
            message.setJMSReplyTo(replyDest);
            return message;
        }

    });
    Message replyMsg = jmsTemplate.receive(replyDest);
    if (replyMsg instanceof TextMessage) {
        TextMessage replyTMessage = (TextMessage) replyMsg;
        try {
            out.print(replyTMessage.getText());
        } catch (JMSException e) {
            JmsUtils.convertJmsAccessException(e);
        }
    }
}

From source file:org.apache.cxf.transport.jms.JMSConduit.java

/**
 * When a message is received on the reply destination the correlation map is searched for the
 * correlationId. If it is found the message is converted to a CXF message and the thread sending the
 * request is notified {@inheritDoc}//from w w w . j a  va 2s .c o m
 */
public void onMessage(javax.jms.Message jmsMessage) {
    String correlationId;
    try {
        correlationId = jmsMessage.getJMSCorrelationID();
    } catch (JMSException e) {
        throw JmsUtils.convertJmsAccessException(e);
    }

    Exchange exchange = correlationMap.remove(correlationId);
    if (exchange == null) {
        LOG.log(Level.WARNING, "Could not correlate message with correlationId " + correlationId);
        return;
    }
    Message inMessage = new MessageImpl();
    exchange.setInMessage(inMessage);
    LOG.log(Level.FINE, "client received reply: ", jmsMessage);
    try {
        JMSUtils.populateIncomingContext(jmsMessage, inMessage, JMSConstants.JMS_CLIENT_RESPONSE_HEADERS);

        byte[] response = JMSUtils.retrievePayload(jmsMessage, (String) inMessage.get(Message.ENCODING));
        LOG.log(Level.FINE, "The Response Message payload is : [" + response + "]");
        inMessage.setContent(InputStream.class, new ByteArrayInputStream(response));

        if (exchange.isSynchronous()) {
            synchronized (exchange) {
                exchange.put(CORRELATED, Boolean.TRUE);
                exchange.notifyAll();
            }
        }

        //REVISIT: put on a workqueue?
        if (incomingObserver != null) {
            incomingObserver.onMessage(exchange.getInMessage());
        }
    } catch (UnsupportedEncodingException ex) {
        getLogger().log(Level.WARNING, "can't get the right encoding information " + ex);
    }
}

From source file:org.apache.servicemix.jbi.cluster.requestor.AbstractJmsRequestorPool.java

protected JmsException convertJmsAccessException(JMSException ex) {
    return JmsUtils.convertJmsAccessException(fixForSpring5470(ex));
}

From source file:org.springframework.jms.core.JmsTemplate.java

/**
 * Convert the specified checked {@link javax.jms.JMSException JMSException} to
 * a Spring runtime {@link org.springframework.jms.JmsException JmsException}
 * equivalent.//from ww  w . j a  v  a  2  s . c om
 * <p>Default implementation delegates to JmsUtils.
 * @param ex the original checked JMSException to convert
 * @return the Spring runtime JmsException wrapping <code>ex</code>
 * @see org.springframework.jms.support.JmsUtils#convertJmsAccessException
 */
protected JmsException convertJmsAccessException(JMSException ex) {
    return JmsUtils.convertJmsAccessException(ex);
}

From source file:rewards.messaging.server.DiningListenerImpl.java

@Override
// TODO-02 Add @Transactional
public void onMessage(Message message) {
    try {/*from   ww w.  j av a  2 s .  co m*/
        Dining dining = (Dining) ((ObjectMessage) message).getObject();
        logMessage(message, dining);
        if (causeErrorAfterReceiving)
            throw new RuntimeException("error after receiving dining with amount " + dining.getAmount());
        RewardConfirmation confirmation = this.rewardNetwork.rewardAccountFor(dining);
        if (causeErrorAfterProcessing)
            throw new RuntimeException("error after processing dining with amount " + dining.getAmount());
        jmsTemplate.convertAndSend(confirmation);
        log.debug("Sent response with confirmation nr " + confirmation.getConfirmationNumber());
    } catch (JMSException e) {
        throw JmsUtils.convertJmsAccessException(e);
    }
}