I would recommend checking out the authentication framework at http://cocoon.apache.org/2.1/developing/webapps/authentication.html. It does almost exactly what you're trying to do. You should be able to combine the 'auth-protect' action with the SQL transformer to do everything you're doing below with off-the-shelf Cocoon components, without writing any Java code.
Morley -----Original Message----- From: beyaNet Consultancy [mailto:[EMAIL PROTECTED] Sent: Saturday January 17, 2004 4:34 PM To: [EMAIL PROTECTED] Subject: Action problem hi, I have written an action which is meant to, for the meantime, return a single column value. The problem is that you continually keep getting redirected to the login page, which is meant to happen if a map is not returned successfully. What am I missing? This action is called from a login page as so: 1.login.html <form action="testpage" method="post"? 2. sitemap <map:match pattern="testpage"> <map:act type="get-detail2"> <map:generate type="file" src="content/main.xml" /> <map:transform scr="style/main.xsl"> <map:parameter name="first_name" value="{first_name}" /> </map:transform> </map:act> <map:redirect-to uri="login.html" /> </map:match> 3. Action package test; import org.apache.avalon.excalibur.datasource.DataSourceComponent; import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.component.ComponentSelector; import org.apache.avalon.framework.parameters.Parameters; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.avalon.framework.component.Composable; import org.apache.avalon.framework.activity.Disposable; import org.apache.cocoon.Constants; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Redirector; import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.acting.AbstractAction; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.sql.SQLException; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; public class GetUserDetail2 extends AbstractAction implements ThreadSafe, Composable, Disposable { protected ComponentSelector dbselector; protected ComponentManager manager; public void compose(ComponentManager manager) throws ComponentException { this.dbselector = (ComponentSelector) manager.lookup(DataSourceComponent.ROLE + "Selector"); } protected final DataSourceComponent getDataSource(String pool) throws ComponentException { return (DataSourceComponent) this.dbselector.select(pool); } public Map act ( Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters param) throws Exception { Request request = ObjectModelHelper.getRequest(objectModel); Map map = new HashMap(); DataSourceComponent dataSource = getDataSource("postgresql"); Connection conn = null; try { conn = dataSource.getConnection(); Statement stmt = conn.createStatement(); String cmd = "Select user_id, first_name, last_name, address1, address2, address3, postcode, country, email, home_telephone, mobile_telephone, date_joined from usertbl where username = 'x' and userpassword = 'y'"; ResultSet rs = stmt.executeQuery(cmd); if (rs.next()) { map.put("first_name", rs.getString(1)); } rs.close(); stmt.close(); }catch (Exception e){ getLogger().error("Query failed: ", e); }finally { try { if (conn != null) conn.close(); }catch (SQLException sqe) { getLogger().warn("Error closing the datasource", sqe); } } return (map); } public void dispose() { this.manager.release(dbselector); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
