Search in sources :

Example 81 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class ExceptionReportService method doService.

@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
    try {
        if (msg.getObjectHeaders().containsKey(OBJ_METADATA_EXCEPTION)) {
            Exception e = (Exception) msg.getObjectHeaders().get(OBJ_METADATA_EXCEPTION);
            getExceptionSerializer().serialize(e, msg);
        } else {
            log.debug("No Exception in object metadata, nothing to do.");
        }
    } catch (Exception e) {
        throw ExceptionHelper.wrapServiceException(e);
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) CoreException(com.adaptris.core.CoreException)

Example 82 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class JdbcServiceList method applyServices.

@Override
protected void applyServices(AdaptrisMessage msg) throws ServiceException {
    try {
        AdaptrisConnection c = connection();
        if (c != null) {
            Connection conn = c.retrieveConnection(DatabaseConnection.class).connect();
            msg.getObjectHeaders().put(JdbcConstants.OBJ_METADATA_DATABASE_CONNECTION_KEY, conn);
        }
        super.applyServices(msg);
        // We may not have a valid connection here if we're using pooled connections.  If not, then no point in committing on a new connection.
        Connection conn = (Connection) msg.getObjectHeaders().get(JdbcConstants.OBJ_METADATA_DATABASE_CONNECTION_KEY);
        if (conn != null && !conn.isClosed())
            JdbcUtil.commit(conn);
    } catch (Exception e) {
        rollback(msg, e);
        throw ExceptionHelper.wrapServiceException(e);
    } finally {
        Connection conn = (Connection) msg.getObjectHeaders().get(JdbcConstants.OBJ_METADATA_DATABASE_CONNECTION_KEY);
        JdbcUtil.closeQuietly(conn);
    }
}
Also used : AdaptrisConnection(com.adaptris.core.AdaptrisConnection) DatabaseConnection(com.adaptris.core.jdbc.DatabaseConnection) Connection(java.sql.Connection) AdaptrisConnection(com.adaptris.core.AdaptrisConnection) DatabaseConnection(com.adaptris.core.jdbc.DatabaseConnection) ServiceException(com.adaptris.core.ServiceException) CoreException(com.adaptris.core.CoreException)

Example 83 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class JdbcDataQueryService method doService.

/**
 * The main service method, which sees the specified query executed and the results returned in an XML message.
 *
 * @see com.adaptris.core.Service#doService(com.adaptris.core.AdaptrisMessage)
 */
@Override
@SuppressWarnings({ "lgtm [java/database-resource-leak]" })
public void doService(AdaptrisMessage msg) throws ServiceException {
    log.trace("Beginning doService");
    JdbcResult result = null;
    Connection conn = null;
    try {
        Connection c = getConnection(msg);
        if (!c.equals(actor.getSqlConnection())) {
            actor.reInitialise(c);
        }
        conn = actor.getSqlConnection();
        initXmlHelper(msg);
        String statement = getStatementCreator().createStatement(msg);
        PreparedStatement preparedStatement = actor.getQueryStatement(statement);
        preparedStatement.clearParameters();
        log.trace("Executing statement [{}]", statement);
        this.getParameterApplicator().applyStatementParameters(msg, preparedStatement, getStatementParameters(), statement);
        try {
            // closed by the finally block which closes the JdbcResult
            ResultSet rs = preparedStatement.executeQuery();
            result = new JdbcResultBuilder().setHasResultSet(true).setResultSet(rs).build();
        } catch (SQLException e) {
            if (ignoreExecuteQueryErrors()) {
                log.debug("Ignore ExecuteQuery Errors enabled); using empty ResultSet");
                result = new JdbcResultBuilder().setHasResultSet(false).build();
            } else {
                throw e;
            }
        }
        resultSetTranslator.translate(result, msg);
        destroyXmlHelper(msg);
        JdbcUtil.commit(conn, msg);
    } catch (Exception e) {
        JdbcUtil.rollback(conn, msg);
        throw ExceptionHelper.wrapServiceException(e);
    } finally {
        JdbcUtil.closeQuietly(result);
        JdbcUtil.closeQuietly(conn);
    }
}
Also used : JdbcResultBuilder(com.adaptris.jdbc.JdbcResultBuilder) SQLException(java.sql.SQLException) Connection(java.sql.Connection) DatabaseConnection(com.adaptris.core.jdbc.DatabaseConnection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) JdbcResult(com.adaptris.jdbc.JdbcResult) ServiceException(com.adaptris.core.ServiceException) SQLException(java.sql.SQLException) CoreException(com.adaptris.core.CoreException)

Example 84 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class DynamicJmxOperationService method doService.

@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
    try {
        MBeanServerConnection mbeanConn = cachedGet(msg.resolve(getJmxServiceUrl())).mbeanServerConnection();
        Object result = getInvoker().invoke(mbeanConn, msg.resolve(getObjectName()), msg.resolve(getOperationName()), parametersToArray(msg), parametersToTypeArray(msg));
        if (getResultValueTranslator() != null)
            getResultValueTranslator().setValue(msg, result);
    } catch (Exception e) {
        throw ExceptionHelper.wrapServiceException(e);
    }
}
Also used : MBeanServerConnection(javax.management.MBeanServerConnection) ServiceException(com.adaptris.core.ServiceException) CoreException(com.adaptris.core.CoreException)

Example 85 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class NamedParameterApplicator method applyStatementParameters.

@Override
public void applyStatementParameters(AdaptrisMessage message, PreparedStatement statement, StatementParameterCollection parameters, String originalSql) throws ServiceException {
    Matcher m = Pattern.compile(this.getParameterNameRegex()).matcher(originalSql);
    int counter = 0;
    while (m.find()) {
        counter++;
        String parameterName = m.group();
        JdbcStatementParameter statementParameter = parameters.getParameterByName(parameterName.substring(this.getParameterNamePrefix().length()));
        try {
            Args.notNull(statementParameter, "statementParameter");
            statementParameter.apply(counter, statement, message);
        } catch (Exception ex) {
            throw ExceptionHelper.wrapServiceException(ex);
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) ServiceException(com.adaptris.core.ServiceException)

Aggregations

ServiceException (com.adaptris.core.ServiceException)236 Test (org.junit.Test)172 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)161 CoreException (com.adaptris.core.CoreException)45 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)26 StandaloneProducer (com.adaptris.core.StandaloneProducer)18 MetadataElement (com.adaptris.core.MetadataElement)17 ValidationStage (com.adaptris.transform.validate.ValidationStage)16 Cache (com.adaptris.core.cache.Cache)15 DefectiveMessageFactory (com.adaptris.core.stubs.DefectiveMessageFactory)13 TimeInterval (com.adaptris.util.TimeInterval)13 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)11 Connection (java.sql.Connection)10 File (java.io.File)9 IOException (java.io.IOException)9 OutputStream (java.io.OutputStream)9 SQLException (java.sql.SQLException)9 InputStream (java.io.InputStream)8 Document (org.w3c.dom.Document)8 Channel (com.adaptris.core.Channel)7