use of nl.nn.adapterframework.util.StringTagger in project iaf by ibissource.
the class ExecuteJdbcQueryExecute method executeSub.
public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// Initialize action
initAction(request);
DynaActionForm executeJdbcQueryExecuteForm = (DynaActionForm) form;
String form_jmsRealm = (String) executeJdbcQueryExecuteForm.get("jmsRealm");
String form_queryType = (String) executeJdbcQueryExecuteForm.get("queryType");
String form_resultType = (String) executeJdbcQueryExecuteForm.get("resultType");
String form_query = (String) executeJdbcQueryExecuteForm.get("query");
DirectQuerySender qs;
String result = "";
try {
qs = (DirectQuerySender) ibisManager.getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
try {
qs.setName("QuerySender");
qs.setJmsRealm(form_jmsRealm);
qs.setQueryType(form_queryType);
qs.setBlobSmartGet(true);
qs.configure(true);
qs.open();
result = qs.sendMessage("dummy", form_query);
if ("csv".equalsIgnoreCase(form_resultType)) {
URL url = ClassUtils.getResourceURL(this, DB2XML_XSLT);
if (url != null) {
Transformer t = XmlUtils.createTransformer(url);
result = XmlUtils.transformXml(t, result);
}
}
} catch (Throwable t) {
error("error occured on executing jdbc query", t);
} finally {
qs.close();
}
} catch (Exception e) {
error("error occured on creating or closing connection", e);
}
StoreFormData(form_query, result, executeJdbcQueryExecuteForm);
if (!errors.isEmpty()) {
saveErrors(request, errors);
return (new ActionForward(mapping.getInput()));
}
// Successfull: store cookie
String cookieValue = "";
cookieValue += "jmsRealm=\"" + form_jmsRealm + "\"";
// separator
cookieValue += " ";
cookieValue += "queryType=\"" + form_queryType + "\"";
// separator
cookieValue += " ";
cookieValue += "resultType=\"" + form_resultType + "\"";
// separator
cookieValue += " ";
// TODO: fix workaround to avoid http error 500 on WAS (line separators in query cookie)
String fq = Misc.replace(form_query, System.getProperty("line.separator"), " ");
cookieValue += "query=\"" + fq + "\"";
Cookie execJdbcCookie = new Cookie(AppConstants.getInstance().getProperty("WEB_EXECJDBCCOOKIE_NAME"), cookieValue);
execJdbcCookie.setMaxAge(Integer.MAX_VALUE);
log.debug("Store cookie for " + request.getServletPath() + " cookieName[" + AppConstants.getInstance().getProperty("WEB_EXECJDBCCOOKIE_NAME") + "] " + " cookieValue[" + new StringTagger(cookieValue).toString() + "]");
try {
response.addCookie(execJdbcCookie);
} catch (Throwable e) {
log.warn("unable to add cookie to request. cookie value [" + execJdbcCookie.getValue() + "]");
}
log.debug("forward to success");
return (mapping.findForward("success"));
}
use of nl.nn.adapterframework.util.StringTagger in project iaf by ibissource.
the class SendJmsMessage method executeSub.
public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// Initialize action
initAction(request);
DynaActionForm sendJmsMessageForm = getPersistentForm(mapping, form, request);
Cookie[] cookies = request.getCookies();
if (null != cookies) {
for (int i = 0; i < cookies.length; i++) {
Cookie aCookie = cookies[i];
if (aCookie.getName().equals(AppConstants.getInstance().getProperty("WEB_JMSCOOKIE_NAME"))) {
StringTagger cs = new StringTagger(aCookie.getValue());
log.debug("restoring values from cookie: " + cs.toString());
try {
sendJmsMessageForm.set("jmsRealm", cs.Value("jmsRealm"));
sendJmsMessageForm.set("destinationName", cs.Value("destinationName"));
sendJmsMessageForm.set("destinationType", cs.Value("destinationType"));
} catch (Exception e) {
log.warn("could not restore Cookie value's");
}
}
}
}
List jmsRealms = JmsRealmFactory.getInstance().getRegisteredRealmNamesAsList();
if (jmsRealms.size() == 0)
jmsRealms.add("no realms defined");
sendJmsMessageForm.set("jmsRealms", jmsRealms);
// Forward control to the specified success URI
log.debug("forward to success");
return (mapping.findForward("success"));
}
use of nl.nn.adapterframework.util.StringTagger in project iaf by ibissource.
the class SendJmsMessageExecute method executeSub.
public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// Initialize action
initAction(request);
// -------------------------------
if (isCancelled(request)) {
log.debug("sendJmsMessage was cancelled");
removeFormBean(mapping, request);
return (mapping.findForward("success"));
}
// Retrieve form content
// ---------------------
DynaActionForm sendJmsMessageForm = (DynaActionForm) form;
String form_jmsRealm = (String) sendJmsMessageForm.get("jmsRealm");
String form_destinationName = (String) sendJmsMessageForm.get("destinationName");
String form_destinationType = (String) sendJmsMessageForm.get("destinationType");
boolean form_persistent = false;
if (null != sendJmsMessageForm.get("persistent")) {
form_persistent = ((Boolean) sendJmsMessageForm.get("persistent")).booleanValue();
}
String form_message = (String) sendJmsMessageForm.get("message");
FormFile form_file = (FormFile) sendJmsMessageForm.get("file");
String form_replyToName = (String) sendJmsMessageForm.get("replyToName");
// if upload is choosen, it prevails over the message
if ((form_file != null) && (form_file.getFileSize() > 0)) {
log.debug("Upload of file [" + form_file.getFileName() + "] ContentType[" + form_file.getContentType() + "]");
if (FileUtils.extensionEqualsIgnoreCase(form_file.getFileName(), "zip")) {
ZipInputStream archive = new ZipInputStream(new ByteArrayInputStream(form_file.getFileData()));
for (ZipEntry entry = archive.getNextEntry(); entry != null; entry = archive.getNextEntry()) {
String name = entry.getName();
int size = (int) entry.getSize();
if (size > 0) {
byte[] b = new byte[size];
int rb = 0;
int chunk = 0;
while (((int) size - rb) > 0) {
chunk = archive.read(b, rb, (int) size - rb);
if (chunk == -1) {
break;
}
rb += chunk;
}
String currentMessage = XmlUtils.readXml(b, 0, rb, request.getCharacterEncoding(), false);
// initiate MessageSender
JmsSender qms = new JmsSender();
qms.setName("SendJmsMessageAction");
qms.setJmsRealm(form_jmsRealm);
qms.setDestinationName(form_destinationName);
qms.setPersistent(form_persistent);
qms.setDestinationType(form_destinationType);
if ((form_replyToName != null) && (form_replyToName.length() > 0))
qms.setReplyToName(form_replyToName);
processMessage(qms, name + "_" + Misc.createSimpleUUID(), currentMessage);
}
archive.closeEntry();
}
archive.close();
form_message = null;
} else {
form_message = XmlUtils.readXml(form_file.getFileData(), request.getCharacterEncoding(), false);
}
} else {
form_message = new String(form_message.getBytes(), Misc.DEFAULT_INPUT_STREAM_ENCODING);
}
if (form_message != null && form_message.length() > 0) {
// initiate MessageSender
JmsSender qms = new JmsSender();
qms.setName("SendJmsMessageAction");
qms.setJmsRealm(form_jmsRealm);
qms.setDestinationName(form_destinationName);
qms.setPersistent(form_persistent);
qms.setDestinationType(form_destinationType);
if ((form_replyToName != null) && (form_replyToName.length() > 0))
qms.setReplyToName(form_replyToName);
processMessage(qms, "testmsg_" + Misc.createUUID(), form_message);
}
StoreFormData(sendJmsMessageForm);
// Report any errors we have discovered back to the original form
if (!errors.isEmpty()) {
saveErrors(request, errors);
return (new ActionForward(mapping.getInput()));
}
// Successfull: store cookie
String cookieValue = "";
cookieValue += "jmsRealm=\"" + form_jmsRealm + "\"";
// separator
cookieValue += " ";
cookieValue += "destinationName=\"" + form_destinationName + "\"";
// separator
cookieValue += " ";
cookieValue += "destinationType=\"" + form_destinationType + "\"";
Cookie sendJmsCookie = new Cookie(AppConstants.getInstance().getProperty("WEB_JMSCOOKIE_NAME"), cookieValue);
sendJmsCookie.setMaxAge(Integer.MAX_VALUE);
log.debug("Store cookie for " + request.getServletPath() + " cookieName[" + AppConstants.getInstance().getProperty("WEB_JMSCOOKIE_NAME") + "] " + " cookieValue[" + new StringTagger(cookieValue).toString() + "]");
try {
response.addCookie(sendJmsCookie);
} catch (Throwable e) {
log.warn("unable to add cookie to request. cookie value [" + sendJmsCookie.getValue() + "]");
}
// Forward control to the specified success URI
log.debug("forward to success");
return (mapping.findForward("success"));
}
use of nl.nn.adapterframework.util.StringTagger in project iaf by ibissource.
the class BrowseJdbcTableExecute method executeSub.
public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// Initialize action
initAction(request);
// -------------------------------
if (isCancelled(request)) {
log.debug("browseJdbcTable was cancelled");
removeFormBean(mapping, request);
return (mapping.findForward("cancel"));
}
// Retrieve form content
// ---------------------
IniDynaActionForm browseJdbcTableForm = (IniDynaActionForm) form;
String form_jmsRealm = (String) browseJdbcTableForm.get("jmsRealm");
String form_tableName = (String) browseJdbcTableForm.get("tableName");
String form_where = (String) browseJdbcTableForm.get("where");
boolean form_numberOfRowsOnly = false;
String form_order = (String) browseJdbcTableForm.get("order");
if (browseJdbcTableForm.get("numberOfRowsOnly") != null)
form_numberOfRowsOnly = ((Boolean) browseJdbcTableForm.get("numberOfRowsOnly")).booleanValue();
int form_rownumMin = ((Integer) browseJdbcTableForm.get("rownumMin")).intValue();
int form_rownumMax = ((Integer) browseJdbcTableForm.get("rownumMax")).intValue();
if (!form_numberOfRowsOnly) {
if (form_rownumMin < 0) {
form_rownumMin = 0;
}
if (form_rownumMax < 0) {
form_rownumMax = 0;
}
if (form_rownumMin == 0 && form_rownumMax == 0) {
form_rownumMin = 1;
form_rownumMax = 100;
}
if (errors.isEmpty()) {
if (form_rownumMax < form_rownumMin) {
error("errors.generic", "Rownum max must be greater than or equal to Rownum min", null);
}
}
if (errors.isEmpty()) {
if (form_rownumMax - form_rownumMin >= 100) {
error("errors.generic", "Difference between Rownum max and Rownum min must be less than hundred", null);
}
}
if (!readAllowed(permissionRules, request, form_tableName)) {
error("errors.generic", "Access to table (" + form_tableName + ") not allowed", null);
}
}
if (errors.isEmpty()) {
DirectQuerySender qs;
String result = "";
String query = null;
try {
qs = (DirectQuerySender) ibisManager.getIbisContext().createBeanAutowireByName(DirectQuerySender.class);
try {
qs.setName("QuerySender");
qs.setJmsRealm(form_jmsRealm);
// if (form_numberOfRowsOnly || qs.getDatabaseType() == DbmsSupportFactory.DBMS_ORACLE) {
qs.setQueryType("select");
qs.setBlobSmartGet(true);
qs.setIncludeFieldDefinition(true);
qs.configure(true);
qs.open();
ResultSet rs = qs.getConnection().getMetaData().getColumns(null, null, form_tableName, null);
if (!rs.isBeforeFirst()) {
rs = qs.getConnection().getMetaData().getColumns(null, null, form_tableName.toUpperCase(), null);
}
String fielddefinition = "<fielddefinition>";
while (rs.next()) {
String field = "<field name=\"" + rs.getString(4) + "\" type=\"" + DB2XMLWriter.getFieldType(rs.getInt(5)) + "\" size=\"" + rs.getInt(7) + "\"/>";
fielddefinition = fielddefinition + field;
}
fielddefinition = fielddefinition + "</fielddefinition>";
String browseJdbcTableExecuteREQ = "<browseJdbcTableExecuteREQ>" + "<dbmsName>" + qs.getDbmsSupport().getDbmsName() + "</dbmsName>" + "<tableName>" + form_tableName + "</tableName>" + "<where>" + XmlUtils.encodeChars(form_where) + "</where>" + "<numberOfRowsOnly>" + form_numberOfRowsOnly + "</numberOfRowsOnly>" + "<order>" + form_order + "</order>" + "<rownumMin>" + form_rownumMin + "</rownumMin>" + "<rownumMax>" + form_rownumMax + "</rownumMax>" + fielddefinition + "<maxColumnSize>1000</maxColumnSize>" + "</browseJdbcTableExecuteREQ>";
URL url = ClassUtils.getResourceURL(this, DB2XML_XSLT);
if (url != null) {
Transformer t = XmlUtils.createTransformer(url);
query = XmlUtils.transformXml(t, browseJdbcTableExecuteREQ);
}
result = qs.sendMessage("dummy", query);
// } else {
// error("errors.generic","This function only supports oracle databases",null);
// }
} catch (Throwable t) {
error("errors.generic", "error occured on executing jdbc query [" + query + "]", t);
} finally {
qs.close();
}
} catch (Exception e) {
error("errors.generic", "error occured on creating or closing connection", e);
}
String resultEnvelope = "<resultEnvelope>" + "<request " + "tableName=\"" + form_tableName + "\">" + XmlUtils.encodeChars(query) + "</request>" + result + "</resultEnvelope>";
request.setAttribute("DB2Xml", resultEnvelope);
}
// Report any errors we have discovered back to the original form
if (!errors.isEmpty()) {
StoreFormData(browseJdbcTableForm);
saveErrors(request, errors);
return (new ActionForward(mapping.getInput()));
}
// Successfull: store cookie
String cookieValue = "";
cookieValue += "jmsRealm=\"" + form_jmsRealm + "\"";
// separator
cookieValue += " ";
cookieValue += "tableName=\"" + form_tableName + "\"";
// separator
cookieValue += " ";
cookieValue += "where=\"" + form_where + "\"";
// separator
cookieValue += " ";
cookieValue += "order=\"" + form_order + "\"";
// separator
cookieValue += " ";
cookieValue += "numberOfRowsOnly=\"" + form_numberOfRowsOnly + "\"";
// separator
cookieValue += " ";
cookieValue += "rownumMin=\"" + form_rownumMin + "\"";
// separator
cookieValue += " ";
cookieValue += "rownumMax=\"" + form_rownumMax + "\"";
Cookie sendJdbcBrowseCookie = new Cookie(AppConstants.getInstance().getProperty("WEB_JDBCBROWSECOOKIE_NAME"), cookieValue);
sendJdbcBrowseCookie.setMaxAge(Integer.MAX_VALUE);
log.debug("Store cookie for " + request.getServletPath() + " cookieName[" + AppConstants.getInstance().getProperty("WEB_JDBCBROWSECOOKIE_NAME") + "] " + " cookieValue[" + new StringTagger(cookieValue).toString() + "]");
try {
response.addCookie(sendJdbcBrowseCookie);
} catch (Throwable e) {
log.warn("unable to add cookie to request. cookie value [" + sendJdbcBrowseCookie.getValue() + "]");
}
// Forward control to the specified success URI
log.debug("forward to success");
return (mapping.findForward("success"));
}
use of nl.nn.adapterframework.util.StringTagger in project iaf by ibissource.
the class BrowseQueueExecute method executeSub.
public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// Initialize action
initAction(request);
// -------------------------------
if (isCancelled(request)) {
log.debug("browseQueue was cancelled");
removeFormBean(mapping, request);
return (mapping.findForward("cancel"));
}
// Retrieve form content
// ---------------------
IniDynaActionForm browseQueueForm = (IniDynaActionForm) form;
String form_jmsRealm = (String) browseQueueForm.get("jmsRealm");
String form_destinationName = (String) browseQueueForm.get("destinationName");
String form_destinationType = (String) browseQueueForm.get("destinationType");
boolean form_numberOfMessagesOnly = false;
boolean form_showPayload = false;
if (browseQueueForm.get("numberOfMessagesOnly") != null)
form_numberOfMessagesOnly = ((Boolean) browseQueueForm.get("numberOfMessagesOnly")).booleanValue();
if (browseQueueForm.get("showPayload") != null)
form_showPayload = ((Boolean) browseQueueForm.get("showPayload")).booleanValue();
// initiate MessageSender
JmsMessageBrowser jmsBrowser = new JmsMessageBrowser();
jmsBrowser.setName("BrowseQueueAction");
jmsBrowser.setJmsRealm(form_jmsRealm);
jmsBrowser.setDestinationName(form_destinationName);
jmsBrowser.setDestinationType(form_destinationType);
IMessageBrowser browser = jmsBrowser;
IMessageBrowsingIterator it = null;
try {
it = browser.getIterator();
List messages = new ArrayList();
while (it.hasNext()) {
messages.add(it.next());
}
log.debug("Browser returned " + messages.size() + " messages");
browseQueueForm.set("numberOfMessages", Integer.toString(messages.size()));
if (!form_numberOfMessagesOnly) {
/*
try {
for (int i = 0; i < messages.size(); i++) {
Message msg = (Message) messages.get(i);
if (msg instanceof TextMessage) {
TextMessage tm = (TextMessage) msg;
if (log.isDebugEnabled())
log.debug("Found message " + tm.getText());
}
}
} catch (JMSException je) {
log.error(je);
errors.add(
"",
new ActionError(
"errors.generic",
"error occured browsing messages:" + je.getMessage()));
}
*/
browseQueueForm.set("messages", messages);
} else
browseQueueForm.set("messages", new ArrayList());
} catch (ListenerException e) {
error("Error occured browsing messages", e);
} finally {
try {
if (it != null) {
it.close();
}
} catch (ListenerException e1) {
log.error(e1);
}
}
// Report any errors we have discovered back to the original form
if (!errors.isEmpty()) {
StoreFormData(browseQueueForm);
saveErrors(request, errors);
return (new ActionForward(mapping.getInput()));
}
// Successfull: store cookie
String cookieValue = "";
cookieValue += "jmsRealm=\"" + form_jmsRealm + "\"";
// separator
cookieValue += " ";
cookieValue += "destinationName=\"" + form_destinationName + "\"";
// separator
cookieValue += " ";
cookieValue += "destinationType=\"" + form_destinationType + "\"";
// separator
cookieValue += " ";
cookieValue += "showPayload=\"" + form_showPayload + "\"";
log.debug("*** value : " + AppConstants.getInstance().getString("WEB_QBROWSECOOKIE_NAME", "WEB_QBROWSECOOKIE"));
Cookie sendJmsCookie = new Cookie(AppConstants.getInstance().getString("WEB_QBROWSECOOKIE_NAME", "WEB_QBROWSECOOKIE"), cookieValue);
sendJmsCookie.setMaxAge(Integer.MAX_VALUE);
log.debug("Store cookie for " + request.getServletPath() + " cookieName[" + sendJmsCookie.getName() + "] " + " cookieValue[" + new StringTagger(cookieValue).toString() + "]");
try {
response.addCookie(sendJmsCookie);
} catch (Throwable e) {
log.warn("unable to add cookie to request. cookie value [" + sendJmsCookie.getValue() + "]");
}
// Forward control to the specified success URI
log.debug("forward to success");
return (mapping.findForward("success"));
}
Aggregations