use of org.apache.struts.action.ActionForward 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 org.apache.struts.action.ActionForward 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"));
}
use of org.apache.struts.action.ActionForward in project sonar-java by SonarSource.
the class ForwardTag method doEndTag.
/**
* Look up the ActionForward associated with the specified name, and
* perform a forward or redirect to that path as indicated.
*
* @throws JspException if a JSP exception has occurred
*/
public int doEndTag() throws JspException {
// Look up the desired ActionForward entry
ActionForward forward = null;
ModuleConfig config = TagUtils.getInstance().getModuleConfig(pageContext);
if (config != null) {
forward = (ActionForward) config.findForwardConfig(name);
}
if (forward == null) {
JspException e = new JspException(messages.getMessage("forward.lookup", name));
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
// Forward or redirect to the corresponding actual path
String path = forward.getPath();
path = config.getPrefix() + path;
if (forward.getRedirect()) {
this.doRedirect(path);
} else {
this.doForward(path);
}
// Skip the remainder of this page
return (SKIP_PAGE);
}
use of org.apache.struts.action.ActionForward in project sonar-java by SonarSource.
the class TestActionConfigMatcher method buildActionConfig.
private ActionConfig buildActionConfig(String path) {
ActionMapping mapping = new ActionMapping();
mapping.setName("name,{1}");
mapping.setPath(path);
mapping.setScope("request");
mapping.setUnknown(false);
mapping.setValidate(true);
mapping.setPrefix("foo,{1}");
mapping.setSuffix("bar,{1}");
mapping.setType("foo.bar.{1}Action");
mapping.setRoles("public,{1}");
mapping.setParameter("param,{1}");
mapping.setAttribute("attrib,{1}");
mapping.setForward("fwd,{1}");
mapping.setInclude("include,{1}");
mapping.setInput("input,{1}");
ForwardConfig cfg = new ActionForward();
cfg.setName("name");
cfg.setPath("path,{1}");
cfg.setModule("mod{1}");
cfg.setProperty("foo", "bar,{1}");
mapping.addForwardConfig(cfg);
cfg = new ActionForward();
cfg.setName("name2");
cfg.setPath("path2");
cfg.setModule("mod{1}");
mapping.addForwardConfig(cfg);
ExceptionConfig excfg = new ExceptionConfig();
excfg.setKey("foo");
excfg.setType("foo.Bar");
excfg.setPath("path");
mapping.addExceptionConfig(excfg);
excfg = new ExceptionConfig();
excfg.setKey("foo2");
excfg.setType("foo.Bar2");
excfg.setPath("path2");
mapping.addExceptionConfig(excfg);
mapping.setProperty("testprop", "testval");
mapping.setProperty("testprop2", "test{1}");
mapping.freeze();
return mapping;
}
use of org.apache.struts.action.ActionForward in project zoj by licheng.
the class AddUserRoleAction method execute.
/**
* AddUserRoleAction.
*
* @param mapping
* action mapping
* @param form
* action form
* @param request
* http servlet request
* @param response
* http servlet response
*
* @return action forward instance
*
* @throws Exception
* any errors happened
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
// check admin
ActionForward forward = this.checkAdmin(mapping, context);
if (forward != null) {
return forward;
}
long userId = Utility.parseLong(String.valueOf(context.getRequest().getParameter("userId")));
long roleId = Utility.parseLong(String.valueOf(context.getRequest().getParameter("roleId")));
UserProfile user = UserManager.getInstance().getUserProfile(userId);
if (user == null) {
return this.handleSuccess(mapping, context, "failure");
}
PersistenceManager.getInstance().getAuthorizationPersistence().addUserRole(userId, roleId);
return this.handleSuccess(mapping, context, "success", "?userId=" + userId);
}
Aggregations