当前位置: 首页>>代码示例>>Java>>正文


Java MapMessage.getMapNames方法代码示例

本文整理汇总了Java中javax.jms.MapMessage.getMapNames方法的典型用法代码示例。如果您正苦于以下问题:Java MapMessage.getMapNames方法的具体用法?Java MapMessage.getMapNames怎么用?Java MapMessage.getMapNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.jms.MapMessage的用法示例。


在下文中一共展示了MapMessage.getMapNames方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: print

import javax.jms.MapMessage; //导入方法依赖的package包/类
public static void print(Message msg) throws JMSException {
    log.info(".print received message: " + msg.getJMSMessageID());
    if (msg instanceof ObjectMessage) {
        ObjectMessage objMsg = (ObjectMessage) msg;
        log.info(".print object: " + objMsg.getObject().toString());
    } else {
        MapMessage mapMsg = (MapMessage) msg;
        HashMap map = new HashMap();
        Enumeration en = mapMsg.getMapNames();
        while (en.hasMoreElements()) {
            String property = (String) en.nextElement();
            Object mapObject = mapMsg.getObject(property);
            map.put(property, mapObject);
        }
        log.info(".print map: " + map);
    }
}
 
开发者ID:espertechinc,项目名称:esper,代码行数:18,代码来源:SupportJMSReceiver.java

示例2: extractMapFromMessage

import javax.jms.MapMessage; //导入方法依赖的package包/类
/**
 * Extract a Map from the given {@link MapMessage}.
 * @param message the message to convert
 * @return the resulting Map
 * @throws JMSException if thrown by JMS methods
 */
@SuppressWarnings("unchecked")
protected Map<String, Object> extractMapFromMessage(MapMessage message) throws JMSException {
	Map<String, Object> map = new HashMap<String, Object>();
	Enumeration<String> en = message.getMapNames();
	while (en.hasMoreElements()) {
		String key = en.nextElement();
		map.put(key, message.getObject(key));
	}
	return map;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:SimpleMessageConverter.java

示例3: saveMessagePayload

import javax.jms.MapMessage; //导入方法依赖的package包/类
private void saveMessagePayload(Message msg, String baseName) throws JMSException, IOException {
    try (FileOutputStream fos = new FileOutputStream(new File(_messageFileDirectory, baseName + ".payload"))) {
        byte[] payload;
        if (msg instanceof TextMessage) {
            payload = TextMessageData.textToBytes(((TextMessage) msg).getText());
        }
        else if (msg instanceof BytesMessage) {
            BytesMessage bytesMessage = (BytesMessage) msg;
            payload = new byte[(int) bytesMessage.getBodyLength()];
            bytesMessage.readBytes(payload);
        }
        else if (msg instanceof ObjectMessage) {
            payload = _objectMessageAdapter.getObjectPayload((ObjectMessage) msg);
        }
        else if (msg instanceof MapMessage) {
            // Partial support, not all data types are handled and we may not be able to post
            MapMessage mapMessage = (MapMessage) msg;
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            Properties props = new Properties();
            for (Enumeration<?> mapNames = mapMessage.getMapNames(); mapNames.hasMoreElements();) {
                String mapName = mapNames.nextElement().toString();
                props.setProperty(mapName, mapMessage.getObject(mapName).toString());
            }
            props.store(bos, "Map message properties for " + msg.getJMSMessageID());
            payload = bos.toByteArray();
        }
        else if (msg instanceof StreamMessage) {
            _logger.warn("Can't save payload for {}, stream messages not supported!", msg.getJMSMessageID());
            payload = new byte[0];
        }
        else {
            _logger.warn("Can't save payload for {}, unsupported type {}!", msg.getJMSMessageID(),
                msg.getClass().getName());
            payload = new byte[0];
        }
        fos.write(payload);
        fos.flush();
    }
}
 
开发者ID:erik-wramner,项目名称:JmsTools,代码行数:40,代码来源:DequeueWorker.java

示例4: createMapFromMapMessage

import javax.jms.MapMessage; //导入方法依赖的package包/类
/**
 * Extracts a {@link Map} from a {@link MapMessage}
 */
public Map<String, Object> createMapFromMapMessage(MapMessage message) throws JMSException {
    Map<String, Object> answer = new HashMap<String, Object>();
    Enumeration<?> names = message.getMapNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement().toString();
        Object value = message.getObject(name);
        answer.put(name, value);
    }
    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:14,代码来源:JmsBinding.java

示例5: extractMapFromMessage

import javax.jms.MapMessage; //导入方法依赖的package包/类
/**
 * Extract a Map from the given {@link MapMessage}.
 *
 * @param message the message to convert
 * @return the resulting Map
 * @throws JMSException if thrown by JMS methods
 */
protected Map<String, Object> extractMapFromMessage(MapMessage message) throws JMSException
{
  Map<String, Object> map = new HashMap<String, Object>();
  Enumeration<?> en = message.getMapNames();
  while (en.hasMoreElements()) {
    String key = (String)en.nextElement();
    map.put(key, message.getObject(key));
  }
  return map;
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:18,代码来源:JMSObjectInputOperator.java

示例6: ActiveMQMapMessage

import javax.jms.MapMessage; //导入方法依赖的package包/类
/**
 * Constructor for a foreign MapMessage
 *
 * @param foreign
 * @throws JMSException
 */
public ActiveMQMapMessage(final MapMessage foreign, final ClientSession session) throws JMSException {
   super(foreign, ActiveMQMapMessage.TYPE, session);
   Enumeration<?> names = foreign.getMapNames();
   while (names.hasMoreElements()) {
      String name = (String) names.nextElement();
      Object obj = foreign.getObject(name);
      setObject(name, obj);
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:16,代码来源:ActiveMQMapMessage.java

示例7: resolveMapMessage

import javax.jms.MapMessage; //导入方法依赖的package包/类
public static Map<String, Object> resolveMapMessage(MapMessage mapMessage) throws JMSException {
    Map<String, Object> map = new LinkedHashMap<>();
    for (@SuppressWarnings({"unchecked", "checkstyle:emptyforiteratorpad"})
         Enumeration<String> e = mapMessage.getMapNames(); e.hasMoreElements(); ) {
        String key = e.nextElement();
        map.put(key, mapMessage.getObject(key));
    }
    return map;
}
 
开发者ID:Tibor17,项目名称:javaee-samples,代码行数:10,代码来源:Util.java

示例8: extractContent

import javax.jms.MapMessage; //导入方法依赖的package包/类
private void extractContent(StringBuilder buffer, StringBuilder propBuffer,
        Message msg, boolean isLast) {
    if (msg != null) {
        try {
            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());
        }
    }
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:42,代码来源:SubscriberSampler.java

示例9: unmarshal

import javax.jms.MapMessage; //导入方法依赖的package包/类
public EventBean unmarshal(EventAdapterService eventAdapterService,
                           Message message) throws EPException {
    try {
        if (message instanceof ObjectMessage) {
            ObjectMessage objmsg = (ObjectMessage) message;
            Serializable obj = objmsg.getObject();
            return eventAdapterService.adapterForBean(obj);
        } else if (message instanceof MapMessage) {
            Map<String, Object> properties = new HashMap<String, Object>();
            MapMessage mapMsg = (MapMessage) message;
            Enumeration en = mapMsg.getMapNames();
            while (en.hasMoreElements()) {
                String property = (String) en.nextElement();
                Object mapObject = mapMsg.getObject(property);
                properties.put(property, mapObject);
            }

            // Get event type property
            Object typeProperty = properties.get(InputAdapter.ESPERIO_MAP_EVENT_TYPE);
            if (typeProperty == null) {
                log.warn(".unmarshal Failed to unmarshal map message, expected type property not found: '" + InputAdapter.ESPERIO_MAP_EVENT_TYPE + "'");
                return null;
            }

            // Get event type
            String name = typeProperty.toString();
            EventType eventType = eventAdapterService.getExistsTypeByName(name);
            if (eventType == null) {
                log.warn(".unmarshal Failed to unmarshal map message, event type name '" + name + "' is not a known type");
                return null;
            }

            return eventAdapterService.adapterForTypedMap(properties, eventType);
        } else {
            String error = ".unmarshal Failed to unmarshal message of JMS type: " + message.getJMSType();
            log.error(error);
            throw new EPException(error);
        }
    } catch (JMSException ex) {
        throw new EPException("Error unmarshalling message", ex);
    }
}
 
开发者ID:espertechinc,项目名称:esper,代码行数:43,代码来源:JMSDefaultAnyMessageUnmarshaller.java

示例10: compose

import javax.jms.MapMessage; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public org.switchyard.Message compose(JMSBindingData source, Exchange exchange) throws Exception {
    final org.switchyard.Message syMessage = exchange.createMessage();
    getContextMapper().mapFrom(source, exchange.getContext(syMessage));

    Message jmsMessage = source.getMessage();
    if (jmsMessage instanceof BytesMessage) {
        BytesMessage sourceBytes = BytesMessage.class.cast(jmsMessage);
        if (sourceBytes.getBodyLength() > Integer.MAX_VALUE) {
            throw JCAMessages.MESSAGES.theSizeOfMessageContentExceedsBytesThatIsNotSupportedByThisMessageComposer("" + Integer.MAX_VALUE);
        }
        byte[] bytearr = new byte[(int)sourceBytes.getBodyLength()];
        sourceBytes.readBytes(bytearr);
        syMessage.setContent(bytearr);

    } else if (jmsMessage instanceof MapMessage) {
        MapMessage sourceMap = MapMessage.class.cast(jmsMessage);
        Map<String,Object> body = new HashMap<String,Object>();
        Enumeration<?> e = sourceMap.getMapNames();
        while (e.hasMoreElements()) {
            String key = String.class.cast(e.nextElement());
            body.put(key, sourceMap.getObject(key));
        }
        syMessage.setContent(body);
        
     } else if (jmsMessage instanceof ObjectMessage) {
         ObjectMessage sourceObj = ObjectMessage.class.cast(jmsMessage);
         syMessage.setContent(sourceObj.getObject());
         
    } else if (jmsMessage instanceof StreamMessage) {
        StreamMessage sourceStream = StreamMessage.class.cast(jmsMessage);
        syMessage.setContent(sourceStream);
        
    } else if (jmsMessage instanceof TextMessage) {
        TextMessage sourceText = TextMessage.class.cast(jmsMessage);
        syMessage.setContent(sourceText.getText());
        
    } else {
        // plain javax.jms.Message doesn't have body content
        syMessage.setContent(null);
    }

    return syMessage;
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:48,代码来源:JMSMessageComposer.java


注:本文中的javax.jms.MapMessage.getMapNames方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。