I am using version 3.0EE to build an application for a client. The client is using Oracle for the enterprise database. The project requires my team to use a mechanism similar to Oracle's Proxy Authentication.
For each request to the database, we are forced to call a stored procedure in Oracle passing the UserID of the user currently logged into the web application. This stored procedure sets up some security and some role stuff in the database for the user.
I was not sure of the best approach in SmartGWT, but here is what I came up with. We are making use of the ds.xml files, but I did not want to have to go thru a DMI handler for each ds.xml operation. I wanted to the call to the stored procedure to not add any complexity to the ds.xml operations. We already extended the IDACall to make use of the build in role management feature.
I decided to put the call to the stored procedure into our servlet that now extends IDACall. Here is some of the code:
You can see that I have replace the line "processRPCTransaction(rpc, context);" with "setUser(rpc, context, user.getUserID());". This works as intended in terms of successfully calling the stored procedure before each operation defined in a ds.xml file. The only problem is that I get the following error: "java.lang.Exception: No current connection for 'null'". This occurs at the line that that tries to commit the transaction - "SQLTransaction.commitTransaction(rpc)".
My guess is that the call to processRPCTransaction commits the transaction and sets the connection object to null. Can you just verify this for me or suggest a better approach to the one that I have already taken?
For each request to the database, we are forced to call a stored procedure in Oracle passing the UserID of the user currently logged into the web application. This stored procedure sets up some security and some role stuff in the database for the user.
I was not sure of the best approach in SmartGWT, but here is what I came up with. We are making use of the ds.xml files, but I did not want to have to go thru a DMI handler for each ds.xml operation. I wanted to the call to the stored procedure to not add any complexity to the ds.xml operations. We already extended the IDACall to make use of the build in role management feature.
I decided to put the call to the stored procedure into our servlet that now extends IDACall. Here is some of the code:
Code:
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); Object user = session.getAttribute("SESSION_USER"); if (user.getRoles() != null) { try { RequestContext context = RequestContext.instance(this, request, response); RPCManager rpc = new RPCManager(request, response); rpc.setAuthenticated(true); rpc.setUserRoles((String) roles); // call processRPCTransaction() to iterate through all RPCRequests and // DSRequests and execute them //processRPCTransaction(rpc, context); setUser(rpc, context, user.getUserID()); } catch (Throwable e) { handleError(response, e); } } else { super.processRequest(request, response); } } private void setUser(RPCManager rpc, RequestContext, String userID) { Connection conn = null; CallableStatement cstmt = null; ResultSet rs = null; try { SQLTransaction.startTransaction(rpc); conn = SQLTransaction.getConnection(rpc); cstmt = conn.prepareCall("{ call xyz.THE_STORED_PROC(?) }"); cstmt.setString(1, userID); cstmt.execute(); processRPCTansaction(rpc, context); SQLTransaction.commitTransaction(rpc); } catch (Exception e) { SQLTransaction.rollbackTransaction(rpc); throw e; } finally { if (rs != null) rs.close(); if (cstmt != null) cstmt.close(); if (conn != null) conn.close(); } }
My guess is that the call to processRPCTransaction commits the transaction and sets the connection object to null. Can you just verify this for me or suggest a better approach to the one that I have already taken?
Comment