List of usage examples for javax.jms MapMessage setBoolean
void setBoolean(String name, boolean value) throws JMSException;
From source file:Vendor.java
public void onMessage(Message message) { if (!(message instanceof MapMessage)) { synchronized (supplierLock) { numSuppliers--;/* ww w . j a va 2s .c o m*/ supplierLock.notifyAll(); } try { asyncSession.commit(); return; } catch (JMSException e) { e.printStackTrace(); } } int orderNumber = -1; try { MapMessage componentMessage = (MapMessage) message; orderNumber = componentMessage.getInt("VendorOrderNumber"); Order order = Order.getOrder(orderNumber); order.processSubOrder(componentMessage); asyncSession.commit(); if (!"Pending".equals(order.getStatus())) { System.out.println("Vendor: Completed processing for order " + orderNumber); MessageProducer replyProducer = asyncSession.createProducer(order.getMessage().getJMSReplyTo()); MapMessage replyMessage = asyncSession.createMapMessage(); if ("Fulfilled".equals(order.getStatus())) { replyMessage.setBoolean("OrderAccepted", true); System.out.println("Vendor: sent " + order.quantity + " computer(s)"); } else { replyMessage.setBoolean("OrderAccepted", false); System.out.println("Vendor: unable to send " + order.quantity + " computer(s)"); } replyProducer.send(replyMessage); asyncSession.commit(); System.out.println("Vender: committed transaction 2"); } } catch (JMSException e) { e.printStackTrace(); } }
From source file:hermes.impl.DefaultXMLHelper.java
public Message createMessage(MessageFactory hermes, XMLMessage message) throws JMSException, IOException, ClassNotFoundException, DecoderException { try {//from w ww . j a v a 2s .c om Message rval = hermes.createMessage(); if (message instanceof XMLTextMessage) { rval = hermes.createTextMessage(); XMLTextMessage textMessage = (XMLTextMessage) message; TextMessage textRval = (TextMessage) rval; if (BASE64_CODEC.equals(textMessage.getCodec())) { byte[] bytes = base64EncoderTL.get().decode(textMessage.getText().getBytes()); textRval.setText(new String(bytes, "ASCII")); } else { textRval.setText(textMessage.getText()); } } else if (message instanceof XMLMapMessage) { rval = hermes.createMapMessage(); XMLMapMessage mapMessage = (XMLMapMessage) message; MapMessage mapRval = (MapMessage) rval; for (Iterator iter = mapMessage.getBodyProperty().iterator(); iter.hasNext();) { final Property property = (Property) iter.next(); if (property.getValue() == null) { mapRval.setObject(property.getName(), null); } else if (property.getType().equals(String.class.getName())) { mapRval.setString(property.getName(), property.getValue()); } else if (property.getType().equals(Long.class.getName())) { mapRval.setLong(property.getName(), Long.parseLong(property.getValue())); } else if (property.getType().equals(Double.class.getName())) { mapRval.setDouble(property.getName(), Double.parseDouble(property.getValue())); } else if (property.getType().equals(Boolean.class.getName())) { mapRval.setBoolean(property.getName(), Boolean.getBoolean(property.getValue())); } else if (property.getType().equals(Character.class.getName())) { mapRval.setChar(property.getName(), property.getValue().charAt(0)); } else if (property.getType().equals(Short.class.getName())) { mapRval.setShort(property.getName(), Short.parseShort(property.getValue())); } else if (property.getType().equals(Integer.class.getName())) { mapRval.setInt(property.getName(), Integer.parseInt(property.getValue())); } } } else if (message instanceof XMLBytesMessage) { rval = hermes.createBytesMessage(); XMLBytesMessage bytesMessage = (XMLBytesMessage) message; BytesMessage bytesRval = (BytesMessage) rval; bytesRval.writeBytes(base64EncoderTL.get().decode(bytesMessage.getBytes().getBytes())); } else if (message instanceof XMLObjectMessage) { rval = hermes.createObjectMessage(); XMLObjectMessage objectMessage = (XMLObjectMessage) message; ObjectMessage objectRval = (ObjectMessage) rval; ByteArrayInputStream bistream = new ByteArrayInputStream( base64EncoderTL.get().decode(objectMessage.getObject().getBytes())); ObjectInputStream oistream = new ObjectInputStream(bistream); objectRval.setObject((Serializable) oistream.readObject()); } // // JMS Header properties try { rval.setJMSDeliveryMode(message.getJMSDeliveryMode()); } catch (JMSException ex) { log.error("unable to set JMSDeliveryMode to " + message.getJMSDeliveryMode() + ": " + ex.getMessage()); } try { rval.setJMSMessageID(message.getJMSMessageID()); } catch (JMSException ex) { log.error("unable to set JMSMessageID: " + ex.getMessage(), ex); } try { if (message.getJMSExpiration() != null) { rval.setJMSExpiration(message.getJMSExpiration()); } } catch (JMSException ex) { log.error("unable to set JMSExpiration: " + ex.getMessage(), ex); } try { if (message.getJMSPriority() != null) { rval.setJMSPriority(message.getJMSPriority()); } } catch (JMSException ex) { log.error("unable to set JMSPriority: " + ex.getMessage(), ex); } try { if (message.getJMSTimestamp() != null) { rval.setJMSTimestamp(message.getJMSTimestamp()); } } catch (JMSException ex) { log.error("unable to set JMSTimestamp:" + ex.getMessage(), ex); } if (message.getJMSCorrelationID() != null) { rval.setJMSCorrelationID(message.getJMSCorrelationID()); } if (message.getJMSReplyTo() != null && !message.getJMSReplyTo().equals("null")) { rval.setJMSReplyTo(hermes.getDestination(message.getJMSReplyTo(), Domain.getDomain(message.getJMSReplyToDomain()))); } if (message.getJMSType() != null) { rval.setJMSType(message.getJMSType()); } if (message.getJMSDestination() != null) { if (message.isFromQueue()) { rval.setJMSDestination(hermes.getDestination(message.getJMSDestination(), Domain.QUEUE)); } else { rval.setJMSDestination(hermes.getDestination(message.getJMSDestination(), Domain.TOPIC)); } } for (Iterator iter = message.getHeaderProperty().iterator(); iter.hasNext();) { Property property = (Property) iter.next(); if (property.getValue() == null) { rval.setObjectProperty(property.getName(), null); } else if (property.getType().equals(String.class.getName())) { rval.setStringProperty(property.getName(), StringEscapeUtils.unescapeXml(property.getValue())); } else if (property.getType().equals(Long.class.getName())) { rval.setLongProperty(property.getName(), Long.parseLong(property.getValue())); } else if (property.getType().equals(Double.class.getName())) { rval.setDoubleProperty(property.getName(), Double.parseDouble(property.getValue())); } else if (property.getType().equals(Boolean.class.getName())) { rval.setBooleanProperty(property.getName(), Boolean.parseBoolean(property.getValue())); } else if (property.getType().equals(Short.class.getName())) { rval.setShortProperty(property.getName(), Short.parseShort(property.getValue())); } else if (property.getType().equals(Integer.class.getName())) { rval.setIntProperty(property.getName(), Integer.parseInt(property.getValue())); } } return rval; } catch (NamingException e) { throw new HermesException(e); } }
From source file:com.espertech.esperio.jms.JMSDefaultMapMessageMarshaller.java
public Message marshal(EventBean eventBean, Session session, long timestamp) throws EPException { EventType eventType = eventBean.getEventType(); MapMessage mapMessage = null; try {/* w w w . ja v a 2 s . com*/ mapMessage = session.createMapMessage(); String[] properties = eventType.getPropertyNames(); for (String property : properties) { if ((ExecutionPathDebugLog.isDebugEnabled) && (log.isDebugEnabled())) { log.debug( ".Marshal EventProperty property==" + property + ", value=" + eventBean.get(property)); } Class clazz = eventType.getPropertyType(property); if (JavaClassHelper.isNumeric(clazz)) { Class boxedClazz = JavaClassHelper.getBoxedType(clazz); if (boxedClazz == Double.class) { mapMessage.setDouble(property, (Double) eventBean.get(property)); } if (boxedClazz == Float.class) { mapMessage.setFloat(property, (Float) eventBean.get(property)); } if (boxedClazz == Byte.class) { mapMessage.setFloat(property, (Byte) eventBean.get(property)); } if (boxedClazz == Short.class) { mapMessage.setShort(property, (Short) eventBean.get(property)); } if (boxedClazz == Integer.class) { mapMessage.setInt(property, (Integer) eventBean.get(property)); } if (boxedClazz == Long.class) { mapMessage.setLong(property, (Long) eventBean.get(property)); } } else if ((clazz == boolean.class) || (clazz == Boolean.class)) { mapMessage.setBoolean(property, (Boolean) eventBean.get(property)); } else if ((clazz == Character.class) || (clazz == char.class)) { mapMessage.setChar(property, (Character) eventBean.get(property)); } else if (clazz == String.class) { mapMessage.setString(property, (String) eventBean.get(property)); } else { mapMessage.setObject(property, eventBean.get(property)); } } mapMessage.setJMSTimestamp(timestamp); } catch (JMSException ex) { throw new EPException(ex); } return mapMessage; }
From source file:org.gss_project.gss.server.ejb.AdminAPIBean.java
public void indexFile(Long fileId, boolean delete) { Connection qConn = null;/*from w ww . j a va 2s . c o m*/ Session session = null; MessageProducer sender = null; try { Context jndiCtx = new InitialContext(); ConnectionFactory factory = (QueueConnectionFactory) jndiCtx.lookup("java:/JmsXA"); Queue queue = (Queue) jndiCtx.lookup("queue/gss-indexingQueue"); qConn = factory.createConnection(); session = qConn.createSession(false, Session.AUTO_ACKNOWLEDGE); sender = session.createProducer(queue); MapMessage map = session.createMapMessage(); map.setObject("id", fileId); map.setBoolean("delete", delete); sender.send(map); } catch (NamingException e) { logger.error("Index was not updated: ", e); } catch (JMSException e) { logger.error("Index was not updated: ", e); } finally { try { if (sender != null) sender.close(); if (session != null) session.close(); if (qConn != null) qConn.close(); } catch (JMSException e) { logger.warn(e); } } }
From source file:org.gss_project.gss.server.ejb.ExternalAPIBean.java
private void indexFile(Long fileId, boolean delete) { Connection qConn = null;/*from w ww. j av a 2s .c o m*/ Session session = null; MessageProducer sender = null; try { Context jndiCtx = new InitialContext(); ConnectionFactory factory = (QueueConnectionFactory) jndiCtx.lookup("java:/JmsXA"); Queue queue = (Queue) jndiCtx.lookup("queue/gss-indexingQueue"); qConn = factory.createConnection(); session = qConn.createSession(false, Session.AUTO_ACKNOWLEDGE); sender = session.createProducer(queue); MapMessage map = session.createMapMessage(); map.setObject("id", fileId); map.setBoolean("delete", delete); sender.send(map); } catch (NamingException e) { logger.error("Index was not updated: ", e); } catch (JMSException e) { logger.error("Index was not updated: ", e); } finally { try { if (sender != null) sender.close(); if (session != null) session.close(); if (qConn != null) qConn.close(); } catch (JMSException e) { logger.warn(e); } } }