use of com.marklogic.client.DatabaseClientFactory.SecurityContext in project components by Talend.
the class MarkLogicConnection method connect.
/**
* Creates new {@link DatabaseClient} connection or gets referenced one from container.
*
* @param container
* @return connection to MarkLogic database.
* @throws IOException thrown if referenced connection is not connected.
*/
public DatabaseClient connect(RuntimeContainer container) {
MarkLogicConnectionProperties properties = getMarkLogicConnectionProperties();
if (properties.getReferencedComponentId() != null && container != null) {
DatabaseClient client = (DatabaseClient) container.getComponentData(properties.getReferencedComponentId(), CONNECTION);
if (client != null) {
return client;
}
throw new MarkLogicException(new MarkLogicErrorCode(MESSAGES.getMessage("error.invalid.referenceConnection", properties.getReferencedComponentId())));
}
SecurityContext context = "BASIC".equals(properties.authentication.getValue()) ? new DatabaseClientFactory.BasicAuthContext(properties.username.getValue(), properties.password.getValue()) : new DatabaseClientFactory.DigestAuthContext(properties.username.getValue(), properties.password.getValue());
DatabaseClient client = DatabaseClientFactory.newClient(properties.host.getValue(), properties.port.getValue(), properties.database.getValue(), context);
testConnection(client);
LOGGER.info("Connected to MarkLogic server");
if (container != null) {
container.setComponentData(container.getCurrentComponentId(), CONNECTION, client);
LOGGER.info("Connection stored in container");
}
return client;
}
Aggregations