Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to connect to MySQL #21

Closed
justin-ad opened this issue Apr 1, 2019 · 3 comments · Fixed by #26
Closed

Unable to connect to MySQL #21

justin-ad opened this issue Apr 1, 2019 · 3 comments · Fixed by #26

Comments

@justin-ad
Copy link

Following the README, I clone the project and then perform the following steps:

  1. mvn install - no issues here
  2. mvn jetty:run - no issues; I'm able to access the web UI as expected. This is using Derby as indicated in the README.
  3. Run local MySQL:
    • docker run --name hapi-mysql -e MYSQL_ROOT_PASSWORD=mypassword -p 3306:3306 -d mysql:5
    • Connect to local MySQL with DB client and run the following to create user and hapi_dstu3 database:
CREATE USER 'hapiDbUser'@'localhost' IDENTIFIED BY 'hapiDbPass';
CREATE DATABASE hapi_dstu3;
GRANT ALL PRIVILEGES ON hapi_dstu3.* to 'hapiDbUser'@'localhost';
FLUSH PRIVILEGES;

Success! Everything looks good thus far.

  1. Update the hapi.properties file as indicated in the README
datasource.driver=com.mysql.cj.jdbc.Driver
datasource.url=jdbc:mysql:https://localhost:3306/hapi_dstu3
datasource.username=hapiDbUser
datasource.password=hapiDbPass
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
  1. Save and mvn install....
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.21.0:verify (default) on project hapi-fhir-jpaserver-starter: There are test failures.

  2. Retrieve log from target/classes/failsafe-reports. Here's the critical error message in the log file that I'm seeing (happy to provide the entire file contents if helpful):
    java.sql.SQLException: Cannot create PoolableConnectionFactory (Cannot load connection class because of underlying exception: com.mysql.cj.core.exceptions.WrongArgumentException: Malformed database URL, failed to parse the main URL sections.)

I've reviewed the database URL ad nauseam and have been unable to identify any apparent issues. I've also attempted to connect to an RDS MySQL instance to no avail. I'm able to connect to the DB instance without issue using both the CLI and a SQL client. Additionally, I had a developer colleague attempt to connect this to MySQL following the README instructions as a sanity check and encountered the same error.

@jamesagnew
Copy link
Contributor

This StackOverflow post seems to suggest that there may be unwanted characters in the URL: https://stackoverflow.com/questions/50311481/malformed-database-url-failed-to-parse-the-main-url-sections

It might be worth attaching a debugger and looking at the string that's being passed to the JDBC driver if nothing obvious is there.

@justin-ad
Copy link
Author

justin-ad commented Apr 2, 2019

Thanks for taking a look at this @jamesagnew. I found the issue - the static initializers in the ExampleServerDstu3IT/ExampleServerDstu2IT/ExampleServerR4IT test files are setting the DATASOURCE_URL to the hard coded jdbc:derby:memory:dbr3;create=true, but the datasource.driver value found in the hapi.properties file now contains datasource.driver=com.mysql.cj.jdbc.Driver following my attempts to connect to MySQL. This causes the "Malformed database URL" error shown in my original comment due to the fact that the test projects are trying to use the jdbc:derby:memory:dbr3;create=true URL with the MySQL driver.

I tried setting the DATASOURCE_DRIVER in the test files initializers to the Derby class as shown below, but now mvn install gets hung up on running the tests (no errors, just hangs at [INFO] Running ca.uhn.fhir.jpa.starter.ExampleServerR4IT):

HapiProperties.setProperty(HapiProperties.DATASOURCE_DRIVER, "org.apache.derby.jdbc.EmbeddedDriver");

@jamesagnew
Copy link
Contributor

Ahhh of course. That makes sense.

This is a bit of a quandry- The integration tests for this project are all there to make sure that the demo project is in a good state, but in all honesty I wouldn't expect people to keep them if they are customizing the project to their own needs and environment (as you are doing).

The quick workaround for you is probably to just delete the integration tests on your own fork of this project.

The better solution here is probably to make them not run automatically without a build flag, or maybe to just update the README to reflect that you need to delete them? I'm not sure...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants