opensearch-project / opensearch-java

Java Client for OpenSearch
Apache License 2.0
106 stars 169 forks source link

[BUG] ApacheHttpClient5Transport requires apache commons logging dependency (but not provided if RHEC excluded) #1002

Closed rursprung closed 1 month ago

rursprung commented 1 month ago

What is the bug?

if you depend on opensearch-java but exclude the opensearch-rest-client (RHEC) then it fails in the runtime with the following error:

java.lang.NoClassDefFoundError: Could not initialize class org.opensearch.client.transport.httpclient5.ApacheHttpClient5Transport

    at org.opensearch.client.transport.httpclient5.ApacheHttpClient5TransportBuilder.build(ApacheHttpClient5TransportBuilder.java:279)
    at liquibase.ext.opensearch.database.OpenSearchConnection.connect(OpenSearchConnection.java:146)
    at liquibase.ext.opensearch.database.OpenSearchConnection.open(OpenSearchConnection.java:64)
    at liquibase.database.ConnectionServiceFactory.create(ConnectionServiceFactory.java:32)
    at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:238)
    at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:188)
    at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:153)
    at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:142)
    at liquibase.ext.opensearch.AbstractOpenSearchLiquibaseIT.beforeEach(AbstractOpenSearchLiquibaseIT.java:42)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory [in thread "main"]
    at org.opensearch.client.transport.httpclient5.ApacheHttpClient5Transport.<clinit>(ApacheHttpClient5Transport.java:98)
    ... 12 more

How can one reproduce the bug?

in maven:

        <dependency>
            <groupId>org.opensearch.client</groupId>
            <artifactId>opensearch-java</artifactId>
            <version>2.10.3</version>
            <exclusions>
                <exclusion>
                    <groupId>org.opensearch.client</groupId>
                    <artifactId>opensearch-rest-client</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

as a workaround the following dependency can be added:

        <dependency>
            <!-- transitive dependency needed by ApacheHttpClient5Transport -->
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.3.2</version>
        </dependency>

What is the expected behavior?

the required dependencies are provided by opensearch-java, consumers do not need to know about such internals.

What is your host/environment?

tested with opensearch-java 2.10.3.

Do you have any screenshots?

n/a

Do you have any additional context?

@reta is already informed