Dynamically connect to an Oracle database with each JAX-RS request

Asked

Viewed 37 times

2

I’m developing a project on Jboss Seam to provide some services via JAX-RS on Wildfly 9.

The DBMS used is Oracle 10g, and the services that will be made available are form features that the company develops in Oracle Forms.

Legacy system procedures, functions and triggers are strongly based on the oracle user variable, because of the audit.

This behavior (registering the user who performed the operation) needs to be reflected in the call of the Java services I am developing.

There is already, in the calls of this service, a parameter sent via header that has information about the user, so I already know which user will log in.

The issue is to effectively log in with this specific user, since the project’s datasource configuration uses a fixed user.

The datasource is configured in the standalone.xml file

<datasource jta="false" jndi-name="java:jboss/datasources/servicesDS" pool-name="servicesDS" enabled="true" use-ccm="false">
    <connection-url>jdbc:oracle:thin:@<IP>:<Porta>:<SID></connection-url>
    <driver-class>oracle.jdbc.OracleDriver</driver-class>
    <driver>ojdbc6.jar</driver>
    <security>
        <user-name><USER></user-name>
        <password><PASSWORD></password>
    </security>
</datasource>

...and in persistence.xml...

<persistence-unit name="services">
    <jta-data-source>java:jboss/datasources/servicesDS</jta-data-source>
    <properties>
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.proc.param_null_passing" value="true" />
    </properties>
</persistence-unit>

To produce the Entitymanagers:

import java.util.logging.Logger;

import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.faces.context.FacesContext;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

public class Resources {

    @Produces
    @PersistenceContext(unitName = "services")
    private EntityManager em;

    @Produces
    public Logger produceLog(InjectionPoint injectionPoint) {
        return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
    }

    @Produces
    @RequestScoped
    public FacesContext produceFacesContext() {
        return FacesContext.getCurrentInstance();
    }

}

I searched the internet and found something on Oracle Proxy, but there were only suggestions for use for Eclipselink. However, the project has already been carried out with JPA/Hibernate.

Have you ever been through this situation (dynamically configure these connection credentials to each service call)? If so, it was with JPA/Hibernate?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.