Search in sources :

Example 11 with ListenerException

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);
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ListenerException(nl.nn.adapterframework.core.ListenerException) JMSException(javax.jms.JMSException) JMSException(javax.jms.JMSException) ListenerException(nl.nn.adapterframework.core.ListenerException) QueueSession(javax.jms.QueueSession) Session(javax.jms.Session)

Example 12 with ListenerException

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);
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ListenerException(nl.nn.adapterframework.core.ListenerException) JMSException(javax.jms.JMSException) JMSException(javax.jms.JMSException) ListenerException(nl.nn.adapterframework.core.ListenerException) QueueSession(javax.jms.QueueSession) Session(javax.jms.Session)

Example 13 with ListenerException

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);
                }
            }
        }
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement)

Example 14 with ListenerException

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();
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) HashMap(java.util.HashMap) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 15 with ListenerException

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();
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IMessageBrowsingIteratorItem(nl.nn.adapterframework.core.IMessageBrowsingIteratorItem) IMessageBrowser(nl.nn.adapterframework.core.IMessageBrowser) ArrayList(java.util.ArrayList) IMessageBrowsingIterator(nl.nn.adapterframework.core.IMessageBrowsingIterator) ListenerException(nl.nn.adapterframework.core.ListenerException) ListenerException(nl.nn.adapterframework.core.ListenerException) JmsMessageBrowser(nl.nn.adapterframework.jms.JmsMessageBrowser) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Aggregations

ListenerException (nl.nn.adapterframework.core.ListenerException)84 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)37 IOException (java.io.IOException)19 HashMap (java.util.HashMap)18 Map (java.util.Map)18 JMSException (javax.jms.JMSException)16 SenderException (nl.nn.adapterframework.core.SenderException)14 SQLException (java.sql.SQLException)13 PreparedStatement (java.sql.PreparedStatement)11 Session (javax.jms.Session)10 LinkedHashMap (java.util.LinkedHashMap)9 IPipeLineSession (nl.nn.adapterframework.core.IPipeLineSession)9 TimeOutException (nl.nn.adapterframework.core.TimeOutException)9 IfsaException (nl.nn.adapterframework.extensions.ifsa.IfsaException)9 Connection (java.sql.Connection)8 ResultSet (java.sql.ResultSet)8 QueueSession (javax.jms.QueueSession)8 File (java.io.File)7 MessageConsumer (javax.jms.MessageConsumer)7 Message (javax.jms.Message)6