Example usage for org.springframework.integration.file.remote SessionCallback doInSession

List of usage examples for org.springframework.integration.file.remote SessionCallback doInSession

Introduction

In this page you can find the example usage for org.springframework.integration.file.remote SessionCallback doInSession.

Prototype

T doInSession(Session<F> session) throws IOException;

Source Link

Document

Called within the context of a session.

Usage

From source file:org.springframework.integration.file.remote.RemoteFileTemplate.java

@SuppressWarnings("rawtypes")
@Override//  ww  w . j  a  v  a2  s .c  om
public <T> T execute(SessionCallback<F, T> callback) {
    Session<F> session = null;
    try {
        session = this.sessionFactory.getSession();
        Assert.notNull(session, "failed to acquire a Session");
        return callback.doInSession(session);
    } catch (Exception e) {
        if (session instanceof CachingSessionFactory<?>.CachedSession) {
            ((CachingSessionFactory.CachedSession) session).dirty();
        }
        if (e instanceof MessagingException) {
            throw (MessagingException) e;
        }
        throw new MessagingException("Failed to execute on session", e);
    } finally {
        if (session != null) {
            try {
                session.close();
            } catch (Exception ignored) {
                if (this.logger.isDebugEnabled()) {
                    this.logger.debug("failed to close Session", ignored);
                }
            }
        }
    }
}