List of usage examples for javax.jms MapMessage setStringProperty
void setStringProperty(String name, String value) throws JMSException;
From source file:org.kuali.student.enrollment.courseoffering.service.EnqueuerCallbackListener.java
public boolean updateCallbacks(String offeringId, String methodName) { try {//from w ww . j av a 2 s . c om MapMessage mapMessage = new ActiveMQMapMessage(); mapMessage.setStringProperty(EVENT_QUEUE_MESSAGE_OFFERING_ID, offeringId); mapMessage.setStringProperty(EVENT_QUEUE_MESSAGE_METHOD_NAME, methodName); jmsTemplate.convertAndSend(EVENT_QUEUE, mapMessage); } catch (JMSException e) { throw new RuntimeException("Error submitting notification.", e); } return true; }
From source file:com.xyxy.platform.examples.showcase.demos.jms.JmsAdvancedTest.java
@Test public void topicMessageWithWrongType() { Threads.sleep(1000);/*from w ww .j a v a 2 s . c o m*/ LogbackListAppender appender = new LogbackListAppender(); appender.addToLogger(AdvancedNotifyMessageListener.class); advancedJmsTemplate.send(advancedNotifyTopic, new MessageCreator() { @Override public Message createMessage(Session session) throws JMSException { MapMessage message = session.createMapMessage(); message.setStringProperty("objectType", "role"); return message; } }); Threads.sleep(1000); assertThat(appender.isEmpty()).isTrue(); }
From source file:com.it.j2ee.jms.JmsAdvancedTest.java
@Test public void topicMessageWithWrongType() throws InterruptedException { Thread.sleep(1000);//from w ww .j ava 2s .c o m LogbackListAppender appender = new LogbackListAppender(); appender.addToLogger(AdvancedNotifyMessageListener.class); advancedJmsTemplate.send(advancedNotifyTopic, new MessageCreator() { public Message createMessage(Session session) throws JMSException { MapMessage message = session.createMapMessage(); message.setStringProperty("objectType", "role"); return message; } }); Thread.sleep(1000); assertThat(appender.isEmpty()).isTrue(); }
From source file:com.xyxy.platform.examples.showcase.demos.jms.advanced.AdvancedNotifyMessageProducer.java
/** * jmsTemplatesend/MessageCreator()??Map?Message?. *//*from w ww.j a v a2 s.c o m*/ private void sendMessage(final User user, Destination destination) { jmsTemplate.send(destination, new MessageCreator() { @Override public Message createMessage(Session session) throws JMSException { MapMessage message = session.createMapMessage(); message.setString("userName", user.getName()); message.setString("email", user.getEmail()); message.setStringProperty("objectType", "user"); return message; } }); }
From source file:com.it.j2ee.modules.jms.advanced.AdvancedNotifyMessageProducer.java
/** * jmsTemplatesend/MessageCreator()??Map?Message?. *///from w w w. jav a 2 s .co m private void sendMessage(final User user, Destination destination) { jmsTemplate.send(destination, new MessageCreator() { public Message createMessage(Session session) throws JMSException { MapMessage message = session.createMapMessage(); message.setString("userName", user.getName()); message.setString("email", user.getEmail()); message.setStringProperty("objectType", "user"); return message; } }); }
From source file:eu.domibus.submission.jms.BackendJMSImpl.java
/** * This method is called when a message was received at the incoming queue * * @param message The incoming JMS Message *//*from w w w . j a v a 2 s . c om*/ @Override public void onMessage(final Message message) { final MapMessage map = (MapMessage) message; try { final Connection con = this.cf.createConnection(); final Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); final MapMessage res = session.createMapMessage(); try { final String messageID = this.submit(map); res.setStringProperty("messageId", messageID); } catch (final TransformationException | ValidationException e) { BackendJMSImpl.LOG.error("Exception occurred: ", e); res.setString("ErrorMessage", e.getMessage()); } res.setJMSCorrelationID(map.getJMSCorrelationID()); final MessageProducer sender = session.createProducer(this.outQueue); sender.setDeliveryMode(DeliveryMode.NON_PERSISTENT); sender.send(res); sender.close(); session.close(); con.close(); } catch (final JMSException ex) { BackendJMSImpl.LOG.error("Error while sending response to queue", ex); } }
From source file:eu.domibus.submission.transformer.impl.JMSMessageTransformer.java
/** * Transforms {@link eu.domibus.submission.Submission} to {@link javax.jms.MapMessage} * * @param submission the message to be transformed * * @return result of the transformation as {@link javax.jms.MapMessage} *//*from w ww .ja va2 s. co m*/ @Override public MapMessage transformFromSubmission(final Submission submission, final MapMessage messageOut) { try { messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_ACTION, submission.getAction()); messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_SERVICE, submission.getService()); messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_CONVERSATION_ID, submission.getConversationId()); for (final Submission.Party fromParty : submission.getFromParties()) { messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_FROM_PARTY_ID, fromParty.getPartyId()); messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_FROM_PARTY_TYPE, fromParty.getPartyIdType()); } for (final Submission.Party toParty : submission.getToParties()) { messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_TO_PARTY_ID, toParty.getPartyId()); messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_TO_PARTY_TYPE, toParty.getPartyIdType()); } messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_FROM_ROLE, submission.getFromRole()); messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_TO_ROLE, submission.getToRole()); for (final Map.Entry p : submission.getMessageProperties().entrySet()) { if (p.getKey().equals(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PROPERTY_ORIGINAL_SENDER)) { messageOut.setStringProperty( JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PROPERTY_ORIGINAL_SENDER, p.getValue().toString()); } if (p.getKey().equals(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PROPERTY_ENDPOINT)) { messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PROPERTY_ENDPOINT, p.getValue().toString()); } if (p.getKey().equals(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PROPERTY_FINAL_RECIPIENT)) { messageOut.setStringProperty( JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PROPERTY_FINAL_RECIPIENT, p.getValue().toString()); } } messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PROTOCOL, "AS4"); messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_AGREEMENT_REF, submission.getAgreementRef()); messageOut.setStringProperty(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_REF_TO_MESSAGE_ID, submission.getRefToMessageId()); int counter = 2; for (final Submission.Payload p : submission.getPayloads()) { if (p.isInBody()) { messageOut.setBytes( MessageFormat .format(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PAYLOAD_NAME_FORMAT, 1), p.getPayloadData()); messageOut.setStringProperty( MessageFormat.format( JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PAYLOAD_MIME_TYPE_FORMAT, 1), p.getPayloadProperties().getProperty(Property.MIME_TYPE)); messageOut.setStringProperty(MessageFormat.format( JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PAYLOAD_MIME_CONTENT_ID_FORMAT, 1), p.getContentId()); if (p.getDescription() != null) { messageOut.setStringProperty(MessageFormat.format( JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PAYLOAD_DESCRIPTION_FORMAT, 1), p.getDescription()); } } else { final String payContID = String.valueOf(MessageFormat.format( JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PAYLOAD_MIME_CONTENT_ID_FORMAT, counter)); final String payDescrip = String.valueOf(MessageFormat.format( JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PAYLOAD_DESCRIPTION_FORMAT, counter)); final String propPayload = String.valueOf(MessageFormat .format(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PAYLOAD_NAME_FORMAT, counter)); final String payMimeTypeProp = String.valueOf(MessageFormat.format( JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_PAYLOAD_MIME_TYPE_FORMAT, counter)); messageOut.setBytes(propPayload, p.getPayloadData()); messageOut.setStringProperty(payMimeTypeProp, p.getPayloadProperties().getProperty(Property.MIME_TYPE)); messageOut.setStringProperty(payContID, p.getContentId()); if (p.getDescription() != null) { messageOut.setStringProperty(payDescrip, p.getDescription()); } counter++; } } messageOut.setInt(JMSMessageTransformer.SUBMISSION_JMS_MAPMESSAGE_TOTAL_NUMBER_OF_PAYLOADS, submission.getPayloads().size()); } catch (final JMSException ex) { JMSMessageTransformer.LOG.error("Error while filling the MapMessage", ex); } return messageOut; }
From source file:org.jwebsocket.plugins.scripting.ScriptingPlugIn.java
/** * Reload a deployed script application. * * @param aConnector//from ww w. j a v a 2 s .c om * @param aToken * @throws Exception */ public void reloadAppAction(WebSocketConnector aConnector, Token aToken) throws Exception { String lAppName = aToken.getString("app"); boolean lHotReload = aToken.getBoolean("hotReload", true); Assert.notNull(lAppName, "The 'app' argument cannot be null!"); Assert.isTrue(mSettings.getApps().containsKey(lAppName), "The target application '" + lAppName + "' does not exists!"); if (!hasAuthority(aConnector, NS + ".reloadApp.*") && !hasAuthority(aConnector, NS + ".reloadApp." + lAppName)) { sendToken(aConnector, createAccessDenied(aToken)); return; } // loading the app String lAppPath = mSettings.getApps().get(lAppName); execAppBeforeLoadChecks(lAppName, lAppPath); loadApp(lAppName, lAppPath, lHotReload); // broadcasting event to other ScriptingPlugIn nodes MapMessage lMessage = getServer().getJMSManager().buildMessage(NS, ClusterMessageTypes.LOAD_APP.name()); lMessage.setStringProperty("appName", lAppName); lMessage.setBooleanProperty("hotLoad", lHotReload); lMessage.setStringProperty(Attributes.NODE_ID, JWebSocketConfig.getConfig().getNodeId()); // sending the message getServer().getJMSManager().send(lMessage); sendToken(aConnector, createResponse(aToken)); }
From source file:org.jwebsocket.plugins.scripting.ScriptingPlugIn.java
/** * Deploy an application/* w w w. j a va2 s . com*/ * * @param aConnector * @param aToken * @throws Exception */ public void deployAction(WebSocketConnector aConnector, Token aToken) throws Exception { // getting calling arguments String lAppFile = aToken.getString("appFile"); boolean lDeleteAfterDeploy = aToken.getBoolean("deleteAfterDeploy", false); boolean lHotDeploy = aToken.getBoolean("hotDeploy", false); // getting the FSP instance TokenPlugIn lFSP = (TokenPlugIn) getPlugInChain().getPlugIn("jws.filesystem"); Assert.notNull(lFSP, "FileSystem plug-in is not running!"); // creating invoke request for FSP Token lCommand = TokenFactory.createToken(JWebSocketServerConstants.NS_BASE + ".plugins.filesystem", "getAliasPath"); lCommand.setString("alias", "privateDir"); Token lResult = lFSP.invoke(aConnector, lCommand); Assert.notNull(lResult, "Unable to communicate with the FileSystem plug-in " + "to retrieve the client private directory!"); // locating the app zip file File lAppZipFile = new File(lResult.getString("aliasPath") + File.separator + lAppFile); Assert.isTrue(lAppZipFile.exists(), "The target application file '" + lAppFile + "' does not exists" + " on the user file-system scope!"); // validating MIME type String lFileType = new MimetypesFileTypeMap().getContentType(lAppZipFile); Assert.isTrue("application/zip, application/octet-stream".contains(lFileType), "The file format is not valid! Expecting a ZIP compressed directory."); // umcompressing in TEMP unique folder File lTempDir = new File(FileUtils.getTempDirectory().getCanonicalPath() + File.separator + UUID.randomUUID().toString() + File.separator); try { Tools.unzip(lAppZipFile, lTempDir); if (lDeleteAfterDeploy) { lAppZipFile.delete(); } } catch (IOException lEx) { throw new Exception("Unable to uncompress zip file: " + lEx.getMessage()); } // validating structure File[] lTempAppDirContent = lTempDir.listFiles((FileFilter) FileFilterUtils.directoryFileFilter()); Assert.isTrue(1 == lTempAppDirContent.length && lTempAppDirContent[0].isDirectory(), "Compressed application has invalid directory structure! " + "Expecting a single root folder."); // executing before-load checks execAppBeforeLoadChecks(lTempAppDirContent[0].getName(), lTempAppDirContent[0].getPath()); // copying application content to apps directory File lAppDir = new File(mSettings.getAppsDirectory() + File.separator + lTempAppDirContent[0].getName()); FileUtils.copyDirectory(lTempAppDirContent[0], lAppDir); FileUtils.deleteDirectory(lTempDir); // getting the application name String lAppName = lAppDir.getName(); // checking security if (!hasAuthority(aConnector, NS + ".deploy.*") && !hasAuthority(aConnector, NS + ".deploy." + lAppName)) { sendToken(aConnector, createAccessDenied(aToken)); return; } // loading the script app loadApp(lAppName, lAppDir.getAbsolutePath(), lHotDeploy); // broadcasting event to other ScriptingPlugIn nodes MapMessage lMessage = getServer().getJMSManager().buildMessage(NS, ClusterMessageTypes.LOAD_APP.name()); lMessage.setStringProperty("appName", lAppName); lMessage.setBooleanProperty("hotLoad", lHotDeploy); lMessage.setStringProperty(Attributes.NODE_ID, JWebSocketConfig.getConfig().getNodeId()); // sending the message getServer().getJMSManager().send(lMessage); // finally send acknowledge response sendToken(aConnector, createResponse(aToken)); }
From source file:org.jwebsocket.plugins.scripting.ScriptingPlugIn.java
/** * Undeploy an application//from w ww. j a va2 s . c om * * @param aConnector * @param aToken * @throws Exception */ public void undeployAction(WebSocketConnector aConnector, Token aToken) throws Exception { // getting calling arguments String lApp = aToken.getString("app"); Assert.notNull(lApp, "The 'app' argument cannot be null!"); // validating BaseScriptApp lScriptApp = mApps.get(lApp); Assert.notNull(lScriptApp, "The target app does not exists!"); // checking security if (!hasAuthority(aConnector, NS + ".deploy.*") && !hasAuthority(aConnector, NS + ".deploy." + lApp)) { sendToken(aConnector, createAccessDenied(aToken)); return; } // notifying event before undeploy lScriptApp.notifyEvent(BaseScriptApp.EVENT_UNDEPLOYING, new Object[0]); // propertly destroying script app active beans destroyAppBeans(lScriptApp); // deleting app mApps.remove(lApp); FileUtils.deleteDirectory(new File(lScriptApp.getPath())); // broadcasting event to other ScriptingPlugIn nodes MapMessage lMessage = getServer().getJMSManager().buildMessage(NS, ClusterMessageTypes.UNDEPLOY_APP.name()); lMessage.setStringProperty("appName", lApp); lMessage.setStringProperty(Attributes.NODE_ID, JWebSocketConfig.getConfig().getNodeId()); // sending the message getServer().getJMSManager().send(lMessage); // acknowledge response for the client sendToken(aConnector, createResponse(aToken)); }