Elastic Search and webmethods Integration


(Ravi Kumar) #1

Hi All,

I am trying to integrate elastic search with webmethods. In order to achieve that, I have created a maven java project and downloaded all the dependent jars. After that, I created the a sample class to index a new document. The code of the class is as follows:

package com.fiserv.icc;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

public class MainApp {

public static void main(String[] args) {
	try {
		TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
		        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("10.253.153.81"), 9300));
		
		if(client != null){
			String json = "{" +
			        "\"user\":\"kimchy124\"," +
			        "\"postDate\":\"2013-01-30\"," +
			        "\"message\":\"trying out Elasticsearch\"" +
			    "}";

			IndexResponse response = client.prepareIndex("twitter", "tweet")
			        .setSource(json)
			        .get();
		}else{
			System.out.println("Not success");
		}
		
		client.close();
	} catch (UnknownHostException e) {			
		e.printStackTrace();
	}
}

}
Then I packaged all the dependent jars and the code into a JAR and imported it in webmethods. Inside webmethod's Java service, i am calling the following method:

MainApp.main(null);

But i am getting the following exception:

Could not initialize class org.elasticsearch.common.settings.IndexScopedSettings
Caused by: java.lang.reflect.InvocationTargetException: null
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.common.settings.IndexScopedSettings java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.common.settings.IndexScopedSettings
at org.elasticsearch.common.settings.SettingsModule.(SettingsModule.java:68)
at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:133)
at org.elasticsearch.client.transport.TransportClient.(TransportClient.java:247)
at org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:92)
at org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:81)
at org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:71)
at com.fiserv.icc.MainApp.main(MainApp.java:16)
at AthenaLogsElasticSearch.v1_0.testConnectivity(v1_0.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)

I tried searching on the internet for resolution but was unable to find one. Please let me know if some one has faced this issue and how we can resolve it.


(David Pilato) #2

What does your pom looks like?


(Ravi Kumar) #3

PFB the POM which i have used:


4.0.0

<groupId>com.fiserv.icc</groupId>
<artifactId>myElasticSearch</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>myElasticSearch</name>
<url>http://maven.apache.org</url>

<properties>
	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
	<dependency>
		<groupId>junit</groupId>
		<artifactId>junit</artifactId>
		<version>3.8.1</version>
		<scope>test</scope>
	</dependency>
	<dependency>
		<groupId>org.elasticsearch.client</groupId>
		<artifactId>transport</artifactId>
		<version>5.1.1</version>
	</dependency>
</dependencies>

(David Pilato) #4

Please format your code using </> icon as explained in this guide. It will make your post more readable.

Or use markdown style like:

```
CODE
```

IndexScopedSettings is part of the elasticsearch core jar. Not sure why you are not seeing it.

If you are really using Maven, you should not see such an issue. May be you used Maven "just to download" jars but then copied manually jars in your application classpath?


(Ravi Kumar) #5

Thanks dadoonet for the formatting tip.

I did not copied the jars manually but used Eclipse to create the runnable jar along with all the dependent jars packed into it.

When I am using this jar in a separate java project, i am able to index the document. But when I am trying to use it with webmethods java service, it is giving issue.

Kindly let me know if I could try something.


(David Pilato) #6

So you are probably missing some jars in your final package.

Either use something like Maven, Gradle to build your end package or fix manually the missing jars.

Run mvn dependency:tree and you'll get the list of needed jars.


(Ravi Kumar) #7

I checked and all the jars are present in the final package. I even looked into the final jar and the IndexedScopedSettings class was present.

The class path is also having the final packaged jar loaded.

Please let me know, if I could try some other approach.


(David Pilato) #8

Can you ls -l the content of your distribution?
Are you sure you are adding all those jars to the classpath when you start your app?

Disclaimer: I don't know Webmethods.


(system) #9

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