OW2 Consortium joram

Compare Revisions

Ignore whitespace Rev 6445 → Rev 6446

/trunk/joram/joram/tools/rest/jms/src/main/java/org/objectweb/joram/tools/rest/jms/Helper.java
53,6 → 53,7
 
public class Helper {
 
private static final String BYTES_CLASS_NAME = byte[].class.getName();
public static final String BUNDLE_CF_PROP = "rest.jms.connectionFactory";
public static final String BUNDLE_JNDI_FACTORY_INITIAL_PROP = "rest.jndi.factory.initial";
public static final String BUNDLE_JNDI_FACTORY_HOST_PROP = "rest.jndi.factory.host";
428,8 → 429,14
try {
if (array.size() == 2) {
String className = array.get(1);
Constructor<?> constructor = Class.forName(className).getConstructor(String.class);
value = constructor.newInstance(array.get(0));
if (Character.class.getName().equals(className)) {
value = array.get(0).charAt(0);
} else if (BYTES_CLASS_NAME.equals(className)) {
value = array.get(0).getBytes("UTF-8");
} else {
Constructor<?> constructor = Class.forName(className).getConstructor(String.class);
value = constructor.newInstance(array.get(0));
}
}
} catch (Exception e) {
if (logger.isLoggable(BasicLevel.ERROR))
450,6 → 457,9
case "Integer":
msg.setInt(key, (Integer)value);
break;
case "Long":
msg.setLong(key, (Long)value);
break;
case "Double":
msg.setDouble(key, (Double)value);
break;
459,13 → 469,13
case "Short":
msg.setShort(key, (Short)value);
break;
case "Char":
case "Character":
msg.setChar(key, (char)value);
break;
case "Byte":
msg.setByte(key, (Byte)value);
break;
case "Bytes":
case "byte[]":
msg.setBytes(key, (byte[])value);
break;
 
635,6 → 645,9
case "Integer":
msg.setIntProperty(key, (Integer)value);
break;
case "Long":
msg.setLongProperty(key, (Long)value);
break;
case "Double":
msg.setDoubleProperty(key, (Double)value);
break;
/trunk/joram/joram/tools/rest/jms/src/main/java/org/objectweb/joram/tools/rest/jms/JmsContextService.java
25,8 → 25,10
import java.net.URI;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
 
import javax.jms.BytesMessage;
593,6 → 595,27
}
}
 
private Map getMapMessageToJsonBodyMap(Message message) throws JMSException {
Map msgMap = message.getBody(Map.class);
if (msgMap == null)
return null;
HashMap<String, Object> jsonBodyMap = new HashMap<>();
Iterator<Map.Entry> entries = msgMap.entrySet().iterator();
while (entries.hasNext()) {
Entry entry = entries.next();
String name = (String) entry.getKey();
Object v = entry.getValue();
if (v != null) {
String[] value = {""+v, v.getClass().getName()};
if (v instanceof byte[]) {
value[0] = new String((byte[])v);
}
jsonBodyMap.put(name, value);
}
}
return jsonBodyMap;
}
@GET
@Path("/{name}")
@Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
628,7 → 651,7
// receive the message
message = helper.consume(consName, timeout, noLocal, durable, shared, subName, -1);
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "consumeTextMsg: message = " + message);
logger.log(BasicLevel.DEBUG, "consumeMsg: message = " + message);
} catch (Exception e) {
if (logger.isLoggable(BasicLevel.WARN))
logger.log(BasicLevel.WARN, "", e);
662,7 → 685,7
if (jsonMedia) {
HashMap jsonMap = new HashMap<>();
jsonMap.put(JMS_TYPE, message.getClass().getSimpleName());
jsonMap.put(JMS_BODY, message.getBody(Map.class));
jsonMap.put(JMS_BODY, getMapMessageToJsonBodyMap(message));
jsonMap.put(JMS_PROPERTIES, getPropertiesToJsonMap(message));
jsonMap.put(JMS_HEADER, getHeaderToJsonMap(message));
msg = jsonMap;
803,7 → 826,7
// receive the message
message = helper.consume(consName, timeout, noLocal, durable, shared, subName, id);
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "consumeTextMsg: message = " + message);
logger.log(BasicLevel.DEBUG, "consumeMsg: message = " + message);
} catch (Exception e) {
if (logger.isLoggable(BasicLevel.WARN))
logger.log(BasicLevel.WARN, "", e);
836,7 → 859,7
if (jsonMedia) {
HashMap jsonMap = new HashMap<>();
jsonMap.put(JMS_TYPE, message.getClass().getSimpleName());
jsonMap.put(JMS_BODY, message.getBody(Map.class));
jsonMap.put(JMS_BODY, getMapMessageToJsonBodyMap(message));
jsonMap.put(JMS_PROPERTIES, getPropertiesToJsonMap(message));
jsonMap.put(JMS_HEADER, getHeaderToJsonMap(message));
msg = jsonMap;