We have spring boot application (version => 2.4.3) that needs to run in weblogic 12.2.1.4.0. When we give url, name and password like below, it successfully deploy and can get connection, but when we deploy via jndi like below. It is getting error. How can we fix this? We already tried these links, but it is not solved our problem.
https://weblogic.developer.interest.jdbc.narkive.com/2JvpDwJc/weblogic-jdbc-extensions-poolpermissionssqlexception
https://groups.google.com/g/weblogic.developer.interest.jdbc/c/SobQpZNwrfM?pli=1
https://groups.google.com/g/weblogic.developer.interest.jdbc/c/lkTGus61SNE
Weblogic errror=>
weblogic.common.resourcepool.ResourcePermissionsException: User "<anonymous>" does not have permission to perform operation "reserve" on resource "myusername" of module "none" of application "none" of type "ConnectionPool"
weblogic.jdbc.extensions.PoolPermissionsSQLException: weblogic.common.resourcepool.ResourcePermissionsException: User "<anonymous>" does not have permission to perform operation "reserve" on resource "myusername" of module "none" of application "none" of type "ConnectionPool"
at weblogic.jdbc.common.internal.JDBCUtil.wrapAndThrowResourceException(JDBCUtil.java:281)
at weblogic.jdbc.common.internal.WLDataSourceImpl.getPoolConnection(WLDataSourceImpl.java:563)
at weblogic.jdbc.common.internal.WLDataSourceImpl.getConnectionInternal(WLDataSourceImpl.java:660)
Working properties =>
# Oracle settings
spring.datasource.url=jdbc:oracle:thin:#10.10.10.10:1521:MYDB
spring.datasource.username=myusername
spring.datasource.password=userpassword
spring.datasource.driver.class=oracle.jdbc.driver.OracleDriver
not working properties =>
spring.datasource.jndi-name=jdbc/ABC
spring.datasource.driver.class=oracle.jdbc.driver.OracleDriver
Error occur in this code 'dataSource.getConnection()'
#Component
#Slf4j
public class SysUrlLinkDao {
#Autowired
private DataSource dataSource;
public ImagePojo loadImgPathLink(String value) {
ImagePojo generic = new ImagePojo();
String query = " SELECT * FROM IMG_PATH WHERE PARAM_VALUE =?";
try (Connection connection = dataSource.getConnection();
PreparedStatement preStatement = connection.prepareStatement(query)) {
preStatement.setString(1, value);
try (ResultSet rset = preStatement.executeQuery()) {
while (rset.next()) {
generic = new ImagePojo();
generic.setImagePath(rset.getString("PATH"));
generic.setLinkPath(rset.getString("LINK"));
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return generic;
}
}
After removing 'Locale.setDefault(new Locale("tr", "TR"));' in ContextListener, it can get connection. I don't understand why it gets faults from weblogic datasource. Secondly, when we deploy our war package to local weblogic. It is also gets datasource error and after logging off console, we cannot log in. Admin console also affected. We tried correct username and password, but it gives error like this 'Access denied'. All these has solved with removing default locale.
Related
I am writing a spring boot application and I am trying to create a callable stored procedure, however I am having issues with the connection. I originally have the connection set up using Hibernate and JPA, by incorporating the spring.datasource in my application.properties file. So I am looking for a way to ignore setting up the connection and have it automatically call the application.propeties file for when it needs to make the call.
Application Properties:
spring.datasource.url=jdbc:sqlserver://server\\RRSHRD01;databaseName=db_name
spring.datasource.username=User
spring.datasource.password=password
spring.datasource.databasename=db_nam,e
spring.datasource.databaseschema=APD
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
spring.jpa.hibernate.ddl-auto = none
Java code:
Connection con = null;
try {
String url = "jdbc:sqlserver://server\\\\RRSHRD01;databaseName=dn_name";
con = DriverManager.getConnection(url, "User", "password");
System.out.println("Success");
} catch (Exception e) {
e.printStackTrace();
}
So above is the code I want to replace, instead of calling the connection I want it to automatically look and retrieve it from my application properties. I want to do this because when I do it the normal way the session always times out.
I´m quite new to Java EE and have a comprehension question about running an application in the application server, in my case Wildfly 10.
My Problem is, that objects apparently keep their state, once they where instantiated on application start up, even if i close and re-open the browser session. In my case, i´m using a bean that tries to open a jdbc connection and writes to the facelet´s messages in case something goes wrong.
So, to test the scenario i shut down the database and started the application. As expected, the error message comes up. Now, after restarting the database, it is still not connecting and giving me the "no database" message. A complete restart of the application server is necessary in order to have the bean start over new.
So the question is, what do i have to do, to re-initialize all involved object instances of my application?
Here is the code of the bean in question:
#Named
#Stateless
public class CoworkerProducer
{
#Inject
private EntityManager em;
#Resource(lookup="java:/JMPostgres")
private DataSource dsJM;
public void addCoworkers(Long projectId)
{
Project managedProject = em.find(Project.class, projectId);
Long jmId = managedProject.getJmId();
try {
Connection con = dsJM.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT * FROM employees e, departments d WHERE e.department_id = d.id AND d.project_id = " + jmId);
ResultSet result = ps.executeQuery();
while(result.next()){
Coworker cow = new Coworker();
cow.setProject(managedProject);
em.persist(cow);
}
}
catch (SQLException e) {
final FacesContext facesContext = FacesContext.getCurrentInstance();
facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "no database!", null));
}
}
}
It's best practice to let the container, in your case Wildfly 10, handle the database connection, You can configure that in the standalone.xml file.
Documentation for configuration
In your case, create a (pooled) Datasource in Wildfly and enable connection validation and connection retries in Wildfly. That way, Wildfly will manage your database connection and reestablish connection if it failed.
Once you installed the MySQL driver in Wildfly, you can create the datasource on the Wildfly admin console (by default it runs on port 9990) or with the JBoss CLI.
Further reading:
Datasource configuration
I'm trying get the data base connection using JNDI Name. I'm sing Websphere application server.
Please find below code.
public class GetDbConnection {
private static Connection getConnection() throws Exception {
Hashtable<String, String> pdEnv = new Hashtable<String, String>();
pdEnv.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
pdEnv.put(Context.PROVIDER_URL, "iiop://10.70.52.228:30305/");
Connection connection = null;
try{
Context ctx = new InitialContext(pdEnv);
System.out.println("Initial Context: "+ctx.getNameInNamespace());
DataSource ds = (DataSource) ctx.lookup("jdbc/siperian-mdmtrg01-cmx_ors-ds");
System.out.println("DataSource Object : "+ds.getClass());
connection = ds.getConnection();
System.out.println("Connection established ::" +connection);
}catch(Exception ex){
ex.printStackTrace();
}
return connection; }
I'm getting below error.This is the full print stack trace.
Initial Context: MDMTRG2Cell01/clusters/InformaticaMDM_Cluster
J2CA0036E: An exception occurred while invoking method
setDataSourceProperties on
com.ibm.ws.rsadapter.spi.WSManagedConnectionFactoryImpl used by
resource jdbc/siperian-mdmtrg01-cmx_ors-ds :
java.lang.NoClassDefFoundError:
com/ibm/websphere/appprofile/accessintent/AccessIntent
Please help me in this reagrd.
The cause of the problem is that the WebSphere Application Server Java™ virtual machine (JVM) could not find the JDBC JAR file.
Example if we are using DB2 datasource we need DB2 JAR, in websphere classpath that contains the implementation class.
The most likely cause is that the classpath of the JDBC Provider configuration has used a WebSphere Application Server variable, for example, DB2_JDBC_DRIVER_PATH, which has not been set for the corresponding WebSphere Application Server jvm process.
This could also be caused on Unix based servers by the userID not having permission to access the jar that contains the class.
I have wrote Java Client application (bean for Oracle form) to access the data through "jdbcdatasource" created on Weblogic 12c. It works fine when I am running on desktop, but when I am embedding on oracle forms as a bean, it gives following error:
java.lang.ClassNotFoundException: weblogic.jdbc.common.internal.RmiDataSource_12210_WLStub
java bean is an executable jar file includes all the dependency jar file, and it is executed independently by double click.
Here is a code:
Context ctx = null;
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL, "t3:" + url + ":7001");
if(sUser != null && sPwd != null){
ht.put(Context.SECURITY_PRINCIPAL, sUser);
ht.put(Context.SECURITY_CREDENTIALS, sPwd);
}
ctx = new InitialContext(ht);
System.out.println("!!! WebLogic Server Connection Done!");
javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("myDatasource");
java.sql.Connection conn = ds.getConnection();
System.out.println("!!! DataSource Connection Done!");
In the environment of Oracle forms it connect to the weblogic server but could not access the data source by displaying above error.
Any suggestion?
Just to make things clear to me.
When you say :
"to access the data through "jdbcdatasource" created on Weblogic 12c."
and you code shows:
"javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("myDatasource");"
The lookup parameter value shouldn't be exactly like "jdbcdatasource" instead of "myDataSource' as you stated before or it was just to explain your situation ?
I have many tests which access our Oracle DB without a problem, however when I run these tests along with other tests in our codebase which use a keystore, the tests that interact with the DB are no longer able to connect. Here is the exception they get:
Caused by: java.sql.SQLException: ORA-01017: invalid username/password; logon denied
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:388)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:381)
at oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:564)
at oracle.jdbc.driver.T4CTTIoauthenticate.processError(T4CTTIoauthenticate.java:431)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186)
at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:366)
at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:752)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:359)
at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:531)
at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:221)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290)
at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:877)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:851)
... 68 more
Obviously the username and password are still correct. I'm having a really hard time figuring out what in our code is causing the connection to fail, and I don't really know how to debug what's happening when the Oracle driver tries to connect. I'm using the Oracle thin driver with Oracle 11g. We use Spring, Hibernate, and the Apache Commons DBCP. It seems like the driver is maybe trying to establish an SSL connection to the DB? I'm not sure though. I seem to remember a very similar issue with SQL Server when we were still using that, at the time I just ignored it. Right now we run the tests that interact with the keystore in a separate batch and JVM.
Any help would be greatly appreciated.
UPDATED
I did a bunch more debugging and finally traced this down to our use of the wss4j library (version 1.5.9) via Spring-WS. Eventually the WSSConfig class gets to a set of code that does this:
int ret = 0;
for (int i = 0; i < provs.length; i++) {
if ("SUN".equals(provs[i].getName())
|| "IBMJCE".equals(provs[i].getName())) {
ret =
java.security.Security.insertProviderAt(
(java.security.Provider) c.newInstance(), i + 2
);
break;
}
}
Immediately after this code my connections to Oracle stop working. It looks like when the insertProviderAt method is called using a bouncy castle provider my Oracle connection starts failing. Any ideas?
Minimal Test Case
The first connection attempt succeeds, but the second attempt fails.
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:#server/servicename", "username", "password");
conn.prepareStatement("select * from dual").getResultSet();
conn.close();
org.apache.ws.security.WSSConfig.getDefaultWSConfig();
conn = DriverManager.getConnection("jdbc:oracle:thin:server/servicename", "username", "password");
conn.prepareStatement("select * from dual").getResultSet();
conn.close();
WSSConfig Initialize Method
private synchronized void
staticInit() {
if (!staticallyInitialized) {
org.apache.xml.security.Init.init();
if (addJceProviders) {
/*
* The last provider added has precedence, that is if JuiCE can be added
* then WSS4J uses this provider.
*/
addJceProvider("BC", "org.bouncycastle.jce.provider.BouncyCastleProvider");
addJceProvider("JuiCE", "org.apache.security.juice.provider.JuiCEProviderOpenSSL");
}
Transform.init();
try {
Transform.register(
STRTransform.implementedTransformURI,
"org.apache.ws.security.transform.STRTransform"
);
} catch (Exception ex) {
if (log.isDebugEnabled()) {
log.debug(ex.getMessage(), ex);
}
}
staticallyInitialized = true;
}
}
The add sign in the second connection string is missing
logon denied error can be shown if in oracle the parameter SEC_CASE_SENSITIVE_LOGON is set true. You can check it via SHOW PARAMETER SEC_CASE_SENSITIVE_LOGON and alter it through ALTER SYSTEM SET SEC_CASE_SENSITIVE_LOGON = FALSE;
Now the error should get resolved.
1.
Modify the file
%JAVA_HOME%/jre/lib/security/java.security
security.provider.10=org.bouncycastle.jce.provider.BouncyCastleProvider
Example:
security.provider.1=sun.security.provider.Sun
security.provider.2=sun.security.rsa.SunRsaSign
security.provider.3=com.sun.net.ssl.internal.ssl.Provider
security.provider.4=com.sun.crypto.provider.SunJCE
security.provider.5=sun.security.jgss.SunProvider
security.provider.6=com.sun.security.sasl.Provider
security.provider.7=org.jcp.xml.dsig.internal.dom.XMLDSigRI
security.provider.8=sun.security.smartcardio.SunPCSC
security.provider.9=sun.security.mscapi.SunMSCAPI
security.provider.10=org.bouncycastle.jce.provider.BouncyCastleProvider
or
2.
WSSConfig.setAddJceProviders(false);