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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
}
Aggregations