i'm trying to generate code from a MySQL database, which I connect to over SSL. I got 3 files from the guy who set up the database (client-cert.pem, client-key.pem, ca-cert.pem)
To connect to the database in Java I first had to solve another problem with the certificates. With the help of http://bugs.mysql.com/bug.php?id=68957 and the answer from "[17 Apr 2013 9:04] Alexander Soklakov" , I mananged to get the JDBC connection to work as expected in my Java code.
But now I don't know where to configure SSL in JOOQs library.xml. Where do I provide the *.pem files? Or my created trust- & keystore? Without configuration of SSL I get
Jun 11, 2014 1:53:40 PM org.jooq.tools.JooqLogger info
Information: Initialising properties : ./library.xml
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
javax.net.ssl.SSLException
MESSAGE: Unsupported record version Unknown-0.0
STACKTRACE:
javax.net.ssl.SSLException: Unsupported record version Unknown-0.0
at sun.security.ssl.InputRecord.readV3Record(Unknown Source)
at sun.security.ssl.InputRecord.read(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.mysql.jdbc.ExportControlled.transformSocketToSSLSocket(ExportControlled.java:72)
at com.mysql.jdbc.MysqlIO.negotiateSSLConnection(MysqlIO.java:4237)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1222)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2558)
at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.jooq.util.GenerationTool.run(GenerationTool.java:206)
at org.jooq.util.GenerationTool.main(GenerationTool.java:173)
at org.jooq.util.GenerationTool.main(GenerationTool.java:160)
** END NESTED EXCEPTION **
Last packet sent to the server was 396 ms ago.
at com.mysql.jdbc.ExportControlled.transformSocketToSSLSocket(ExportControlled.java:87)
at com.mysql.jdbc.MysqlIO.negotiateSSLConnection(MysqlIO.java:4237)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1222)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2558)
at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.jooq.util.GenerationTool.run(GenerationTool.java:206)
at org.jooq.util.GenerationTool.main(GenerationTool.java:173)
at org.jooq.util.GenerationTool.main(GenerationTool.java:160)
Jun 11, 2014 1:53:41 PM org.jooq.tools.JooqLogger error
Schwerwiegend: Cannot read ./library.xml. Error : Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
javax.net.ssl.SSLException
MESSAGE: Unsupported record version Unknown-0.0
STACKTRACE:
javax.net.ssl.SSLException: Unsupported record version Unknown-0.0
at sun.security.ssl.InputRecord.readV3Record(Unknown Source)
at sun.security.ssl.InputRecord.read(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.mysql.jdbc.ExportControlled.transformSocketToSSLSocket(ExportControlled.java:72)
at com.mysql.jdbc.MysqlIO.negotiateSSLConnection(MysqlIO.java:4237)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1222)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2558)
at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.jooq.util.GenerationTool.run(GenerationTool.java:206)
at org.jooq.util.GenerationTool.main(GenerationTool.java:173)
at org.jooq.util.GenerationTool.main(GenerationTool.java:160)
** END NESTED EXCEPTION **
Last packet sent to the server was 396 ms ago.
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
javax.net.ssl.SSLException
MESSAGE: Unsupported record version Unknown-0.0
STACKTRACE:
javax.net.ssl.SSLException: Unsupported record version Unknown-0.0
at sun.security.ssl.InputRecord.readV3Record(Unknown Source)
at sun.security.ssl.InputRecord.read(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.mysql.jdbc.ExportControlled.transformSocketToSSLSocket(ExportControlled.java:72)
at com.mysql.jdbc.MysqlIO.negotiateSSLConnection(MysqlIO.java:4237)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1222)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2558)
at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.jooq.util.GenerationTool.run(GenerationTool.java:206)
at org.jooq.util.GenerationTool.main(GenerationTool.java:173)
at org.jooq.util.GenerationTool.main(GenerationTool.java:160)
** END NESTED EXCEPTION **
Last packet sent to the server was 396 ms ago.
at com.mysql.jdbc.ExportControlled.transformSocketToSSLSocket(ExportControlled.java:87)
at com.mysql.jdbc.MysqlIO.negotiateSSLConnection(MysqlIO.java:4237)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1222)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2558)
at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.jooq.util.GenerationTool.run(GenerationTool.java:206)
at org.jooq.util.GenerationTool.main(GenerationTool.java:173)
at org.jooq.util.GenerationTool.main(GenerationTool.java:160)
Jun 11, 2014 1:53:41 PM org.jooq.tools.JooqLogger error
Schwerwiegend: Usage : GenerationTool <configuration-file>
My library.xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-2.5.0.xsd">
<!-- Configure the database connection here -->
<jdbc>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://server:3306/dbname?useSSL=true&requireSSL=true&verifyServerCertificate=false;</url>
<user>user</user>
<password>pass</password>
</jdbc>
<generator>
<!-- The default code generator. You can override this one, to generate your own code style
Defaults to org.jooq.util.DefaultGenerator -->
<name>org.jooq.util.DefaultGenerator</name>
<database>
<!-- The database type. The format here is:
org.util.[database].[database]Database -->
<name>org.jooq.util.mysql.MySQLDatabase</name>
<!-- The database schema (or in the absence of schema support, in your RDBMS this
can be the owner, user, database name) to be generated -->
<inputSchema>dbname</inputSchema>
<!-- All elements that are generated from your schema (several Java regular expressions, separated by comma)
Watch out for case-sensitivity. Depending on your database, this might be important! -->
<includes>smv_.*</includes>
<!-- All elements that are excluded from your schema (several Java regular expressions, separated by comma).
Excludes match before includes -->
<excludes></excludes>
</database>
<target>
<!-- The destination package of your generated classes (within the destination directory) -->
<packageName>my.package</packageName>
<!-- The destination directory of your generated classes -->
<directory>./src</directory>
</target>
</generator>
</configuration>
I also could not find any hints, when I took a look at the schema under http://www.jooq.org/xsd/jooq-codegen-2.5.0.xsd
Right now it looks like I have to give up on using JOOQ :(
Edit: I use Eclipse to generate the JOOQ code, like explained in: http://www.jooq.org/doc/3.0/manual/code-generation/codegen-configuration/ under "Run code generation from Eclipse".
If you need a more special way to set up your database connection, the right way to go forward is probably by using programmatic code generation configuration. This is documented here:
http://www.jooq.org/doc/latest/manual/code-generation/codegen-programmatic/
We (unfortunately) hadn't explicitly documented this yet, but you can pass a JDBC connection explicitly to the GenerationTool
by calling setConnection()
Solution, based on the accepted answer of Lukas Eder
After creating the truststore and keystore (scroll down to [17 Apr 2013 9:04] Alexander Soklakov), I could generate the code with the following class, where I get an SSL database connection and use it for the JOOQ Generator:
import java.sql.Connection;
import org.jooq.util.GenerationTool;
import org.jooq.util.jaxb.Configuration;
import org.jooq.util.jaxb.Database;
import org.jooq.util.jaxb.Generator;
import org.jooq.util.jaxb.Target;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
public class JooqGenerator {
public static void main(String[] args) throws Exception {
MysqlDataSource mysqlDS = new MysqlDataSource();
mysqlDS.setUseSSL(true);
mysqlDS.setRequireSSL(true);
mysqlDS.setClientCertificateKeyStoreUrl(".../keystore");
mysqlDS.setClientCertificateKeyStorePassword("keystore-pw");
mysqlDS.setTrustCertificateKeyStoreUrl(".../truststore");
mysqlDS.setTrustCertificateKeyStorePassword("truststore-pw");
mysqlDS.setServerName("server");
mysqlDS.setPort(3306);
mysqlDS.setDatabaseName("databasename");
Connection connection = mysqlDS.getConnection("user", "password");
Configuration configuration = new Configuration()
.withGenerator(new Generator()
.withName("org.jooq.util.DefaultGenerator")
.withDatabase(new Database()
.withName("org.jooq.util.mysql.MySQLDatabase")
.withIncludes(".*")
.withExcludes("")
.withInputSchema("databasename"))
.withTarget(new Target()
.withPackageName("my.package.name")
.withDirectory("./src")));
GenerationTool tool = new GenerationTool();
tool.setConnection(connection);
tool.run(configuration);
}
}
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.