use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class XmlQuerySender method deleteQuery.
private String deleteQuery(Connection connection, String correlationID, String tableName, String where) throws SenderException, JdbcException {
try {
String query = "DELETE FROM " + tableName;
if (where != null) {
query = query + " WHERE " + where;
}
PreparedStatement statement = getStatement(connection, correlationID, query, false);
statement.setQueryTimeout(getTimeout());
return executeOtherQuery(connection, correlationID, statement, query, null, null);
} catch (SQLException e) {
throw new SenderException(getLogPrefix() + "got exception executing a DELETE SQL command", e);
}
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class XmlQuerySender method insertQuery.
private String insertQuery(Connection connection, String correlationID, ParameterResolutionContext prc, String tableName, Vector columns) throws SenderException {
try {
String query = "INSERT INTO " + tableName + " (";
Iterator iter = columns.iterator();
String queryColumns = null;
String queryValues = null;
while (iter.hasNext()) {
Column column = (Column) iter.next();
if (queryColumns == null) {
queryColumns = column.getName();
} else {
queryColumns = queryColumns + "," + column.getName();
}
if (queryValues == null) {
queryValues = column.getQueryValue();
} else {
queryValues = queryValues + "," + column.getQueryValue();
}
}
query = query + queryColumns + ") VALUES (" + queryValues + ")";
return executeUpdate(connection, correlationID, tableName, query, columns);
} catch (SenderException t) {
throw new SenderException(getLogPrefix() + "got exception executing an INSERT SQL command", t);
}
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class XmlQuerySender method updateQuery.
private String updateQuery(Connection connection, String correlationID, String tableName, Vector columns, String where) throws SenderException {
try {
String query = "UPDATE " + tableName + " SET ";
Iterator iter = columns.iterator();
String querySet = null;
while (iter.hasNext()) {
Column column = (Column) iter.next();
if (querySet == null) {
querySet = column.getName();
} else {
querySet = querySet + "," + column.getName();
}
querySet = querySet + "=" + column.getQueryValue();
}
query = query + querySet;
if (where != null) {
query = query + " WHERE " + where;
}
return executeUpdate(connection, correlationID, tableName, query, columns);
} catch (SenderException t) {
throw new SenderException(getLogPrefix() + "got exception executing an UPDATE SQL command", t);
}
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class ShowAdapterStatistics method getStatistics.
@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/adapters/{adapterName}/statistics")
@Relation("statistics")
@Produces(MediaType.APPLICATION_JSON)
public Response getStatistics(@PathParam("adapterName") String adapterName) throws ApiException {
initBase(servletConfig);
Map<String, Object> statisticsMap = new HashMap<String, Object>();
Adapter adapter = (Adapter) ibisManager.getRegisteredAdapter(adapterName);
if (adapter == null) {
throw new ApiException("Adapter not found!");
}
StatisticsKeeper sk = adapter.getStatsMessageProcessingDuration();
statisticsMap.put("totalMessageProccessingTime", statisticsKeeperToMapBuilder(sk));
long[] numOfMessagesStartProcessingByHour = adapter.getNumOfMessagesStartProcessingByHour();
List<Map<String, Object>> hourslyStatistics = new ArrayList<Map<String, Object>>();
for (int i = 0; i < numOfMessagesStartProcessingByHour.length; i++) {
Map<String, Object> item = new HashMap<String, Object>(2);
String startTime;
if (i < 10) {
startTime = "0" + i + ":00";
} else {
startTime = i + ":00";
}
item.put("time", startTime);
item.put("count", numOfMessagesStartProcessingByHour[i]);
hourslyStatistics.add(item);
}
statisticsMap.put("hourly", hourslyStatistics);
List<Map<String, Object>> receivers = new ArrayList<Map<String, Object>>();
Iterator<?> recIt = adapter.getReceiverIterator();
if (recIt.hasNext()) {
while (recIt.hasNext()) {
IReceiver receiver = (IReceiver) recIt.next();
Map<String, Object> receiverMap = new HashMap<String, Object>();
receiverMap.put("name", receiver.getName());
receiverMap.put("class", receiver.getClass().getName());
receiverMap.put("messagesReceived", receiver.getMessagesReceived());
receiverMap.put("messagesRetried", receiver.getMessagesRetried());
if (receiver instanceof IReceiverStatistics) {
IReceiverStatistics statReceiver = (IReceiverStatistics) receiver;
Iterator<?> statsIter;
statsIter = statReceiver.getProcessStatisticsIterator();
if (statsIter != null) {
ArrayList<Map<String, Object>> procStatsMap = new ArrayList<Map<String, Object>>();
// procStatsXML.addSubElement(statisticsKeeperToXmlBuilder(statReceiver.getResponseSizeStatistics(), "stat"));
while (statsIter.hasNext()) {
StatisticsKeeper pstat = (StatisticsKeeper) statsIter.next();
procStatsMap.add(statisticsKeeperToMapBuilder(pstat));
}
receiverMap.put("processing", procStatsMap);
}
statsIter = statReceiver.getIdleStatisticsIterator();
if (statsIter != null) {
ArrayList<Map<String, Object>> idleStatsMap = new ArrayList<Map<String, Object>>();
while (statsIter.hasNext()) {
StatisticsKeeper pstat = (StatisticsKeeper) statsIter.next();
idleStatsMap.add(statisticsKeeperToMapBuilder(pstat));
}
receiverMap.put("idle", idleStatsMap);
}
receivers.add(receiverMap);
}
}
}
statisticsMap.put("receivers", receivers);
Map<String, Object> tmp = new HashMap<String, Object>();
StatisticsKeeperToXml handler = new StatisticsKeeperToXml(tmp);
handler.configure();
Object handle = handler.start(null, null, null);
try {
adapter.getPipeLine().iterateOverStatistics(handler, tmp, HasStatistics.STATISTICS_ACTION_FULL);
statisticsMap.put("durationPerPipe", tmp.get("pipeStats"));
statisticsMap.put("sizePerPipe", tmp.get("sizeStats"));
} catch (SenderException e) {
log.error(e);
} finally {
handler.end(handle);
}
return Response.status(Response.Status.CREATED).entity(statisticsMap).build();
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class NetStorageAction method mapParameters.
public void mapParameters(ParameterValueList pvl) throws SenderException {
if (requiresFileParam()) {
Object paramValue = pvl.getParameterValue("file").getValue();
if (paramValue instanceof InputStream)
fileStream = (InputStream) paramValue;
else if (paramValue instanceof byte[])
fileBytes = (byte[]) paramValue;
else
throw new SenderException("expected InputStream or ByteArray but got [" + paramValue.getClass().getName() + "] instead");
String md5 = null;
String sha1 = null;
String sha256 = null;
if (pvl.parameterExists("md5")) {
md5 = pvl.getParameterValue("md5").asStringValue(null);
}
if (pvl.parameterExists("sha1")) {
sha1 = pvl.getParameterValue("sha1").asStringValue(null);
}
if (pvl.parameterExists("sha256")) {
sha256 = pvl.getParameterValue("sha256").asStringValue(null);
}
if (hashAlgorithm != null) {
try {
if (fileStream != null)
fileBytes = Misc.streamToBytes(fileStream);
if (md5 == null && hashAlgorithm.equals("MD5")) {
byte[] checksum = NetStorageUtils.computeHash(fileBytes, HashAlgorithm.MD5);
if (checksum != null)
md5 = NetStorageUtils.convertByteArrayToHexString(checksum);
}
if (sha1 == null && hashAlgorithm.equals("SHA1")) {
byte[] checksum = NetStorageUtils.computeHash(fileBytes, HashAlgorithm.SHA1);
if (checksum != null)
sha1 = NetStorageUtils.convertByteArrayToHexString(checksum);
}
if (sha256 == null && hashAlgorithm.equals("SHA256")) {
byte[] checksum = NetStorageUtils.computeHash(fileBytes, HashAlgorithm.SHA256);
if (checksum != null)
sha256 = NetStorageUtils.convertByteArrayToHexString(checksum);
}
fileStream = new ByteArrayInputStream(fileBytes);
} catch (Exception e) {
throw new SenderException("error while calculating [" + hashAlgorithm + "] hash", e);
}
}
if (md5 != null)
actionHeader.put("md5", md5);
if (sha1 != null)
actionHeader.put("sha1", sha1);
if (sha256 != null)
actionHeader.put("sha256", sha256);
if (pvl.parameterExists("size")) {
int size = pvl.getParameterValue("size").asIntegerValue(0);
actionHeader.put("size", size + "");
}
}
if (pvl.parameterExists("mtime")) {
long mtime = pvl.getParameterValue("mtime").asLongValue(-1L);
actionHeader.put("mtime", mtime + "");
}
}
Aggregations