Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Database proxy user - Already a proxy session error

ILya CycloneOct 15 2019 — edited Oct 17 2019

One of several application modules in our app requires a proxy user connection to database.

We implement this by overriding prepareSession and beforeDisconnect in application module impl class. This code worked for years in ADF 11g.

After migrating to 12.2.1.3 from time to time I started to see a following method in logs: Already a proxy session

java.sql.SQLException: Already a proxy session

at oracle.jdbc.driver.PhysicalConnection.openProxySession(PhysicalConnection.java:2654) ~[ojdbc8dms.jar:12.2.0.1.0]

at sun.reflect.GeneratedMethodAccessor1455.invoke(Unknown Source) ~[na:na]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_212]

at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_212]

at weblogic.jdbc.common.internal.ConnectionEnv.OracleOpenProxySession(ConnectionEnv.java:822) ~[com.bea.core.datasource6.jar:12.2.1.3]

at weblogic.jdbc.wrapper.Connection.openProxySession(Connection.java:1435) ~[com.bea.core.datasource6.jar:12.2.1.3]

at mycompany.salary.model.SalaryServiceImpl.prepareSession(SalaryServiceImpl.java:91) ~[adflibCabinetSalary.jar:na]

This error is not directly reproducible and apparently happens as consequence of passivation/activation issue.

public class SalaryServiceImpl extends ApplicationModuleImpl implements SalaryService {

    @Override

    protected void prepareSession(Session session) {

        super.prepareSession(session);

        String currentUser = getCurrentUsername();

        String psw = getPasswordFromSession(); // we ask user password additional time on entering this taskflow

                                               // and keep it in #{sessionScope.psw}

        try {

            Properties prop = new Properties();

            prop.put(OracleConnection.PROXY_USER_NAME, currentUser);

            prop.put(OracleConnection.PROXY_USER_PASSWORD, psw);

            OracleConnection conn = getCurrentConnection();

            conn.openProxySession(OracleConnection.PROXYTYPE_USER_NAME, prop); // exception happens here

        } catch (Exception e) {

                throw new JboException(e);

            }

        }

    }

    @Override

    protected void beforeDisconnect() {

        try {

            OracleConnection conn = getCurrentConnection();

            conn.close(OracleConnection.PROXY_SESSION);

        } catch (Exception e) {

          // log

        }

        super.beforeDisconnect();

    }

    private String getCurrentUsername() {

        return ADFContext.getCurrent().getSecurityContext().getUserName();

    }

    private String getPasswordFromSession() {

        return (String) ADFContext.getCurrent().getSessionScope().get("psw");

    }

    private OracleConnection getCurrentConnection() throws SQLException {

        try (PreparedStatement st = getDBTransaction().createPreparedStatement("commit", 1)) {

            OracleConnection oracleConnection = (OracleConnection) st.getConnection();

            return oracleConnection;

        }

    }

}

I'd be grateful for help. If my code is correct? Have anything changed for establishing proxy connection or passivation/activation logic? Any ideas?

Code is based on Anrejus

     * http://andrejusb.blogspot.com/2017/07/adf-12c-bc-proxy-user-db-connection-and.html

     * http://andrejusb.blogspot.com/2012/03/extending-application-module-for-adf-bc.html

Thanks.

Comments
Post Details
Added on Oct 15 2019
2 comments
354 views