Elastic Search with Java for Standalone Application - java

I'm getting the below error :
StackTrace:
Exception in thread "main" java.lang.NoSuchMethodError: io.netty.buffer.CompositeByteBuf.addComponents(ZLjava/lang/Iterable;)Lio/netty/buffer/CompositeByteBuf;
at org.elasticsearch.transport.netty4.Netty4Utils.toByteBuf(Netty4Utils.java:117)
at org.elasticsearch.transport.netty4.Netty4Transport.sendMessage(Netty4Transport.java:395)
at org.elasticsearch.transport.netty4.Netty4Transport.sendMessage(Netty4Transport.java:94)
at org.elasticsearch.transport.TcpTransport.internalSendMessage(TcpTransport.java:1125)
at org.elasticsearch.transport.TcpTransport.sendRequestToChannel(TcpTransport.java:1107)
at org.elasticsearch.transport.TcpTransport.executeHandshake(TcpTransport.java:1622)
at org.elasticsearch.transport.TcpTransport.openConnection(TcpTransport.java:556)
at org.elasticsearch.transport.TcpTransport.openConnection(TcpTransport.java:117)
at org.elasticsearch.transport.TransportService.openConnection(TransportService.java:334)
at org.elasticsearch.client.transport.TransportClientNodesService$SimpleNodeSampler.doSample(TransportClientNodesService.java:408)
at org.elasticsearch.client.transport.TransportClientNodesService$NodeSampler.sample(TransportClientNodesService.java:358)
at org.elasticsearch.client.transport.TransportClientNodesService.addTransportAddresses(TransportClientNodesService.java:199)
at org.elasticsearch.client.transport.TransportClient.addTransportAddress(TransportClient.java:322)
I am using ES: 5.4.2 and Lucene: 6.5.1 and netty-all 4.0.9, netty buffer 4.1.11 and netty-common 4.1.11 jars
my java code is as below :
Settings settings =Settings.builder().put("cluster.name", "my-application").build();
TransportClient client = new PreBuiltTransportClient(settings);
TransportAddress address = new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300);
client.addTransportAddress(address);

The problem is being caused a Netty version conflict as far as I feel because the code is error-free.
This problem is caused by concurrent versions of Netty being used by different dependencies in your project.
Basically, ES 5 Transport API required Netty 4. And Dependency X, still use Netty 3. This can cause this problem.
Try in order:
Add Netty 4 as a dependency in your project
Create an independent project for the use of ES 5 Transport Client

There was no issue with netty3 jar ,there were some other jar issue ,it is resolved now.Have included the below jars as depicted in screenshot

Related

Gremlin-Driver update causes NoSuchMethodError

I have a Java Spring Boot application that connects to an Amazon Neptune graph database running on engine version 1.1.1.0.
After upgrading the gremlin-driver and TinkerPop dependencies to 3.5.2 from 3.4.6 (working on this version), the application can no longer make a connection to the graph database on AWS and it throws this exception
io.netty.channel.ChannelInitializer : Failed to initialize a channel. Closing: [id: 0xf213a752]ecs/XYZ
java.lang.NoSuchMethodError: io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker13.<init>(Ljava/net/URI;Lio/netty/handler/codec/http/websocketx/WebSocketVersion;Ljava/lang/String;ZLio/netty/handler/codec/http/HttpHeaders;IZZJ)V
I haven't made any changes with the builder besides the code-breaking change with one of the imports and the method name change. Did I miss something in this update?
This is the builder configuration that I am using from 3.4.6
Cluster.Builder builder = Cluster.build();
builder.addContactPoints(gremlinProperties.getContactPoints());
builder.port(gremlinProperties.getPort());
builder.nioPoolSize(gremlinProperties.getNioPoolSize());
builder.workerPoolSize(gremlinProperties.getWorkerPoolSize());
builder.minConnectionPoolSize(gremlinProperties.getMinConnectionPoolSize());
builder.maxConnectionPoolSize(gremlinProperties.getMaxConnectionPoolSize());
builder.minSimultaneousUsagePerConnection(gremlinProperties.getMinSimultaneousUsagePerConnection());
builder.maxSimultaneousUsagePerConnection(gremlinProperties.getMaxSimultaneousUsagePerConnection());
builder.maxInProcessPerConnection(gremlinProperties.getMaxInProcessPerConnection());
builder.minInProcessPerConnection(gremlinProperties.getMinInProcessPerConnection());
builder.maxWaitForConnection(gremlinProperties.getMaxWaitForConnection());
builder.maxWaitForClose(gremlinProperties.getMaxWaitForSessionClose());
builder.maxContentLength(gremlinProperties.getMaxContentLength());
builder.reconnectInterval(gremlinProperties.getReconnectInterval());
builder.resultIterationBatchSize(gremlinProperties.getResultIterationBatchSize());
builder.keepAliveInterval(gremlinProperties.getKeepAliveInterval());
builder.channelizer(Channelizer.WebSocketChannelizer.class);
builder.enableSsl(gremlinProperties.isEnableSsl());
return builder.create();
The values are extracted from a property file
Since the code that handles the gremlin connection and queries is located in a dependency jar project, the netty.version declared in the main project using that jars overrides the netty.io version that is used in the said jar project. I just have to declare a netty.version property in the main project pom so that it matches the netty version used in the dependency.

gRPC Java cannot find a NameResolver when using in OSGi bundle

I am trying to use JAVA gRPC in an OSGi bundle. I am using maven and using org.apache.servicemix.bundles.grpc-1.30.2_1 which is locally built from the release tag for 1.30.2_1.
The OSGi bundle starts up fine without any issue but at runtime when a ManageChannel is created I get a java.lang.IllegalArgumentException: cannot find a NameResolver for localhost:4435 exception.
The relevant part of the stacktrace
java.lang.IllegalArgumentException: cannot find a NameResolver for localhost:4435
at io.grpc.internal.ManagedChannelImpl.getNameResolver(ManagedChannelImpl.java:724) ~[org.apache.servicemix.bundles.grpc-1.30.2_1.jar:?]
at io.grpc.internal.ManagedChannelImpl.<init>(ManagedChannelImpl.java:606) ~[org.apache.servicemix.bundles.grpc-1.30.2_1.jar:?]
at io.grpc.internal.AbstractManagedChannelImplBuilder.build(AbstractManagedChannelImplBuilder.java:518) ~[org.apache.servicemix.bundles.grpc-1.30.2_1.jar:?]
When I debug the gRPC code at runtime I can see that there is zero NameResolvers added. I think that this can be a classloading issue.
This is part of the config from the Apache Felix plugin,
<Import-Package>
...,
org.apache.servicemix.bundles.grpc.*; version="1.30.2_1",
io.grpc*;
</Import-Package>
<Embed-Dependency>org.apache.servicemix.bundles.grpc;scope=compile</Embed-Dependency>
Channel building code (This is using io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder)
ManagedChannel channel = NettyChannelBuilder.forAddress("localhost", 4435)
.usePlaintext()
.build();
I only need to get the gRPC client working in the OSGi bundle.
Any help on this is much appreciated.
Adding the relevant gRPC providers in the META-INF/services worked.
Got it figured out by referencing this, which also uses gRPC inside a OSGi bundle
https://github.com/wso2/micro-integrator/tree/v1.2.0-m4/components/mediation/inbound-endpoints/org.wso2.micro.integrator.inbound.endpoint

How to use org.apache.httpcomponents inside a spark job on Hadoop/Spark?

I am trying to run a spark job on a Hadoop cluster that also makes an http request to another server. I am using org.apache.httpcomponents to make this request, which works fine locally on my machine. However this fails the moment I submit the job to the cluster (managed by Cloudera) with the following error:
User class threw exception: java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.(SSLConnectionSocketFactory.java:151)
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:977)
at org.apache.http.impl.client.HttpClients.createDefault(HttpClients.java:56)
From all the reading I have done, this error is caused by multiple versions of Apache Http client jar. It appears that Hadoop/Spark engine has it's own dependency to Apache Http client and that is a different version than the one I am using. Because my jar is run as part of the hadoop/spark engine it ends up including both my version of http as well as the one Hadoop requires.
If I add 'compileOnly' for org.apache.httpcomponents in my build.gradle and submit, I get this error instead:
User class threw exception: java.lang.NoClassDefFoundError: org/apache/http/impl/client/HttpClients
Is there a way for me to configure this in gradle so that when I build my jar, it will use the already existing version on Hadoop? ie. A way to declare a temporary dependency (when running locally download and use latest version, but when building UberJar drop the dependency)?
UPDATE
I decided to try swapping to a different http library (okhttp3) to see if that would resolve the issue. However I get a very similar exception when trying to run through the cluster here too:
User class threw exception: java.lang.NoSuchFieldError: Companion
at okhttp3.internal.Util.(Util.kt:70)
at okhttp3.OkHttpClient.(OkHttpClient.kt:959)
Looks like Cloudera also supplies a version of okhttp with it's spark2 client which is unfortunate.

WebSphere7 : java.lang.NoSuchMethodError: javax/persistence/spi/PersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode;

Hello everyone long story short,i'm using hibernate in my project,i try to deploy my project on WebSphere but it's giving me the error you see in the question title
,as you see in my jars there is no trace of a lower version of jpa 2.0
jars included in my project
but i know that all servers have a version of jpa,and websphere 7 is using 1.0 that i found among it's jars,here is a picture of it,
WebSphere 7 jars
if anyone please knows how to resolve this problem or found this problem before i will be so thankful,thank you in advance, i will leave the full stack trace for more infos :
Caused by: java.lang.NoSuchMethodError: javax/persistence/spi/PersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode;
at org.hibernate.ejb.util.LogHelper.logPersistenceUnitInfo(LogHelper.java:39)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:516)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:288)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1547)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1485)
... 61 more
I had a similar problem deploying my application with jpa 2.1 in Websphere 7.
If is the same problem, you have to tell Websphere to use Hibernate persistance provider instead of Default Persistance provide.
I wrote a guide with the solution that worked for me in this answer:
https://stackoverflow.com/a/38505479/6503002
EDIT: (Explain step 1 and 2 of the guide)
Step 1: To create a folder you have to access to server machine (through ssh) and create it in the file system (e.g. /usr/sharedHibernate assuming your server runs on linux). Then copy hibernate libraries in the folder you created (from your local machine to the server, with Filezilla or WinScp or Putty).
Step 2: In Websphere console on the left you have Environment section that contains Shared Libraries subsection:
Here create a new shared library, give it the name you want and in classpath textarea insert the path of the folder you created before (e.g. /usr/sharedHibernate)

Axis2 WS consumer in WebMethods8.2

I've got into a scenario where I have to get an Axis2 based ws consumer working within WebMethods as a java service. I've implemented the ws consumer first in netbeans just to see if it works and thus i found that the minimal amount of jars I'll require are the following:
[ xmlschema-1.4.7.jar, apache-mime4j-core-0.7.2.jar,
axiom-api-1.2.13.jar, axiom-impl-1.2.13.jar, axis2-adb-1.6.2.jar,
axis2-kernel-1.6.2.jar, axis2-transport-http-1.6.2.jar,
axis2-transport-local-1.6.2.jar, commons-codec-1.3.jar,
commons-httpclient-3.1.jar, commons-logging-1.1.1.jar,
httpcore-4.0.jar, mail-1.4.jar, neethi-3.0.2.jar, wsdl4j-1.6.2.jar ]
I've uploaded these jar files under the IS/packages/{package_name}/code/jars folder. Whenever I try to execute the java service that would send the request and process the response I get the following exception:
java.lang.reflect.InvocationTargetException:
org.apache.axiom.om.OMFactory.getMetaFactory()Lorg/apache/axiom/om/OMMetaFactory;
From the IS error log file I found that the actual error message is as follows:
org.apache.axiom.om.OMFactory.getMetaFactory()Lorg/apache/axiom/om/OMMetaFactory;
Caused by: java.lang.reflect.InvocationTargetException: null Caused
by:
java.lang.NoSuchMethodError:org.apache.axiom.om.OMFactory.getMetaFactory()Lorg/apache/axiom/om/OMMetaFactory;
The platform is WebMethods 8.2 under Linux environment. The JDK version is 1.6.0_32 and the application server under WebMethods is Jetty.
Actually the solve of this problem was a bit more tricky. First of all I manually had to configure the manifest file of the package on the IS server to use the jars provided in the package abnd thus it wouldn't get in conflict with the Axis used by the IS itself. On the other hand I had to manually add the ClassLoader because WebMethods can't use META-INF based information from jar files as it seems. To solve this problem simply use:
System.setProperty("org.apache.axiom.om.OMMetaFactory", "org.apache.axiom.om.impl.llom.factory.OMLinkedListMetaFactory");
That solves all the problems.

Categories

Resources