简体   繁体   中英

Tomcat connection to Oracle via TCPS: The Network Adapter could not establish the connection

I have a document management system as a Tomcat servlet with a separate config.xml. The DMS system needs a database for correct functionality. In this case an Oracle 19c. I want to encrypt the connection between the Tomcat and Oracle for security reasons. For this I created a wallet under Oracle 19c via orapki with a self signed certificate. Afterwards the listener.ora, sq.net.ora and tnsnames.ora were adapted accordingly. in the config.xml of the servlet I changed the connection string to TNS. Via TCP I get correctly a connection to the Oracle server. Over TCPs the error message, according to the heading.

Via SQLplus I can correctly establish a connection via TCPs. Where else could I have an error here?

My environment:

Server1:
     Linux Oracle Server 7.8
     Oracle 19c
     Hostname: oracleserver.localdomain
Server2:
    Windows Server 2022 Datacenter
    Apache Tomcat 9.0.37
    OpenJDK 15.0.1+9-18
    Hostname elo

ORA-Files from the Oracle Server:

listener.ora

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = oracleserver.localdomain)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCPS)(HOST = oracleserver.localdomain)(PORT = 2484))
    )
  )

WALLET_LOCATION = 
   (SOURCE =
     (METHOD = FILE)
     (METHOD_DATA =
       (DIRECTORY = /u01/app/oracle/product/19.0.0/dbhome_1/wallets/server_wallet)
     )
   )
 
SSL_CLIENT_AUTHENTICATION = FALSE

SQ.net.ora

SQLNET.AUTHENTICATION_SERVICES = (BEQ,TCPS)

NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)

WALLET_LOCATION = 
   (SOURCE =
     (METHOD = FILE)
     (METHOD_DATA =
       (DIRECTORY = /u01/app/oracle/product/19.0.0/dbhome_1/wallets/server_wallet)
     )
   )
 
SSL_CLIENT_AUTHENTICATION = FALSE

tnsnames.ora

LISTENER =
  (ADDRESS = (PROTOCOL = TCP)(HOST = oracleserver.localdomain)(PORT = 1521))
  (ADDRESS = (PROTOCOL = TCPS)(HOST = oracleserver.localdomain)(PORT = 2484))

ELO =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = oracleserver.localdomain)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = elo)
    )
  )

ELOPDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCPS)(HOST = oracleserver.localdomain)(PORT = 2484))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = elopdb)
    )
  )

For the Apache Tomcat i set the following Java Options:

-Djava.net.preferIPv4Stack=true
-Doracle.net.ssl_cipher_suites=SSL_DH_anon_WITH_3DES_EDE_CBC_SHA, SSL_DH_anon_WITH_ C4_128_MD5, SSL_DH_anon_WITH_DES_CBC_SHA

My JDBC-Connection String:

jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL=TCPS)(HOST=oracleserver)(PORT=2484)))(CONNECT_DATA=(SERVICE_NAME=ELOPDB)(SERVER=DEDICATED)))

the exact error message:

19:45:25.690 WARN  eloix-init-2 init-2 (DBConnection.java:486)                  - Could not establish connection using jdbcurl=jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL=TCPS)(HOST=oracleserver)(PORT=2484)))(CONNECT_DATA=(SERVICE_NAME=ELOPDB)(SERVER=DEDICATED))), I/O-Fehler: The Network Adapter could not establish the connection
19:45:25.695 WARN  eloix-init-2 init-2 (IXServlet$InitThread.java:539)          - Initialization error, retry after 10s
java.sql.SQLException: java.sql.SQLException: Cannot get connection from Driver Manager. DB[1] Command=""
    at de.elo.ix.db.DBConnection.throwException(DBConnection.java:175)
    at de.elo.ix.db.DBConnection.internalConnect(DBConnection.java:583)
    at de.elo.ix.db.DBConnection.connect(DBConnection.java:357)
    at de.elo.ix.data.DBFactory.createAndConnect(DBFactory.java:14)
    at de.elo.ix.exec.ServerObject.init(ServerObject.java:1138)
    at de.elo.ix.exec.ServerObjectHolderImpl.init(ServerObjectHolderImpl.java:47)
    at de.elo.ix.IXServlet$InitThread.run(IXServlet.java:521)
Caused by: java.sql.SQLException: Cannot get connection from Driver Manager.
    at de.elo.ix.db.DBConnection.internalConnect(DBConnection.java:551)
    ... 5 common frames omitted

i hope you can see my mistake...

as a possible solution I have installed the Oracle client tools on the Windows server and checked the specification of an alias name as the connection string. Unfortunately the same error. A SQL Plus connection via TCPs worked. Also an openssl s_client -connect oracleserver:2484.

Additionally I had checked the following parameters as Java options unfortunately with the same result

-Doracle.net.wallet_location=D:\App\Oracle\product\19.3.0\dbhome_1\network\admin
-Doracle.net.tns_admin=D:\App\Oracle\product\19.3.0\dbhome_1\network\admin

If you are using Oracle Wallets then you should have oraclepki.jar, osdt_core.jar, osdt_cert.jar in the classpath as well. Please check out the blog for some specific examples related to TCPS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM