use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.
the class JmsMessageBrowser method getMessage.
public Object getMessage(String messageId) throws ListenerException {
Session session = null;
Object msg = null;
MessageConsumer mc = null;
try {
session = createSession();
mc = getMessageConsumer(session, getDestination(), getCombinedSelector(messageId));
msg = mc.receive(getTimeOut());
return msg;
} catch (Exception e) {
throw new ListenerException(e);
} finally {
try {
if (mc != null) {
mc.close();
}
} catch (JMSException e1) {
throw new ListenerException("exception closing message consumer", e1);
}
closeSession(session);
}
}
use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.
the class JmsMessageBrowser method deleteMessage.
public void deleteMessage(String messageId) throws ListenerException {
Session session = null;
MessageConsumer mc = null;
try {
session = createSession();
log.debug("retrieving message [" + messageId + "] in order to delete it");
mc = getMessageConsumer(session, getDestination(), getCombinedSelector(messageId));
mc.receive(getTimeOut());
} catch (Exception e) {
throw new ListenerException(e);
} finally {
try {
if (mc != null) {
mc.close();
}
} catch (JMSException e1) {
throw new ListenerException("exception closing message consumer", e1);
}
closeSession(session);
}
}
use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.
the class SimpleJdbcListener method execute.
protected void execute(Connection conn, String query, String parameter) throws ListenerException {
if (StringUtils.isNotEmpty(query)) {
if (trace && log.isDebugEnabled())
log.debug("executing statement [" + query + "]");
PreparedStatement stmt = null;
try {
stmt = conn.prepareStatement(query);
stmt.clearParameters();
if (StringUtils.isNotEmpty(parameter)) {
log.debug("setting parameter 1 to [" + parameter + "]");
stmt.setString(1, parameter);
}
stmt.execute();
} catch (SQLException e) {
throw new ListenerException(getLogPrefix() + "exception executing statement [" + query + "]", e);
} finally {
if (stmt != null) {
try {
// log.debug("closing statement for ["+query+"]");
stmt.close();
} catch (SQLException e) {
log.warn(getLogPrefix() + "exception closing statement [" + query + "]", e);
}
}
}
}
}
use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.
the class TestServiceListener method postServiceListeners.
@POST
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/test-servicelistener")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response postServiceListeners(MultipartFormDataInput input) throws ApiException {
Map<String, Object> result = new HashMap<String, Object>();
String message = null, serviceName = null, dispatchResult = null;
InputStream file = null;
Map<String, List<InputPart>> inputDataMap = input.getFormDataMap();
try {
if (inputDataMap.get("message") != null)
message = inputDataMap.get("message").get(0).getBodyAsString();
if (inputDataMap.get("service") != null) {
serviceName = inputDataMap.get("service").get(0).getBodyAsString();
}
if (inputDataMap.get("file") != null) {
file = inputDataMap.get("file").get(0).getBody(InputStream.class, null);
String fileEncoding = Misc.DEFAULT_INPUT_STREAM_ENCODING;
message = Misc.streamToString(file, "\n", fileEncoding, false);
message = XmlUtils.readXml(IOUtils.toByteArray(file), fileEncoding, false);
} else {
message = new String(message.getBytes(), Misc.DEFAULT_INPUT_STREAM_ENCODING);
}
if (!ServiceDispatcher.getInstance().isRegisteredServiceListener(serviceName)) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
try {
@SuppressWarnings("rawtypes") Map context = new HashMap();
dispatchResult = ServiceDispatcher.getInstance().dispatchRequest(serviceName, null, message, context);
} catch (ListenerException e) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
result.put("state", "success");
result.put("result", dispatchResult);
} catch (IOException e) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
return Response.status(Response.Status.CREATED).entity(result).build();
}
use of nl.nn.adapterframework.core.ListenerException in project iaf by ibissource.
the class BrowseQueue method putBrowseQueue.
@POST
@RolesAllowed({ "IbisTester" })
@Path("jms/browse")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response putBrowseQueue(LinkedHashMap<String, Object> json) throws ApiException {
initBase(servletConfig);
Map<String, Object> returnMap = new HashMap<String, Object>();
String jmsRealm = null, destination = null, type = null;
for (Entry<String, Object> entry : json.entrySet()) {
String key = entry.getKey();
if (key.equalsIgnoreCase("realm")) {
jmsRealm = entry.getValue().toString();
}
if (key.equalsIgnoreCase("destination")) {
destination = entry.getValue().toString();
}
if (key.equalsIgnoreCase("type")) {
type = entry.getValue().toString();
}
}
if (jmsRealm == null)
throw new ApiException("No realm provided");
if (destination == null)
throw new ApiException("No destination provided");
if (type == null)
throw new ApiException("No type provided");
IMessageBrowsingIterator it = null;
try {
JmsMessageBrowser jmsBrowser = new JmsMessageBrowser();
jmsBrowser.setName("BrowseQueueAction");
jmsBrowser.setJmsRealm(jmsRealm);
jmsBrowser.setDestinationName(destination);
jmsBrowser.setDestinationType(type);
IMessageBrowser browser = jmsBrowser;
it = browser.getIterator();
List<Map<String, Object>> messages = new ArrayList<Map<String, Object>>();
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());
message.put("expiryDate", item.getExpiryDate());
message.put("host", item.getHost());
message.put("id", item.getId());
message.put("insertDate", item.getInsertDate());
message.put("type", item.getType());
message.put("label", item.getLabel());
messages.add(message);
}
log.debug("Browser returned " + messages.size() + " messages");
returnMap.put("numberOfMessages", messages.size());
returnMap.put("messages", messages);
} catch (Exception e) {
throw new ApiException("Error occured browsing messages: " + e.getMessage());
} finally {
try {
if (it != null)
it.close();
} catch (ListenerException e) {
log.error(e);
}
}
return Response.status(Response.Status.OK).entity(returnMap).build();
}
Aggregations