use of nl.nn.adapterframework.jms.JmsMessageBrowserIteratorItem in project iaf by ibissource.
the class BrowseQueue method putBrowseQueue.
@POST
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("jms/browse")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response putBrowseQueue(LinkedHashMap<String, Object> json) throws ApiException {
Map<String, Object> returnMap = new HashMap<String, Object>();
String connectionFactory = null, destination = null;
boolean rowNumbersOnly = false, showPayload = false, lookupDestination = false;
DestinationType type = null;
for (Entry<String, Object> entry : json.entrySet()) {
String key = entry.getKey();
if (key.equalsIgnoreCase("connectionFactory")) {
connectionFactory = entry.getValue().toString();
}
if (key.equalsIgnoreCase("destination")) {
destination = entry.getValue().toString();
}
if (key.equalsIgnoreCase("type")) {
type = EnumUtils.parse(DestinationType.class, entry.getValue().toString());
}
if (key.equalsIgnoreCase("rowNumbersOnly")) {
rowNumbersOnly = Boolean.parseBoolean(entry.getValue().toString());
}
if (key.equalsIgnoreCase("payload")) {
showPayload = Boolean.parseBoolean(entry.getValue().toString());
}
if (key.equalsIgnoreCase("lookupDestination")) {
lookupDestination = Boolean.parseBoolean(entry.getValue().toString());
}
}
if (connectionFactory == null)
throw new ApiException("No connection factory provided");
if (destination == null)
throw new ApiException("No destination provided");
if (type == null)
throw new ApiException("No type provided");
try {
JmsBrowser<javax.jms.Message> jmsBrowser = getIbisContext().createBeanAutowireByName(JmsBrowser.class);
jmsBrowser.setName("BrowseQueueAction");
if (type == DestinationType.QUEUE) {
jmsBrowser.setQueueConnectionFactoryName(connectionFactory);
} else {
jmsBrowser.setTopicConnectionFactoryName(connectionFactory);
}
jmsBrowser.setDestinationName(destination);
jmsBrowser.setDestinationType(type);
jmsBrowser.setLookupDestination(lookupDestination);
List<Map<String, Object>> messages = new ArrayList<Map<String, Object>>();
try (IMessageBrowsingIterator it = jmsBrowser.getIterator()) {
while (it.hasNext()) {
IMessageBrowsingIteratorItem item = it.next();
Map<String, Object> message = new HashMap<String, Object>();
message.put("comment", item.getCommentString());
message.put("correlationId", item.getCorrelationId());
try {
message.put("expiryDate", item.getExpiryDate());
} catch (Exception e) {
log.warn("Could not get expiryDate", e);
}
message.put("host", item.getHost());
message.put("id", item.getId());
try {
message.put("insertDate", item.getInsertDate());
} catch (Exception e) {
log.warn("Could not get insertDate", e);
}
if (showPayload && item instanceof JmsMessageBrowserIteratorItem) {
message.put("text", ((JmsMessageBrowserIteratorItem) item).getText());
}
messages.add(message);
}
}
log.debug("Browser returned " + messages.size() + " messages");
returnMap.put("numberOfMessages", messages.size());
if (!rowNumbersOnly) {
returnMap.put("messages", messages);
}
} catch (Exception e) {
throw new ApiException("Error occured browsing messages", e);
}
return Response.status(Response.Status.OK).entity(returnMap).build();
}
Aggregations