List of usage examples for javax.jms JMSException getMessage
public String getMessage()
From source file:org.sdnmq.jms.PacketHandler.java
/** * Sets message properties according to UDP datagram header fields. * /*from w w w . j a v a 2 s. c om*/ * @param udp the UDP datagram * @param msg the message to which the information will be added */ private void udpToProperties(UDP udp, Message msg) { try { msg.setShortProperty(MessageFilterAttributes.Keys.TP_SRC.toFilterName(), udp.getSourcePort()); } catch (JMSException e) { log.error(e.getMessage()); } try { msg.setShortProperty(MessageFilterAttributes.Keys.TP_DST.toFilterName(), udp.getDestinationPort()); } catch (JMSException e) { log.error(e.getMessage()); } }
From source file:org.sdnmq.jms.PacketHandler.java
/** * Adds message properties according to Ethernet header fields. * //w w w . j a v a2 s . c om * @param ethernet the Ethernet frame * @param msg the message object to which the information will be added */ private void ethernetToProperties(Ethernet ethernet, Message msg) { try { msg.setStringProperty(MessageFilterAttributes.Keys.DL_SRC.toFilterName(), Netutil.macToStr(ethernet.getSourceMACAddress())); } catch (JMSException e) { log.error(e.getMessage()); } try { msg.setStringProperty(MessageFilterAttributes.Keys.DL_DST.toFilterName(), Netutil.macToStr(ethernet.getDestinationMACAddress())); } catch (JMSException e) { log.error(e.getMessage()); } try { msg.setShortProperty(MessageFilterAttributes.Keys.DL_TYPE.toFilterName(), ethernet.getEtherType()); } catch (JMSException e) { log.error(e.getMessage()); } }
From source file:org.sdnmq.jms.PacketHandler.java
/** * Adds message properties according to IPv4 header fields. * /*w w w. j ava2s .c o m*/ * @param ipv4 the IPv4 packet * @param msg the message whose properties are set */ private void ipv4ToProperties(IPv4 ipv4, Message msg) { try { msg.setStringProperty(MessageFilterAttributes.Keys.NW_SRC.toFilterName(), Netutil.ipv4ToStr(ipv4.getSourceAddress())); msg.setStringProperty(MessageFilterAttributes.Keys.NW_SRC_BINARY.toFilterName(), Netutil.ipv4ToBinaryStr(ipv4.getSourceAddress())); } catch (JMSException e) { log.error(e.getMessage()); } try { msg.setStringProperty(MessageFilterAttributes.Keys.NW_DST.toFilterName(), Netutil.ipv4ToStr(ipv4.getDestinationAddress())); msg.setStringProperty(MessageFilterAttributes.Keys.NW_DST_BINARY.toFilterName(), Netutil.ipv4ToBinaryStr(ipv4.getDestinationAddress())); } catch (JMSException e) { log.error(e.getMessage()); } try { msg.setShortProperty(MessageFilterAttributes.Keys.NW_PROTOCOL.toFilterName(), (short) ipv4.getProtocol()); } catch (JMSException e) { log.error(e.getMessage()); } }
From source file:org.grouter.common.jms.QueueListenerDestination.java
/** * Connect to queue and open a session. *///from w w w.j a va 2 s . c o m @Override public void bind() { try { // Find ConnectionFactory final QueueConnectionFactory queueConnectionFactory = getInstance() .getQueueConnectionFactory(connectionFactory, context); // Get queue queue = getInstance().getQueue(destinationName, context); // Create conneciton to queue queueConnection = queueConnectionFactory.createQueueConnection(); // Register an exceptionlistener queueConnection.setExceptionListener(exceptionListener); queueSession = queueConnection.createQueueSession(isTransactional, acknowledgeMode); messageConsumer = queueSession.createReceiver(queue); // Sets the receiver which onMessage method will be called. messageConsumer.setMessageListener(listener); queueConnection.start(); logger.info("Bound to destination " + destinationName); } catch (JMSException e) { logger.error("Got exception with JMS provider during bind to destination " + destinationName + ". Got error message :" + e.getMessage()); rebind(this); } catch (ServiceLocatorException ex) { logger.error("Got exception with JMS provider during bind to destination " + destinationName + ". Got error message : " + ex.getMessage()); rebind(this); } }
From source file:org.sakaiproject.nakamura.email.outgoing.OutgoingEmailMessageListener.java
protected void activate(ComponentContext ctx) { @SuppressWarnings("rawtypes") Dictionary props = ctx.getProperties(); Integer _maxRetries = (Integer) props.get(MAX_RETRIES); if (_maxRetries != null) { if (diff(maxRetries, _maxRetries)) { maxRetries = _maxRetries;//from www . j a va2 s . c o m } } else { LOGGER.error("Maximum times to retry messages not set."); } Integer _retryInterval = (Integer) props.get(RETRY_INTERVAL); if (_retryInterval != null) { if (diff(_retryInterval, retryInterval)) { retryInterval = _retryInterval; } } else { LOGGER.error("SMTP retry interval not set."); } if (maxRetries * retryInterval < 4320 /* minutes in 3 days */) { LOGGER.warn("SMTP retry window is very short."); } Integer _smtpPort = (Integer) props.get(SMTP_PORT); boolean validPort = _smtpPort != null && _smtpPort >= 0 && _smtpPort <= 65535; if (validPort) { if (diff(smtpPort, _smtpPort)) { smtpPort = _smtpPort; } } else { LOGGER.error("Invalid port set for SMTP"); } String _smtpServer = (String) props.get(SMTP_SERVER); boolean smtpServerEmpty = _smtpServer == null || _smtpServer.trim().length() == 0; if (!smtpServerEmpty) { if (diff(smtpServer, _smtpServer)) { smtpServer = _smtpServer; } } else { LOGGER.error("No SMTP server set"); } try { connection = connFactoryService.getDefaultConnectionFactory().createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue dest = session.createQueue(QUEUE_NAME); MessageConsumer consumer = session.createConsumer(dest); consumer.setMessageListener(this); connection.start(); } catch (JMSException e) { LOGGER.error(e.getMessage(), e); if (connection != null) { try { connection.close(); } catch (JMSException e1) { } } } }
From source file:org.sdnmq.jms.PacketHandler.java
/** * Sets the properties of the message according to the message header fields for content-based filtering. * //from www . j ava 2 s .c o m * @param msg the message whose properties are set * @param pkt the packet from where the message properties are derived */ private void setMsgProperties(Message msg, RawPacket rawPkt) { // The connector, the packet came from ("port") NodeConnector ingressConnector = rawPkt.getIncomingNodeConnector(); // The node that received the packet ("switch") Node node = ingressConnector.getNode(); try { msg.setStringProperty(MessageFilterAttributes.Keys.NODE_ID.toFilterName(), node.getNodeIDString()); msg.setStringProperty(MessageFilterAttributes.Keys.NODE_TYPE.toFilterName(), node.getType()); } catch (JMSException e) { log.error(e.getMessage()); } try { msg.setStringProperty(MessageFilterAttributes.Keys.INPORT.toFilterName(), ingressConnector.getNodeConnectorIDString()); } catch (JMSException e) { log.error(e.getMessage()); } // Use DataPacketService to decode the packet. Packet pkt = dataPacketService.decodeDataPacket(rawPkt); while (pkt != null) { if (pkt instanceof Ethernet) { Ethernet ethernet = (Ethernet) pkt; ethernetToProperties(ethernet, msg); } else if (pkt instanceof IEEE8021Q) { IEEE8021Q ieee802q = (IEEE8021Q) pkt; ieee8021qToProperties(ieee802q, msg); } else if (pkt instanceof IPv4) { IPv4 ipv4 = (IPv4) pkt; ipv4ToProperties(ipv4, msg); } else if (pkt instanceof TCP) { TCP tcp = (TCP) pkt; tcpToProperties(tcp, msg); } else if (pkt instanceof UDP) { UDP udp = (UDP) pkt; udpToProperties(udp, msg); } pkt = pkt.getPayload(); } }
From source file:org.apache.jmeter.protocol.jms.sampler.SubscriberSampler.java
private void extractContent(StringBuilder buffer, StringBuilder propBuffer, Message msg, boolean isLast) { if (msg != null) { try {//from ww w. j a va2 s .co m if (msg instanceof TextMessage) { buffer.append(((TextMessage) msg).getText()); } else if (msg instanceof ObjectMessage) { ObjectMessage objectMessage = (ObjectMessage) msg; if (objectMessage.getObject() != null) { buffer.append(objectMessage.getObject().getClass()); } else { buffer.append("object is null"); } } else if (msg instanceof BytesMessage) { BytesMessage bytesMessage = (BytesMessage) msg; buffer.append(bytesMessage.getBodyLength() + " bytes received in BytesMessage"); } else if (msg instanceof MapMessage) { MapMessage mapm = (MapMessage) msg; @SuppressWarnings("unchecked") // MapNames are Strings Enumeration<String> enumb = mapm.getMapNames(); while (enumb.hasMoreElements()) { String name = enumb.nextElement(); Object obj = mapm.getObject(name); buffer.append(name); buffer.append(","); buffer.append(obj.getClass().getCanonicalName()); buffer.append(","); buffer.append(obj); buffer.append("\n"); } } Utils.messageProperties(propBuffer, msg); if (!isLast && !StringUtils.isEmpty(separator)) { propBuffer.append(separator); buffer.append(separator); } } catch (JMSException e) { log.error(e.getMessage()); } } }
From source file:be.fedict.trust.service.bean.TrustDomainServiceBean.java
public void coldStart(String crlUrl, String certUrl) { LOG.debug("cold start: " + crlUrl + "; " + certUrl); if (null == crlUrl) { return;/*from ww w. j a va2 s. co m*/ } if (null == certUrl) { return; } if (crlUrl.isEmpty()) { return; } if (certUrl.isEmpty()) { return; } try { this.notificationService.notifyColdStart(crlUrl, certUrl); } catch (JMSException e) { LOG.error("JMS error: " + e.getMessage(), e); } }
From source file:tld.yourname.jms.server.DemoService1.java
/** * * @param aArgs//from w ww.j ava2s .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/DemoService1.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:tld.yourname.jms.server.DemoService2.java
/** * * @param aArgs/*from w w w . j av a 2 s . co 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/DemoService2.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; }