Elasticsearch automatically closes connection as soon as I run my Java Springboot program

*[WARN ][o.e.x.c.s.t.n.SecurityNetty4Transport] [DESKTOP-ADQ0I0S] received plaintext traffic on an encrypted channel, closing connection Netty4TcpChannel{localAddress=/127.0.0.1:9300, remoteAddress=/127.0.0.1:59255, profile=default*

I have asked this question in a descriptive manner on stackoverflow here : https://stackoverflow.com/questions/71971672/elasticsearch-stops-working-after-i-run-the-springboot-java-program-and-elastics .Im getting issues on transport layer I guess.
Please refer to my Stackoverflow question or let me know if I should post the question here too.

Your node is using SSL
Enable SSL in spring boot side

Getting the same error after enabling SSL in Springboot

After running the program I get this error


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.1.RELEASE)

2022-04-24 01:24:37.421  INFO 8036 --- [  restartedMain] pringBootElasticsearchExampleApplication : Starting SpringBootElasticsearchExampleApplication on DESKTOP-ADQ0I0S with PID 8036 (started by Hp in D:\STS Project\demo)
2022-04-24 01:24:37.428  INFO 8036 --- [  restartedMain] pringBootElasticsearchExampleApplication : No active profile set, falling back to default profiles: default
2022-04-24 01:24:37.550  INFO 8036 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-04-24 01:24:37.577  INFO 8036 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-04-24 01:24:38.697  INFO 8036 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2022-04-24 01:24:38.780  INFO 8036 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 75ms. Found 1 repository interfaces.
2022-04-24 01:24:39.864  INFO 8036 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8443 (https)
2022-04-24 01:24:39.892  INFO 8036 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-04-24 01:24:39.893  INFO 8036 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/9.0.13
2022-04-24 01:24:39.915  INFO 8036 --- [  restartedMain] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [D:\STS\sts-4.13.0.RELEASE\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.1.v20211116-1657\jre\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:/STS/sts-4.13.0.RELEASE//plugins/org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.1.v20211116-1657/jre/bin/server;D:/STS/sts-4.13.0.RELEASE//plugins/org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.1.v20211116-1657/jre/bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\nodejs\;C:\Program Files\Java\jdk1.8.0_202\bin;C:\Program Files\Git\cmd;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files\Azure Data Studio\bin;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Program Files\MySQL\MySQL Shell 8.0\bin\;C:\Users\Hp\AppData\Local\Microsoft\WindowsApps;;C:\Users\Hp\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Hp\AppData\Roaming\npm;C:\Program Files\Azure Data Studio\bin;C:\Program Files\Azure Data Studio\bin;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.1\bin;;D:\STS\sts-4.13.0.RELEASE;;.]
2022-04-24 01:24:40.082  INFO 8036 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-04-24 01:24:40.082  INFO 8036 --- [  restartedMain] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2500 ms
2022-04-24 01:24:40.451  INFO 8036 --- [  restartedMain] o.elasticsearch.plugins.PluginsService   : no modules loaded
2022-04-24 01:24:40.452  INFO 8036 --- [  restartedMain] o.elasticsearch.plugins.PluginsService   : loaded plugin [org.elasticsearch.index.reindex.ReindexPlugin]
2022-04-24 01:24:40.452  INFO 8036 --- [  restartedMain] o.elasticsearch.plugins.PluginsService   : loaded plugin [org.elasticsearch.join.ParentJoinPlugin]
2022-04-24 01:24:40.452  INFO 8036 --- [  restartedMain] o.elasticsearch.plugins.PluginsService   : loaded plugin [org.elasticsearch.percolator.PercolatorPlugin]
2022-04-24 01:24:40.453  INFO 8036 --- [  restartedMain] o.elasticsearch.plugins.PluginsService   : loaded plugin [org.elasticsearch.script.mustache.MustachePlugin]
2022-04-24 01:24:40.453  INFO 8036 --- [  restartedMain] o.elasticsearch.plugins.PluginsService   : loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2022-04-24 01:24:41.852  INFO 8036 --- [  restartedMain] o.s.d.e.c.TransportClientFactoryBean     : Adding transport node : 127.0.0.1:9300
2022-04-24 01:24:42.252  INFO 8036 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2022-04-24 01:24:42.280 ERROR 8036 --- [  restartedMain] .d.e.r.s.AbstractElasticsearchRepository : failed to load elasticsearch nodes : org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{Y2r-zQdGTsOzunZYoM4C4A}{localhost}{127.0.0.1:9300}]
2022-04-24 01:24:42.662  INFO 8036 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2022-04-24 01:24:43.903  INFO 8036 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8443 (https) with context path ''
2022-04-24 01:24:43.928  INFO 8036 --- [  restartedMain] pringBootElasticsearchExampleApplication : Started SpringBootElasticsearchExampleApplication in 7.372 seconds (JVM running for 8.427)

As soon as I run the program Elasticsearch closes connection by giving this error

[2022-04-24T01:27:52,345][WARN ][o.e.x.c.s.t.n.SecurityNetty4Transport] [DESKTOP-ADQ0I0S] received plaintext traffic on an encrypted channel, closing connection Netty4TcpChannel{localAddress=/127.0.0.1:9300, remoteAddress=/127.0.0.1:60477, profile=default}

modified application.properties and added the below code

#SSL Configuration
server.ssl.key-alias=selfsigned
server.ssl.key-store-type=PKCS12
server.ssl.key-store=classpath:mykeystore.jks
server.ssl.key-store-password=keypass
server.port=8443

created @configuration @Bean class

package Config;

import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MySecurityConfig {

	  @Bean
	    public ServletWebServerFactory servletContainer() {
	        // Enabling SSL traffic
	        TomcatServletWebServerFactory tomcatServletWebServerFactory = new TomcatServletWebServerFactory() {
	            @Override
	            protected void postProcessContext(Context context) {
	                SecurityConstraint securityConstraint = new SecurityConstraint();
	                securityConstraint.setUserConstraint("CONFIDENTIAL");
	                SecurityCollection securityCollection = new SecurityCollection();
	                securityCollection.addPattern("/*");
	                securityConstraint.addCollection(securityCollection);
	                context.addConstraint(securityConstraint);
	            }
	        };

	        // Adding HTTP to HTTPS redirect
	        tomcatServletWebServerFactory.addAdditionalTomcatConnectors(httpToHttpsRedirectConnector());

	        return tomcatServletWebServerFactory;
	    }

	    /*
	     If any request comes with port 8080 needs to be redirected to HTTPS on 8443.
	     */
	    private Connector httpToHttpsRedirectConnector() {
	        Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
	        connector.setScheme("http");
	        connector.setPort(8080);
	        connector.setSecure(false);
	        connector.setRedirectPort(8443);
	        return connector;
	    }
}

Idk what im doing wrong, it's been 4 days now im facing this issue, springboot program is not connection with Elasticsearch :frowning:

Nothing changed after enabling SSL in springboot

Did you set port 9300.... Can you try 9200

spring.data.elasticsearch.cluster-nodes=localhost:9200

You can not connect to the 9300 transport client port in Elasticsearch 7.x+

Looks like you are running Elasticsearch 8.1.3 ... Definitely can not connect to the transport client.

https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.clients.transport

What version of spring data Elasticsearch

https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/

Your going to need to use the high level rest client

https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.clients.rest

Which I think is already deprecated see

1 Like

Yes, Im using Elasticsearch 8.1.3. Thanks, I will check it out and let you know.

Thanks, I tried using the Java API Client but got some issues and there aren't enough toutorials on internet related to Java API client, I'm new to Springboot and Elasticsearch, so now I have installed Elasticsearch 7.12 and my springboot application is running fine but got "null pointer exception" after calling the rest method, it seems it is not able to connect to the Elasticsearch repository.
Thank you, you have answered my question.

And you have it pointing to port 9200 that is the rest endpoint

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.