001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer(s): Michel-Ange ANTON
022: * --------------------------------------------------------------------------
023: * $Id: ApplyConfirmXaResourceAction.java 9680 2006-10-06 12:08:33Z danesa $
024: * --------------------------------------------------------------------------
025: */
026:
027: package org.objectweb.jonas.webapp.jonasadmin.service.jtm;
028:
029: import java.io.IOException;
030: import java.util.ArrayList;
031:
032: import javax.management.ObjectName;
033: import javax.servlet.ServletException;
034: import javax.servlet.http.HttpServletRequest;
035: import javax.servlet.http.HttpServletResponse;
036:
037: import org.apache.struts.action.ActionForm;
038: import org.apache.struts.action.ActionForward;
039: import org.apache.struts.action.ActionMapping;
040: import org.objectweb.jonas.jmx.J2eeObjectName;
041: import org.objectweb.jonas.jmx.JonasManagementRepr;
042: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
043:
044: /**
045: *
046: */
047:
048: public class ApplyConfirmXaResourceAction extends JonasBaseAction {
049:
050: // --------------------------------------------------------- Public Methods
051:
052: /**
053: */
054: public ActionForward executeAction(ActionMapping pMapping,
055: ActionForm pForm, HttpServletRequest pRequest,
056: HttpServletResponse pResponse) throws IOException,
057: ServletException {
058:
059: // String sForward = null;
060:
061: // Form used
062: ItemsXaResourceForm oForm = (ItemsXaResourceForm) m_Session
063: .getAttribute("itemsXaResourceForm");
064:
065: // Current server and domain
066: String currentDomainName = m_WhereAreYou.getCurrentDomainName();
067: String currentJonasServerName = m_WhereAreYou
068: .getCurrentJonasServerName();
069:
070: // Actions
071: try {
072: Object txObject;
073: String[] asParam = new String[1];
074: String[] asSignature = { "java.lang.String" };
075: String jtaResourceName = "JTAResource";
076: ObjectName jtaResourceObjectName = J2eeObjectName
077: .JTAResource(currentDomainName,
078: currentJonasServerName, jtaResourceName);
079:
080: // Commit
081: if (oForm.getAction().equals("commit") == true) {
082: for (int i = 0; i < oForm.getSelectedItems().length; i++) {
083: asParam[0] = oForm.getSelectedItems()[i];
084: txObject = JonasManagementRepr.invoke(
085: jtaResourceObjectName, "commitXAResource",
086: asParam, asSignature,
087: currentJonasServerName);
088: }
089: }
090: // Rollback
091: else if (oForm.getAction().equals("rollback") == true) {
092: for (int i = 0; i < oForm.getSelectedItems().length; i++) {
093: asParam[0] = oForm.getSelectedItems()[i];
094: txObject = JonasManagementRepr.invoke(
095: jtaResourceObjectName,
096: "rollbackXAResource", asParam, asSignature,
097: currentJonasServerName);
098: }
099: }
100: // Forget
101: else if (oForm.getAction().equals("forget") == true) {
102: for (int i = 0; i < oForm.getSelectedItems().length; i++) {
103: asParam[0] = oForm.getSelectedItems()[i];
104: txObject = JonasManagementRepr.invoke(
105: jtaResourceObjectName, "forgetXAResource",
106: asParam, asSignature,
107: currentJonasServerName);
108: }
109: }
110: } catch (Throwable t) {
111: addGlobalError(t);
112: saveErrors(pRequest, m_Errors);
113: return (pMapping.findForward("Global Error"));
114: }
115:
116: oForm.setAction(null);
117: oForm.setSelectedItems(new String[0]);
118:
119: try {
120: // Get container list
121: String mys;
122: String sDate;
123: String sFullTrans;
124: String sTransaction;
125: String sResource;
126: String sState;
127: String sXidcount;
128: Object txObject;
129: String[] myTxInfo;
130: int txInfoSize;
131: ArrayList al = new ArrayList();
132:
133: // Object name used
134: String jtaResourceName = "JTAResource";
135: ObjectName jtaResourceObjectName = J2eeObjectName
136: .JTAResource(currentDomainName,
137: currentJonasServerName, jtaResourceName);
138:
139: txObject = JonasManagementRepr.invoke(
140: jtaResourceObjectName, "getAllRecoveryTx", null,
141: null, currentJonasServerName);
142: myTxInfo = (String[]) txObject;
143:
144: if (txObject != null) {
145: txInfoSize = myTxInfo.length;
146:
147: for (int i = 0; i < txInfoSize; i++) {
148: mys = myTxInfo[i];
149: int myix1 = mys.indexOf("????");
150: sFullTrans = mys.substring(0, myix1);
151: int myix2 = mys.indexOf("????", myix1 + 4);
152: sTransaction = mys.substring(myix1 + 4, myix2);
153: int myix3 = mys.indexOf("????", myix2 + 4);
154: sDate = mys.substring(myix2 + 4, myix3);
155: sXidcount = mys.substring(myix3 + 4);
156: al.add(new TxRecovery(sFullTrans, sTransaction,
157: sDate, sXidcount));
158: }
159: }
160:
161: // Set list in the request
162: pRequest.setAttribute("listRecoveryEntries", al);
163: } catch (Throwable t) {
164: addGlobalError(t);
165: saveErrors(pRequest, m_Errors);
166: return (pMapping.findForward("Global Error"));
167: }
168:
169: // Forward to action
170: return (pMapping.findForward("Jtm Recovery"));
171: }
172:
173: // --------------------------------------------------------- Protected Methods
174:
175: }
|