尝试使用安全网关将bluemix应用程序(java自由配置文件)连接到我们的内部部署db/as400。拒绝或允许所有连接不会更改错误消息。来自应用程序的请求似乎没有到达安全网关客户端(我在sgw客户端上没有看到提到连接被拒绝的消息)。
我该如何解决?这是代码:
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();
}
错误消息为:
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
根据评论中的进一步讨论进行更新。
将cURL命令上的empty reply from server
发送到云主机:端口应该会在SG客户端上生成日志。它应该相当于一个成功的连接,因为数据库将如何响应这种连接。
这似乎将问题缩小到如何在Bluemix应用程序中创建请求。对最初问题的另一条评论表明,您的驱动程序只接受选择端口作为输入,因此问题可能源于此。
读取日志时,错误消息
连接被拒绝
意味着驱动程序工作正常,但存在连接问题,在您使用安全网关的情况下,您应该调查AS400服务器和安全网关实例
- #1是安全网关实例上正确映射的TCP端口15XXX(JDBC url后面的驱动程序尝试连接的端口)
- #2a如果#1为真,AS400服务器是否在同一TCP端口上侦听传入连接
- #2b如果#2a为false,AS400服务器是否正在侦听不同的TCP端口
- #3根据AS400服务器监听的TCP端口(#2a或#2b),该端口是否正确映射到安全网关实例上,允许通过安全网关发送到TCP 15XXX的请求正确路由到AS400服务器上的正确端口
- #4如果#3是真的,那么AS400服务器是否有防止传入连接的内部防火墙
JT400 JDBC驱动程序使用IBM i主机服务器与IBM i系统通信,每个主机服务器运行在不同的端口上。您需要通过安全网关转发所有这些端口才能使其工作。请参阅此文档以获取更多信息(您至少需要作为数据库、中心和登录)。
如果您需要更改应用程序用于连接的端口,可以通过创建AS400对象并使用setServicePort更改默认端口来实现。然后传递要连接的AS400对象,而不是使用系统、用户名和密码。