Skip to content

Commit

Permalink
fixed error message, encoded username
Browse files Browse the repository at this point in the history
  • Loading branch information
KushnirykOleh committed Mar 31, 2023
1 parent 1661da8 commit cad2d1d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,8 @@ private String injectCredentials(final String url, final Properties driverProper

if (nonNull(driverProperties)) {

final Optional<String> user = Optional.ofNullable(StringUtil.trimToNull(driverProperties.getProperty("user")));
final Optional<String> password = Optional.ofNullable(StringUtil.trimToNull(driverProperties.getProperty("password")))
.map(s -> {
try {
return URLEncoder.encode(s, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
});
final Optional<String> user = Optional.ofNullable(StringUtil.trimToNull(driverProperties.getProperty("user"))).map(MongoConnection::encode);
final Optional<String> password = Optional.ofNullable(StringUtil.trimToNull(driverProperties.getProperty("password"))).map(MongoConnection::encode);

if (user.isPresent()) {
// injects credentials
Expand All @@ -145,6 +138,13 @@ private String injectCredentials(final String url, final Properties driverProper
return url;
}

private static String encode(String s) {
try {
return URLEncoder.encode(s, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}

@Override
public void close() throws DatabaseException {
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/liquibase/nosql/executor/NoSqlExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,13 @@ public void execute(final SqlStatement sql, final List<SqlVisitor> sqlVisitors)
} else if (sql instanceof UpdateStatement) {
execute((UpdateStatement) sql);
} else {
//TODO DAT-14066 fix error message
throw new DatabaseException("liquibase-mongodb extension cannot execute " + sql.getClass().getSimpleName() +
". Please check your classpath, changeType name, other changeSet attributes like 'runWith' " +
"to make sure you have appropriate handler for this change.");
throw new DatabaseException("liquibase-mongodb extension cannot execute changeset \n" +
"Unknown type: " + sql.getClass().getName() +
"\nPlease check the following common causes:\n" +
"- Verify change set definitions for common error such as: changeType name, changeSet attributes spelling " +
"(such as runWith, context, etc.), and punctuation.\n" +
"- Verify that changesets have all the required changeset attributes and do not have invalid attributes for the designated change type.\n" +
"- Double-check to make sure your basic setup includes all needed extensions in your Java classpath");
}
}

Expand Down

0 comments on commit cad2d1d

Please sign in to comment.