Example usage for javax.jms JMSException getMessage

List of usage examples for javax.jms JMSException getMessage

Introduction

In this page you can find the example usage for javax.jms JMSException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:tld.yourname.jms.server.DemoService3.java

/**
 *
 * @param aArgs// w  ww  .  j  av  a 2  s .c  o  m
 * @return
 */
public JWSEndPoint start(String[] aArgs) {
    // set up log4j logging
    // later this should be read from a shared log4j properties or xml file!
    Properties lProps = new Properties();
    lProps.setProperty("log4j.rootLogger", "INFO, console");
    lProps.setProperty("log4j.logger.org.apache.activemq", "WARN");
    lProps.setProperty("log4j.logger.org.springframework", "WARN");
    lProps.setProperty("log4j.logger.org.apache.xbean", "WARN");
    lProps.setProperty("log4j.logger.org.apache.camel", "INFO");
    lProps.setProperty("log4j.logger.org.eclipse.jetty", "WARN");
    lProps.setProperty("log4j.appender.console", "org.apache.log4j.ConsoleAppender");
    lProps.setProperty("log4j.appender.console.layout", "org.apache.log4j.PatternLayout");
    lProps.setProperty("log4j.appender.console.layout.ConversionPattern",
            // "%p: %m%n"
            "%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p - %C{1}: %m%n");
    // set here the jWebSocket log level:
    lProps.setProperty("log4j.logger.org.jwebsocket", "DEBUG");
    lProps.setProperty("log4j.appender.console.threshold", "DEBUG");
    PropertyConfigurator.configure(lProps);

    // setting the endpoint service authenticator, clients commonly require 
    // to authenticate againts endpoint services
    final JWSAutoSelectAuthenticator lAuthenticator = new JWSAutoSelectAuthenticator();
    final JWSOAuthAuthenticator lOAuthAuthenticator = new JWSOAuthAuthenticator();
    final JWSLDAPAuthenticator lLDAPAuthenticator = new JWSLDAPAuthenticator();

    // hardcoding memory authenticator for example
    JWSMemoryAuthenticator lMemoryAuth = new JWSMemoryAuthenticator();
    lMemoryAuth.addCredentials("admin", "21232f297a57a5a743894a0e4a801fc3"); //admin:admin
    lAuthenticator.addAuthenticator(lMemoryAuth);

    mLog.info("jWebSocket JMS Gateway Server Endpoint");
    Configuration lConfig = null;
    boolean lConfigLoaded;
    try {
        // try to load properties files from local folder or jar
        String lPath = "JMSServer.properties";
        mLog.debug("Trying to read properties from: " + lPath);
        lConfig = new PropertiesConfiguration(lPath);
    } catch (ConfigurationException ex) {
    }
    if (null == lConfig) {
        try {
            // try to load properties files from JWEBSOCKET_HOME/conf/JMSPlugIn
            String lPath = Tools
                    .expandEnvVarsAndProps("${JWEBSOCKET_HOME}conf/JMSPlugIn/DemoService3.properties");
            mLog.debug("Tring to read properties from: " + lPath);
            lConfig = new PropertiesConfiguration(lPath);
        } catch (ConfigurationException ex) {
        }
    }
    if (null == lConfig) {
        mLog.error("Configuration file could not be opened.");
        return null;
    }

    // the URL of the message broker
    String lBrokerURL = lConfig.getString("BrokerURL", "tcp://127.0.0.1:61616");
    // "failover:(tcp://0.0.0.0:61616,tcp://127.0.0.1:61616)?initialReconnectDelay=100&randomize=false";
    // the name of the JMS Gateway topic
    String lGatewayTopic = lConfig.getString("GatewayTopic", "org.jwebsocket.jms.gateway");
    // endpoint id of JMS Gateway
    String lGatewayId = lConfig.getString("GatewayId", "org.jwebsocket.jms.gateway");
    String lEndPointId = lConfig.getString("EndPointId", UUID.randomUUID().toString());

    // get authentication information against jWebSocket
    final String lJWSUsername = lConfig.getString("JWSUsername");
    final String lJWSPassword = lConfig.getString("JWSPassword");
    final boolean lFullTextLogging = lConfig.getBoolean("FullTextLogging", false);

    // set up OAuth Authenticator
    boolean lUseOAuth = lConfig.getBoolean("UseOAuth", false);
    if (lUseOAuth) {
        String lOAuthHost = lConfig.getString("OAuthHost");
        String lOAuthAppId = lConfig.getString("OAuthAppId");
        String lOAuthAppSecret = lConfig.getString("OAuthAppSecret");
        String lOAuthUsername = lConfig.getString("OAuthUsername");
        String lOAuthPassword = lConfig.getString("OAuthPassword");
        long lOAuthTimeout = lConfig.getLong("OAuthTimeout", 5000);

        lUseOAuth = lUseOAuth && null != lOAuthHost && null != lOAuthAppId && null != lOAuthAppSecret
                && null != lOAuthUsername && null != lOAuthPassword;

        lOAuthAuthenticator.init(lOAuthHost, lOAuthAppId, lOAuthAppSecret, lOAuthTimeout);
        lAuthenticator.addAuthenticator(lOAuthAuthenticator);
    }

    // set up LDAP Authenticator
    boolean lUseLDAP = lConfig.getBoolean("UseLDAP", false);
    if (lUseLDAP) {
        String lLDAPURL = lConfig.getString("LDAPURL");
        String lBaseDNGroups = lConfig.getString("BaseDNGroups");
        String lBaseDNUsers = lConfig.getString("BaseDNUsers");

        lLDAPAuthenticator.init(lLDAPURL, lBaseDNGroups, lBaseDNUsers);
        lAuthenticator.addAuthenticator(lLDAPAuthenticator);
    }

    // TODO: Validate config data here!
    lConfigLoaded = true;

    if (!lConfigLoaded) {
        mLog.error("Config not loaded.");
        System.exit(1);
    }

    mLog.info("Using: " + lBrokerURL + ", " + "topic: " + lGatewayTopic + ", " + "gateway-id: " + lGatewayId
            + ", " + "endpoint-id: " + lEndPointId);

    // todo: Comment that for production purposes
    JMSLogging.setFullTextLogging(lFullTextLogging);

    // instantiate a new jWebSocket JMS Gateway Client
    try {
        lJWSEndPoint = JWSEndPoint.getInstance(lBrokerURL, lGatewayTopic, // gateway topic
                lGatewayId, // gateway endpoint id
                lEndPointId, // unique node id
                5, // thread pool size, messages being processed concurrently
                JMSEndPoint.TEMPORARY // durable (for servers) or temporary (for clients)
        );
    } catch (JMSException lEx) {
        mLog.fatal("JMSEndpoint could not be instantiated: " + lEx.getMessage());
        System.exit(0);
    }

    lJWSEndPoint.addRequestListener("org.jwebsocket.jms.gateway", "welcome",
            new JWSMessageListener(lJWSEndPoint) {
                @Override
                public void processToken(String aSourceId, Token aToken) {
                    mLog.info("Received 'welcome', authenticating against jWebSocket...");
                    Token lToken = TokenFactory.createToken("org.jwebsocket.plugins.system", "login");
                    lToken.setString("username", lJWSUsername);
                    lToken.setString("password", lJWSPassword);
                    sendToken(aSourceId, lToken);
                }
            });

    // on response of the login...
    lJWSEndPoint.addResponseListener("org.jwebsocket.plugins.system", "login",
            new JWSMessageListener(lJWSEndPoint) {
                @Override
                public void processToken(String aSourceId, Token aToken) {
                    int lCode = aToken.getInteger("code", -1);
                    if (0 == lCode) {
                        if (mLog.isInfoEnabled()) {
                            mLog.info("Authentication against jWebSocket successful.");
                        }
                    } else {
                        mLog.error("Authentication against jWebSocket failed!");
                    }
                }
            });

    // adding service 'getTime' command implementation ...
    lJWSEndPoint.addRequestListener("somecompany.service.clock", "getTime",
            new JWSMessageListener(lJWSEndPoint) {
                @Override
                public void processToken(String aSourceId, Token aToken) {
                    try {
                        String lUser = lAuthenticator.authenticate(aToken);
                        if (null == lUser) {
                            lJWSEndPoint.respondPayload(aToken, -1, // return code
                                    "access denied", // return message
                                    null, null);
                        } else {
                            if (mLog.isInfoEnabled()) {
                                mLog.info("Processing 'getTime' request from '" + lUser + "' user...");
                            }
                            lJWSEndPoint.respondPayload(aToken, 0, // return code
                                    "OK", // return message
                                    new MapAppender().append("time", System.currentTimeMillis()).getMap(),
                                    null);
                        }
                    } catch (JMSEndpointException lEx) {
                        mLog.error("Unexpected error during service request processing", lEx);
                    }
                }
            });

    // on response of the login...
    lJWSEndPoint.addRequestListener("org.jwebsocket.jms.demo", "echo", new JWSMessageListener(lJWSEndPoint) {
        @Override
        public void processToken(String aSourceId, Token aToken) {
            String lPayload = aToken.getString("payload");
            if (mLog.isInfoEnabled()) {
                mLog.info("Processing 'demo1 with Payload '" + lPayload + "'");
            }
            Map<String, Object> lAdditionalResults = new FastMap<String, Object>();
            lAdditionalResults.putAll(aToken.getMap());
            // lAdditionalResults.remove("sourceId");
            lAdditionalResults.remove("payload");
            lJWSEndPoint.respondPayload(aToken, 0, // return code
                    "Ok", // return message
                    lAdditionalResults, aToken.getString("payload"));
        }
    });

    // on response of the login...
    lJWSEndPoint.addRequestListener("org.jwebsocket.jms.demo", "testProgress",
            new JWSMessageListener(lJWSEndPoint) {
                @Override
                @SuppressWarnings("SleepWhileInLoop")
                public void processToken(String aSourceId, Token aToken) {
                    int lMax = 10;
                    for (int lIdx = 0; lIdx < lMax; lIdx++) {
                        mLog.debug("Progress iteration " + lIdx + "...");
                        try {
                            Thread.sleep(333);
                        } catch (InterruptedException lEx) {
                        }
                        lJWSEndPoint.sendProgress(aToken, ((lIdx + 1.0) / lMax) * 100, 0, "Iteration #" + lIdx,
                                null);
                    }
                    lJWSEndPoint.respondPayload(aToken, 0, // return code
                            "Ok", // return message
                            null, aToken.getString("payload"));
                }
            });

    // start the endpoint all all listener have been assigned
    lJWSEndPoint.start();
    return lJWSEndPoint;
}

From source file:org.openhie.openempi.notification.impl.NotificationServiceImpl.java

public void unregisterListener(String eventTypeName, MessageHandler handler) {
    if (brokerService == null || !brokerInitialized) {
        log.debug("The broker service is not running in unregisterListener.");
        return;//w  ww. j  a  v  a2s . c o m
    }

    log.info("Unregistering handler for event " + eventTypeName);
    if (!isValidHandler(handler)) {
        return;
    }

    Topic topic = topicMap.get(eventTypeName);
    if (topic == null) {
        log.error("Caller attempted to unregister interest to events of unknown type " + eventTypeName);
        throw new RuntimeException("Unknown event type specified in un-registration request.");
    }

    MessageListenerImpl listener = lookupMessageListener(handler, eventTypeName);
    if (listener == null) {
        log.warn("Caller attempted to unregister a listener that is not known to the system: "
                + buildMapKey(handler, eventTypeName));
        return;
    }

    try {
        listener.getConnection().stop();
        listener.getSubscriber().close();
        listener.getSession().unsubscribe(topic.getTopicName());
        listener.getSession().close();
    } catch (JMSException e) {
        log.error("Failed while unregistering a listener. Error: " + e, e);
        throw new RuntimeException("Unable to unregister a listener for event notification: " + e.getMessage());
    }
}

From source file:be.fedict.trust.service.bean.TrustDomainServiceBean.java

public void coldStart(String crlText) {
    LOG.debug("coldstart from text file: " + crlText);
    if (null == crlText) {
        return;/*  w w w. java 2  s.co  m*/
    }
    if (crlText.isEmpty()) {
        return;
    }

    BufferedReader bufferedReader = new BufferedReader(new StringReader(crlText));

    String crlUrl;
    try {
        while (null != (crlUrl = bufferedReader.readLine())) {
            crlUrl = crlUrl.trim();
            String certUrl = bufferedReader.readLine();
            certUrl = certUrl.trim();
            try {
                this.notificationService.notifyColdStart(crlUrl, certUrl);
            } catch (JMSException e) {
                LOG.error("JMS error: " + e.getMessage(), e);
            }
        }
    } catch (IOException e) {
        LOG.error("error parsing CRL text file: " + e.getMessage(), e);
    }
}

From source file:hermes.renderers.DefaultMessageRenderer.java

/**
 * Show a BytesMessage either as a java object or just a size.
 * // w  w  w.  java 2 s .  co  m
 * @param parent
 * 
 * @param bytesMessage
 * @return
 * @throws JMSException
 * @throws IOException
 * @throws ClassNotFoundException
 */
protected JComponent handleBytesMessage(JScrollPane parent, BytesMessage bytesMessage)
        throws JMSException, IOException, ClassNotFoundException {
    final MyConfig currentConfig = (MyConfig) getConfig();

    JTextArea textPane = new MyTextArea();

    textPane.setEditable(false);
    textPane.setWrapStyleWord(true);
    textPane.setLineWrap(true);
    bytesMessage.reset();

    if (currentConfig.isBytesIsObject()) {
        final byte[] bytes = MessageUtils.asBytes(bytesMessage);
        final ByteArrayInputStream bistream = new ByteArrayInputStream(bytes);
        final ObjectInputStream oistream = new ObjectInputStream(bistream);
        final Object o = oistream.readObject();

        textPane.setText(o.toString());
    } else if (currentConfig.isBytesIsString()) {
        try {
            String text = new String(MessageUtils.asBytes(bytesMessage), currentConfig.getBytesEncoding());
            textPane.setText(text);
            return textPane;
        } catch (JMSException e) {
            textPane.setText(e.getMessage());
        }
    } else {
        HexMessageRenderer renderer = new HexMessageRenderer();
        textPane = (JTextArea) renderer.render(parent, bytesMessage); // Hack.
    }

    textPane.setCaretPosition(0);

    return textPane;
}

From source file:org.sdnmq.jms.PacketHandler.java

@Override
public PacketResult receiveDataPacket(RawPacket inPkt) {
    log.trace("Received data packet.");

    // Convert packet to JSON representation.
    String jsonStr = pktToJSON(inPkt).toString();

    // Send notification to JMS topic.
    TextMessage message;/*from  www  .  ja va  2 s.c om*/
    try {
        if (session != null && publisher != null) {
            message = session.createTextMessage(jsonStr);
            setMsgProperties(message, inPkt);
            log.trace("Publishing the following packet-in event: " + jsonStr);
            publisher.send(message);
        } else {
            log.error("Cannot publish packet-in event. JMS not setup.");
        }
    } catch (JMSException e) {
        log.error("Error while publishing packet-in event: " + e.getMessage());
        return PacketResult.IGNORED;
    }

    // Also let other message handlers process this packet. 
    // If you don't want these services, remove them from
    // the OpenDaylight configuration.
    return PacketResult.KEEP_PROCESSING;
}

From source file:org.openhie.openempi.notification.impl.NotificationServiceImpl.java

public void registerListener(String eventTypeName, MessageHandler handler) {
    if (brokerService == null || !brokerInitialized) {
        log.debug("The broker service is not running in registerListener.");
        return;//from w w w  .  j  a  v a 2s  .com
    }

    log.info("Registering handler for event " + eventTypeName);
    if (!isValidHandler(handler)) {
        return;
    }

    Topic topic = topicMap.get(eventTypeName);
    if (topic == null) {
        log.error("Caller attempted to register interest to events of unknown type " + eventTypeName);
        throw new RuntimeException("Unknown event type specified in registration request.");
    }

    if (isListenerRegistered(handler, eventTypeName)) {
        log.warn("Caller attempted to register interest for the same event again.");
        return;
    }
    ConnectionFactory connectionFactory = jmsTemplate.getConnectionFactory();
    try {
        TopicConnection connection = (TopicConnection) connectionFactory.createConnection();
        if (connection.getClientID() == null) {
            connection.setClientID(handler.getClientId());
        }
        log.debug("Connection is of type " + connection);
        TopicSession topicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        TopicSubscriber subscriber = topicSession.createSubscriber(topic);
        MessageListenerImpl listener = new MessageListenerImpl(connection, topicSession, subscriber, handler);
        saveListenerRegistration(listener, eventTypeName);
        subscriber.setMessageListener(listener);
        connection.start();
    } catch (JMSException e) {
        log.error("Failed while setting up a registrant for notification events. Error: " + e, e);
        throw new RuntimeException("Unable to setup registration for event notification: " + e.getMessage());
    }
}

From source file:org.frameworkset.mq.RequestDispatcher.java

public void send(int destinationType, String destination_, Message message, boolean persistent, int priority,
        long timeToLive, JMSProperties properties) throws JMSException {

    assertStarted();/*from ww  w  . j ava2 s  .c om*/
    MessageProducer producer = null;
    try {
        Destination destination = null;
        //         if (destinationType == MQUtil.TYPE_QUEUE)
        //         {
        //            destination = session.createQueue(destination_);
        //         }
        //         else
        //         {
        //            destination = session.createTopic(destination_);
        //         }

        LOG.debug("send message to " + destination_ + " build destination");
        destination = connection.createDestination(session, destination_, destinationType);
        LOG.debug("send message to " + destination_ + " build destination end.");

        int deliveryMode = persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT;
        producer = session.createProducer(destination);
        if (properties != null)
            MQUtil.initMessage(message, properties);
        producer.send(message, deliveryMode, priority, timeToLive);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Sent! to destination: " + destination + " message: " + message);
        }
        message = null;
    } catch (JMSException e) {
        throw e;
    } catch (Exception e) {
        throw new JMSException(e.getMessage());
    } finally {
        if (producer != null)
            try {
                producer.close();
            } catch (Exception e) {

            }

    }
}

From source file:org.frameworkset.mq.RequestDispatcher.java

public void send(String msg, JMSProperties properties) throws JMSException {

    assertStarted();/*from   w w  w . j a  v  a 2 s.  co m*/
    MessageProducer producer = null;
    try {
        Destination destination = null;

        //         if (this.destinationType == MQUtil.TYPE_QUEUE)
        //         {
        //            destination = session.createQueue(this.destination);
        //         }
        //         else
        //         {
        //            destination = session.createTopic(this.destination);
        //         }

        LOG.debug("send message to " + this.destination + " build destination");
        destination = connection.createDestination(session, this.destination, destinationType);
        LOG.debug("send message to " + this.destination + " build destination end.");

        int deliveryMode = this.persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT;
        producer = session.createProducer(destination);
        Message message = createTextMessage(msg);
        if (properties != null)
            MQUtil.initMessage(message, properties);
        producer.send(message, deliveryMode, this.priovity, this.timetolive);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Sent! to destination: " + destination + " message: " + message);
        }
    } catch (JMSException e) {
        throw e;
    } catch (Exception e) {
        throw new JMSException(e.getMessage());
    } finally {
        if (producer != null)
            try {
                producer.close();
            } catch (Exception e) {

            }

    }

}

From source file:org.frameworkset.mq.RequestDispatcher.java

public void send(int destinationType, String destination_, boolean persistent, int priority, long timeToLive,
        Message message, JMSProperties properties) throws JMSException {

    LOG.debug("send message to " + destination_ + " assertStarted(),message=" + message);
    assertStarted();//from   w  w  w . ja  va  2 s.  c  o m
    MessageProducer producer = null;
    try {
        Destination destination = null;
        //         destinationType = JMSConnectionFactory.evaluateDestinationType(destination_, destinationType);

        //         destination_ = JMSConnectionFactory.evaluateDestination(destination_);
        //         boolean isqueue = destinationType == MQUtil.TYPE_QUEUE;
        //         if (isqueue)
        //         {
        //            LOG.debug("send message to " + destination_
        //                  + " build QUEUE destination");
        //            destination = session.createQueue(destination_);
        //            LOG.debug("send message to " + destination_
        //                  + " build QUEUE destination end");
        //         }
        //         else
        //         {
        //            LOG.debug("send message to " + destination_
        //                  + " build Topic destination");
        //            destination = session.createTopic(destination_);
        //            LOG.debug("send message to " + destination_
        //                  + " build Topic destination end");
        //         }
        LOG.debug("send message to " + destination_ + " build destination");
        destination = connection.createDestination(session, destination_, destinationType);
        LOG.debug("send message to " + destination_ + " build destination end.");
        int deliveryMode = persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT;
        LOG.debug("send message to " + destination_ + " this.client.isPersistent =" + persistent);
        LOG.debug("send message to " + destination + " send started....");
        producer = session.createProducer(destination);
        if (properties != null)
            MQUtil.initMessage(message, properties);
        producer.send(message, deliveryMode, priority, timeToLive);
        LOG.debug("send message to " + destination + " send end....");
        if (LOG.isDebugEnabled()) {
            LOG.debug("Sent! to destination: " + destination + " message: " + message);
        }
    } catch (JMSException e) {
        throw e;
    } catch (Exception e) {
        throw new JMSException(e.getMessage());
    } finally {
        if (producer != null)
            try {
                producer.close();
            } catch (Exception e) {

            }

    }
}

From source file:org.openhie.openempi.notification.impl.NotificationServiceImpl.java

public void registerListener(List<String> eventTypeNames, MessageHandler handler) {
    if (brokerService == null || !brokerInitialized) {
        log.debug("The broker service is not running in registerListener.");
        return;//from  w w  w.j  a v  a2 s  .co m
    }

    if (!isValidHandler(handler)) {
        return;
    }

    ConnectionFactory connectionFactory = jmsTemplate.getConnectionFactory();
    Connection connection = null;
    try {
        connection = connectionFactory.createConnection();
        connection.setClientID(handler.getClientId());
    } catch (JMSException e) {
        log.error("Failed while setting up a registrant for notification events. Error: " + e, e);
        throw new RuntimeException("Unable to setup registration for event notification: " + e.getMessage());
    }

    for (String eventTypeName : eventTypeNames) {
        log.info("Registering handler for event " + eventTypeName);
        Topic topic = topicMap.get(eventTypeName);
        if (topic == null) {
            log.error("Caller attempted to register interest to events of unknown type " + eventTypeName);
            throw new RuntimeException("Unknown event type specified in registration request.");
        }

        if (isListenerRegistered(handler, eventTypeName)) {
            log.warn("Caller attempted to register interest for the same event again.");
            return;
        }

        try {
            Session topicSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            TopicSubscriber subscriber = topicSession.createDurableSubscriber(topic, topic.getTopicName());
            MessageListenerImpl listener = new MessageListenerImpl(connection, topicSession, subscriber,
                    handler);
            saveListenerRegistration(listener, eventTypeName);
            subscriber.setMessageListener(listener);
        } catch (JMSException e) {
            log.error("Failed while setting up a registrant for notification events. Error: " + e, e);
            throw new RuntimeException(
                    "Unable to setup registration for event notification: " + e.getMessage());
        }
    }

    try {
        connection.start();
    } catch (JMSException e) {
        log.error("Failed while setting up a registrant for notification events. Error: " + e, e);
        throw new RuntimeException("Unable to setup registration for event notification: " + e.getMessage());
    }
}