how to connect a bluemix app to on-premise db/as400?

坚强是说给别人听的谎言 提交于 2019-12-02 16:29:04

问题


trying to connect a bluemix app (java liberty profile) to our on-premise db/as400 using a secure gateway. Denying or allowing all connection, doesn't change the error message. It seems that the request from the app doesn't reach the secure gateway client (and I don't see messages on sgw client that mentions the connection refused).

How can i resolve that? This the code:

    DB_SERVERNAME=jdbc:as400://xxx-xx-xxx-x.integration.ibmcloud.com:15XXX/dbname

    try {
                Driver driver = new com.ibm.as400.access.AS400JDBCDriver();
                DriverManager.registerDriver(driver);
                System.out.println("Driver Loaded Successfully ...");
                dbConn = DriverManager.getConnection(DB_SERVERNAME, DB_USERNAME, DB_PASSWORD);
                System.out.println("Connected...");
            }   catch (SQLException e) {                
                e.printStackTrace();

            } 

And the error msg is :

Driver Loaded Successfully ...
ERR App [err] java.sql.SQLException: The application requester cannot establish the connection. (Connection refused)
ERR App [err]   at com.ibm.as400.access.JDError.throwSQLException(JDError.java:565)
ERR App [err]   at com.ibm.as400.access.AS400JDBCConnection.setProperties(AS400JDBCConnection.java:3308)
ERR App [err]   at com.ibm.as400.access.AS400JDBCDriver.prepareConnection(AS400JDBCDriver.java:1393)
ERR App [err]   at com.ibm.as400.access.AS400JDBCDriver.initializeConnection(AS400JDBCDriver.java:1230)
ERR App [err]   at com.ibm.as400.access.AS400JDBCDriver.connect(AS400JDBCDriver.java:371)
ERR App [err]   at java.sql.DriverManager.getConnection(Unknown Source)
ERR App [err]   at java.sql.DriverManager.getConnection(Unknown Source)
ERR App [err]   at wasdev.sample.servlet.DBServlet.getDBConnection(DBServlet.java:106)
ERR App [err]   at wasdev.sample.servlet.DBServlet.doGet(DBServlet.java:64)
ERR App [err]   at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
ERR App [err]   at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
ERR App [err]   at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1290)
ERR App [err]   at [internal classes]
ERR App [err]   at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
ERR App [err]   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
ERR App [err]   at java.lang.Thread.run(Unknown Source)
ERR App [err] Caused by:
ERR App [err] java.net.ConnectException: Connection refused
ERR App [err]   at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
ERR App [err]   at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
ERR App [err]   at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
ERR App [err]   at java.net.SocksSocketImpl.connect(Unknown Source)
ERR App [err]   at java.net.Socket.connect(Unknown Source)
ERR App [err]   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
ERR App [err]   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
ERR App [err]   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
ERR App [err]   at java.lang.reflect.Method.invoke(Unknown Source)
App [err]   at com.ibm.as400.access.PortMapper.getSocketConnection(PortMapper.java:273)
ERR App [err]   at com.ibm.as400.access.PortMapper.getServerSocket(PortMapper.java:161)
ERR App [err]   at com.ibm.as400.access.AS400ImplRemote.signonConnect(AS400ImplRemote.java:2334)
ERR App [err]   at com.ibm.as400.access.AS400ImplRemote.signon(AS400ImplRemote.java:2250)
ERR App [err]   at com.ibm.as400.access.AS400.sendSignonRequest(AS400.java:3035)
ERR App [err]   at com.ibm.as400.access.AS400.signon(AS400.java:3910)
ERR App [err]   at com.ibm.as400.access.AS400.connectService(AS400.java:1168)
ERR App [err]   at com.ibm.as400.access.AS400JDBCConnection.setProperties(AS400JDBCConnection.java:3300)
ERR App [err]   ... 32 more

回答1:


Updating based on further discussion in comments.

Getting empty reply from server on your cURL command to the cloud host:port should be generating logs on your SG Client. It should be the equivalent of a successful connection due to how a database would respond to this sort of connection.

This seems to narrow down the issue to how the request is being created in your Bluemix app. Another comment on the initial question suggests that your driver only accepts select ports as input, so the issue might originate there.




回答2:


Reading your logs, the error message

Connection refused

is meaning that the Driver is working fine, but there is a connection issue and in your case, using the Secure Gateway, you should investigate both the AS400 server and the Secure gateway instance

  • #1 is the TCP port 15XXX (the one tried to connect to by the driver following the JDBC url) mapped correctly on the Secure Gateway instance
  • #2a if the #1 is true, is the AS400 server listening on the same TCP port for incoming connections?
  • #2b if #2a is false, is the AS400 server listening on a different TCP port?
  • #3 according to the TCP port listened on by the AS400 server (#2a or #2b) is this port mapped correctly on the Secure Gateway instance, allowing the requests sent to the TCP 15XXX through the Secure Gateway routed correctly to the right port on the AS400 server?
  • #4 if #3 is true, has the AS400 server an internal firewall preventing incoming connections?



回答3:


The JT400 JDBC driver communicates with the IBM i system using the IBM i Host Servers, which each run on different ports. You will need to forward all of these ports through your secure gateway in order for it to work. See this doc for more info (you'll need as-database, as-central, and as-signon at a minimum).

If you need to change the ports used by the app to connect, you can do so by creating an AS400 object and using setServicePort to change the default ports. Then pass the AS400 object to connect instead of using the system, user name, and password.



来源:https://stackoverflow.com/questions/37660064/how-to-connect-a-bluemix-app-to-on-premise-db-as400

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!