use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class HttpSender method createMultiPartEntity.
protected HttpEntity createMultiPartEntity(String message, ParameterValueList parameters, IPipeLineSession session) throws SenderException {
MultipartEntityBuilder entity = MultipartEntityBuilder.create();
entity.setCharset(Charset.forName(getCharSet()));
if (isMtomEnabled())
entity.setMtomMultipart();
if (StringUtils.isNotEmpty(getInputMessageParam())) {
entity.addPart(createMultipartBodypart(getInputMessageParam(), message));
log.debug(getLogPrefix() + "appended stringpart [" + getInputMessageParam() + "] with value [" + message + "]");
}
if (parameters != null) {
for (int i = 0; i < parameters.size(); i++) {
ParameterValue pv = parameters.getParameterValue(i);
String paramType = pv.getDefinition().getType();
String name = pv.getDefinition().getName();
if (Parameter.TYPE_INPUTSTREAM.equals(paramType)) {
Object value = pv.getValue();
if (value instanceof InputStream) {
InputStream fis = (InputStream) value;
String fileName = null;
String sessionKey = pv.getDefinition().getSessionKey();
if (sessionKey != null) {
fileName = (String) session.get(sessionKey + "Name");
}
entity.addPart(createMultipartBodypart(name, fis, fileName));
log.debug(getLogPrefix() + "appended filepart [" + name + "] with value [" + value + "] and name [" + fileName + "]");
} else {
throw new SenderException(getLogPrefix() + "unknown inputstream [" + value.getClass() + "] for parameter [" + name + "]");
}
} else {
String value = pv.asStringValue("");
entity.addPart(createMultipartBodypart(name, value));
log.debug(getLogPrefix() + "appended stringpart [" + name + "] with value [" + value + "]");
}
}
}
if (StringUtils.isNotEmpty(getMultipartXmlSessionKey())) {
String multipartXml = (String) session.get(getMultipartXmlSessionKey());
if (StringUtils.isEmpty(multipartXml)) {
log.warn(getLogPrefix() + "sessionKey [" + getMultipartXmlSessionKey() + "] is empty");
} else {
Element partsElement;
try {
partsElement = XmlUtils.buildElement(multipartXml);
} catch (DomBuilderException e) {
throw new SenderException(getLogPrefix() + "error building multipart xml", e);
}
Collection<Node> parts = XmlUtils.getChildTags(partsElement, "part");
if (parts == null || parts.size() == 0) {
log.warn(getLogPrefix() + "no part(s) in multipart xml [" + multipartXml + "]");
} else {
Iterator<Node> iter = parts.iterator();
while (iter.hasNext()) {
Element partElement = (Element) iter.next();
// String partType = partElement.getAttribute("type");
String partName = partElement.getAttribute("name");
String partSessionKey = partElement.getAttribute("sessionKey");
String partMimeType = partElement.getAttribute("mimeType");
Object partObject = session.get(partSessionKey);
if (partObject instanceof InputStream) {
InputStream fis = (InputStream) partObject;
entity.addPart(createMultipartBodypart(partSessionKey, fis, partName, partMimeType));
log.debug(getLogPrefix() + "appended filepart [" + partSessionKey + "] with value [" + partObject + "] and name [" + partName + "]");
} else {
String partValue = (String) session.get(partSessionKey);
entity.addPart(createMultipartBodypart(partName, partValue, partMimeType));
log.debug(getLogPrefix() + "appended stringpart [" + partSessionKey + "] with value [" + partValue + "]");
}
}
}
}
}
// entity.seContentType(contentTypeMtom);
return entity.build();
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class ResultSet2FileSender method sendMessage.
protected String sendMessage(Connection connection, String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
int counter = 0;
ResultSet resultset = null;
String fileName = (String) prc.getSession().get(getFileNameSessionKey());
int maxRecords = -1;
if (StringUtils.isNotEmpty(getMaxRecordsSessionKey())) {
maxRecords = Integer.parseInt((String) prc.getSession().get(getMaxRecordsSessionKey()));
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(fileName, isAppend());
PreparedStatement statement = getStatement(connection, correlationID, null, true);
resultset = statement.executeQuery();
boolean eor = false;
if (maxRecords == 0) {
eor = true;
}
while (resultset.next() && !eor) {
counter++;
processResultSet(resultset, fos, counter);
if (maxRecords >= 0 && counter >= maxRecords) {
ResultSetMetaData rsmd = resultset.getMetaData();
if (rsmd.getColumnCount() >= 3) {
String group = resultset.getString(3);
while (resultset.next() && !eor) {
String groupNext = resultset.getString(3);
if (groupNext.equals(group)) {
counter++;
processResultSet(resultset, fos, counter);
} else {
eor = true;
}
}
} else {
eor = true;
}
}
}
} catch (FileNotFoundException e) {
throw new SenderException(getLogPrefix() + "could not find file [" + fileName + "]", e);
} catch (IOException e) {
throw new SenderException(getLogPrefix() + "got IOException", e);
} catch (SQLException sqle) {
throw new SenderException(getLogPrefix() + "got exception executing a SQL command", sqle);
} catch (JdbcException e) {
throw new SenderException(getLogPrefix() + "got exception executing a SQL command", e);
} finally {
try {
if (fos != null) {
fos.close();
}
} catch (IOException e) {
log.warn(new SenderException(getLogPrefix() + "got exception closing fileoutputstream", e));
}
try {
if (resultset != null) {
resultset.close();
}
} catch (SQLException e) {
log.warn(new SenderException(getLogPrefix() + "got exception closing resultset", e));
}
}
return "<result><rowsprocessed>" + counter + "</rowsprocessed></result>";
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class ResultSetIterator method hasNext.
public boolean hasNext() throws SenderException {
try {
if (!lineChecked) {
lineAvailable = rs.next();
lineChecked = true;
}
return lineAvailable;
} catch (Exception e) {
throw new SenderException(e);
}
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class XmlQuerySender method selectQuery.
private String selectQuery(Connection connection, String correlationID, String tableName, Vector columns, String where, String order) throws SenderException, JdbcException {
try {
String query = "SELECT ";
if (columns != null) {
Iterator iter = columns.iterator();
boolean firstColumn = true;
while (iter.hasNext()) {
Column column = (Column) iter.next();
if (firstColumn) {
query = query + column.getName();
firstColumn = false;
} else {
query = query + "," + column.getName();
}
}
} else {
query = query + "*";
}
query = query + " FROM " + tableName;
if (where != null) {
query = query + " WHERE " + where;
}
if (order != null) {
query = query + " ORDER BY " + order;
}
PreparedStatement statement = getStatement(connection, correlationID, query, false);
statement.setQueryTimeout(getTimeout());
setBlobSmartGet(true);
return executeSelectQuery(statement, null, null);
} catch (SQLException e) {
throw new SenderException(getLogPrefix() + "got exception executing a SELECT SQL command", e);
}
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class XmlQuerySender method sendMessage.
@Override
protected String sendMessage(Connection connection, String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
Element queryElement;
String tableName = null;
Vector columns = null;
String where = null;
String order = null;
String result = null;
try {
queryElement = XmlUtils.buildElement(message);
String root = queryElement.getTagName();
tableName = XmlUtils.getChildTagAsString(queryElement, "tableName");
Element columnsElement = XmlUtils.getFirstChildTag(queryElement, "columns");
if (columnsElement != null) {
columns = getColumns(columnsElement);
}
where = XmlUtils.getChildTagAsString(queryElement, "where");
order = XmlUtils.getChildTagAsString(queryElement, "order");
if (root.equalsIgnoreCase("select")) {
result = selectQuery(connection, correlationID, tableName, columns, where, order);
} else {
if (root.equalsIgnoreCase("insert")) {
result = insertQuery(connection, correlationID, prc, tableName, columns);
} else {
if (root.equalsIgnoreCase("delete")) {
result = deleteQuery(connection, correlationID, tableName, where);
} else {
if (root.equalsIgnoreCase("update")) {
result = updateQuery(connection, correlationID, tableName, columns, where);
} else {
if (root.equalsIgnoreCase("alter")) {
String sequenceName = XmlUtils.getChildTagAsString(queryElement, "sequenceName");
int startWith = Integer.parseInt(XmlUtils.getChildTagAsString(queryElement, "startWith"));
result = alterQuery(connection, sequenceName, startWith);
} else {
if (root.equalsIgnoreCase("sql")) {
String type = XmlUtils.getChildTagAsString(queryElement, "type");
String query = XmlUtils.getChildTagAsString(queryElement, "query");
result = sql(connection, correlationID, query, type);
} else {
throw new SenderException(getLogPrefix() + "unknown root element [" + root + "]");
}
}
}
}
}
}
} catch (DomBuilderException e) {
throw new SenderException(getLogPrefix() + "got exception parsing [" + message + "]", e);
} catch (JdbcException e) {
throw new SenderException(getLogPrefix() + "got exception preparing [" + message + "]", e);
}
return result;
}
Aggregations