I'm trying to use shield plugin with elasticsearch while creating a es client in spring. I have added the following dependency to my pom.xml
<dependency>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>shield</artifactId>
<version>2.4.0</version>
</dependency>
I'm creating the bean in the below fashion:
#Override
protected TransportClient createInstance() throws Exception
{
TransportClient client = null;
String userpass = this.username+":"+this.password;
client = TransportClient.builder()
.addPlugin(ShieldPlugin.class)
.settings(Settings.builder()
.put("shield.user", userpass)
.build()).build()
.addTransportAddress(toAddress());
return client;
}
But when the bean is created it gets the following error.
java.lang.ClassNotFoundException: org.elasticsearch.shield.ShieldPlugin
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167)
... 116 more
Any help on this is appreciated.
Thanks in advance.
I asked the Elastic.co support to fix this point.
It was not the good dependency on the maven repository.
Now the maven repository should work fine.
BR
Nicolas
Go to the official website to download jar, you can solve it
enter link description here
Related
I use dependency of jmeter 5.0 in my custom project pom .
<!-- https://mvnrepository.com/artifact/org.apache.jmeter/ApacheJMeter_core -->
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_core</artifactId>
<version>5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.jmeter/ApacheJMeter_java -->
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_java</artifactId>
<version>5.0</version>
</dependency>
After compiling I copy jar to lib/ext in jmeter5.0 source project pulling from github , and debug by runing NewDriver, then i found the function org.apache.jorphan.reflect.ClassFinder.ExtendsClassFilter#isChildOf at Class.forName(strClassName, false, contextClassLoader) throw exception java.lang.ClassNotFoundException: com.xxxx.xxxx, strClassName has printed my own classs, so it means my class has been scaned?
private final ClassLoader contextClassLoader
= Thread.currentThread().getContextClassLoader(); // Potentially expensive; do it once
private boolean isChildOf(
Class<?>[] parentClasses, String strClassName, ClassLoader contextClassLoader) {
try {
// Here is exception line
Class<?> targetClass = Class.forName(strClassName, false, contextClassLoader);
if (!targetClass.isInterface()
&& !Modifier.isAbstract(targetClass.getModifiers())) {
return Arrays.stream(parentClasses)
.anyMatch(parent -> parent.isAssignableFrom(targetClass));
}
} catch (UnsupportedClassVersionError | ClassNotFoundException
| NoClassDefFoundError | VerifyError e) {
log.debug(e.getLocalizedMessage(), e);
}
return false;
}
My code
public class JmeterSupportTest extends AbstractJavaSamplerClient {
xxxx;
}
Anyone can help!
It is ok now. Couse of plugin compile which did not add depend jars , and config pom add maven-assembly-plugin will solve
If there are any extra libraries which are being used in your Java Request sampler implementation - they should go to "lib" folder of your JMeter installation (see JMeter Classpath user manual entry for more details) or you can think of using i.e. Maven Shade plugin to create "uber" or "fat" .jar containing all the dependencies
According to JMeter Best Practices you should always be using the latest version of JMeter so consider upgrading to JMeter 5.4 (or whatever is the latest stable version available at JMeter Downloads page) on next available opportunity
In addition to point 2 what you're pulling from Github is master (unless you switch to the v5_0 tag so make sure that the source is matching JMeter dependencies, just in case sources for each respective version can be found at JMeter Archives page
I am integrating Outlook API and for making HTTP Calls I am using Retrofit version 2.3.0 and okHttp3 version 3.9.1.
However when I'm making an HTTP Call, for example :
// Create a logging interceptor to log request and responses
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel( HttpLoggingInterceptor.Level.BODY );
OkHttpClient client = new OkHttpClient.Builder().addInterceptor( interceptor ).build();
// Create and configure the Retrofit object
Retrofit retrofit = new Retrofit.Builder().baseUrl( authority ).client( client ).addConverterFactory( JacksonConverterFactory.create() ).build();
// Generate the token service
TokenService tokenService = retrofit.create( TokenService.class );
try
{
return tokenService.getAccessTokenFromAuthCode( tenantId, getAppId(), getAppPassword(), "authorization_code", authCode, getRedirectUrl() ).execute().body();
}
catch ( IOException e )
{
TokenResponse error = new TokenResponse();
error.setError( "IOException" );
error.setErrorDescription( e.getMessage() );
return error;
}
I am getting following exception :
org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: okio.BufferedSource.rangeEquals(JLokio/ByteString;)Z
Below is my partial pom.xml :
<!-- JACKSON DEPENDENCY FOR JSON PARSING -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.3</version>
</dependency>
<!-- RETROFIT DEPENDENCY FOR SENDING HTTP REQUESTS -->
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-jackson</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>3.9.1</version>
</dependency>
Can some one help me figure out, what's wrong with this?
BufferedSource
is in okio project version 1.13.0.
Both dependencies com.squareup.retrofit2 and com.squareup.okhttp3 use this version. Also in this version this method is included. Version-wise it looks okay.
Local Environemnt
Now make sure to clear your maven repository. Maybe an old version got hung up somewhere. After that do a maven update project and a clean install.
Tomcat Environment
If this is happening in your tomcat make also sure to delete the work/Catalina/localhost/ folder, because sometimes things could be cached there.
I experienced a similar issue while executing a MapReduce job via YARN. In my case, an existing downgraded okio version was present which was overriding the external libraries of the application. I changed it to okio 1.13.0 and the issue was fixed.
It was this location for me:
/home/vagrant/bigdata/hadoop/share/hadoop/hdfs/lib
This could be because a conflict with an existing Okio version, provided by a dependency.
See Spark and Influx: OKIO conflict, there is a conflict with Apache Spark.
Use Maven / Gradle dep. tree export to see all transitive dep, or (in my case) :
jar tf /usr/hdp/current/spark-client/lib/spark-assembly-1.6.3.2.6.3.0-235-hadoop2.7.3.2.6.3.0-235.jar | grep okio
This will list:
okio/BufferedSource.class
Then extract the okhttp pom.xml:
jar xf /usr/hdp/current/spark-client/lib/spark-assembly-1.6.3.2.6.3.0-235-hadoop2.7.3.2.6.3.0-235.jar META-INF/maven/com.squareup.okhttp/okhttp/pom.xml
cat META-INF/maven/com.squareup.okhttp/okhttp/pom.xml | grep version
Experienced similar issue executing Spark job on EMR via YARN, as Okio/Okhttp dependencies for an external library used in the application were being overridden by those distributed on a system class path for Spark.
Resolution: Shade/relocate the Okio dependency in the external library's build.
I have multiple POMs that inherit a dependency via their parent. The dependency is not to a maven plugin, but another project that I have created:
<dependency>
<groupId>com.my.name.group</groupId>
<artifactId>id-of-my-artifact</artifactId>
<version>2.3.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
Now I want to remove this from the parent POM file and instead have the children POMs use a custom maven plugin for the same functionality. In that custom maven plugin (which I will create), I want to call/add above dependency. I have tried the following code in a Mojo of the new maven-plugin, but it is not adding the dependency (and gives compilation error):
private MavenProject project;
public void execute() throws MojoExecutionException, MojoFailureException {
try {
// adding a dependency
Dependency dep = new Dependency();
dep.setArtifactId("id-of-my-artifact");
dep.setGroupId("com.my.name.group");
dep.setScope("compile");
dep.setVersion("2.3.0-SNAPSHOT");
List<Dependency> lst = new ArrayList<Dependency>();
lst.add(dep);
project.setDependencies(lst);
} catch (Exception ex) {
getLog().info(String.format("Exception %s: ", ex));
throw new MojoExecutionException("Exception has occurred" + ex);
}
}
Is it possible to do this? If yes, how?
I looked at this related question and the link provided in that. From the external link, it seems that it is not possible. But in that question, OP seems to have figured it out and provided a short answer, but I cannot understand the answer. Could someone please help me out? I am new to Maven.
We have an existing JavaEE web application. We need to connect to a document repository via webdav. I am trying to use sardine but the couldn't find clear setup instructions. Is the Maven build mandatory? Or, is it possible to simply include sardine.jar in our application and use the below code?
Sardine sardine = SardineFactory.begin("username", "password");
List<DavResource> resources = sardine.list("http://myhost.com/modeshape-webdav/sample/default");
for (DavResource res : resources)
{
System.out.println(res);
}
If you use Maven, you can add this dependency in your pom.xml to use Sardine :
<dependency>
<groupId>com.github.lookfirst</groupId>
<artifactId>sardine</artifactId>
<version>5.5</version>
</dependency>
Anyone having any examples or thoughts using gRPC together with Spring Boot?
If it's still relevant for you, I've created gRPC spring-boot-starter here.
grpc-spring-boot-starter auto-configures and runs the embedded gRPC server with #GRpcService-enabled beans.
The simplest example :
#GRpcService(grpcServiceOuterClass = GreeterGrpc.class)
public static class GreeterService implements GreeterGrpc.Greeter {
#Override
public void sayHello(GreeterOuterClass.HelloRequest request, StreamObserver<GreeterOuterClass.HelloReply> responseObserver) {
// omitted
}
}
There is also an example of how to integrate the starter with Eureka in project's README file.
https://github.com/yidongnan/grpc-spring-boot-starter
In server
#GrpcService(GreeterGrpc.class)
public class GrpcServerService extends GreeterGrpc.GreeterImplBase {
#Override
public void sayHello(HelloRequest req, StreamObserver<HelloReply> responseObserver) {
HelloReply reply = HelloReply.newBuilder().setMessage("Hello =============> " + req.getName()).build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
}
}
In client
#GrpcClient("gRPC server name")
private Channel serverChannel;
GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(serverChannel);
HelloReply response = stub.sayHello(HelloRequest.newBuilder().setName(name).build());
If you need a gRPC client library, i.e. consume stubs, check out my library https://github.com/sfcodes/grpc-client-spring-boot
This library will automatically scan your classpath, find all gRPC stub classes, instantiate them, and register them as beans with the ApplicationContext; allowing you to easily #Autowire and inject them just like you would any other Spring bean. For example:
#RestController
public class GreeterController {
#Autowired // <===== gRPC stub is autowired!
private GreeterGrpc.GreeterBlockingStub greeterStub;
#RequestMapping(value = "/sayhello")
public String sayHello(#RequestParam String name) {
HelloRequest request = HelloRequest.newBuilder().setName(name).build();
HelloReply reply = greeterStub.sayHello(request);
return reply.getMessage();
}
}
For gRPC server library, I'd also recommend LogNet/grpc-spring-boot-starter.
Starting from https://spring.io/blog/2015/03/22/using-google-protocol-buffers-with-spring-mvc-based-rest-services, then
take a look at
SPR-13589 ProtobufHttpMessageConverter support for protobuf 3.0.0-beta4 and related SPR-13203
HttpMessageConverter based on Protostuff library
That is some support for proto3 is coming in Spring 5. As it is under development one is encouraged to vote and raise what is important for their project.
In here I use gRpc and eureka to communication. This project based on Spring-boot
https://github.com/WThamira/grpc-spring-boot
additionally you canuse register as consul also. full example in this repo
https://github.com/WThamira/gRpc-spring-boot-example
this maven dependency help to gRpc
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty</artifactId>
<version>1.0.1</version>
</dependency>
and need plugin show in below
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<!-- The version of protoc must match protobuf-java. If you don't depend
on protobuf-java directly, you will be transitively depending on the protobuf-java
version that grpc depends on. -->
<protocArtifact>com.google.protobuf:protoc:3.0.2:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.0.1:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
In this Github Repo[1] you will find an example of using gRPC to insert and view the users into the couchbase db. Please refer the proto file[2] to find the rpc methods.
Normally gRPC clients like bloomRPC is used to access the service. Using envoy proxy it is possible to transcode and access the service using HTTP/1.1. In the readme file the steps of creating a config file and to run the envoy proxy using docker file is shown.
[1] https://github.com/Senthuran100/grpc-User
[2] https://github.com/Senthuran100/grpc-User/blob/master/src/main/proto/user.proto
Created a simple Springboot App with GRPC. This GitHub repo has both Server and Client examples. Repo has separate Maven module(grpc-interface) where we declare the Proto files and generate the Java source code then can be used as lib in both Server and client apps.
https://github.com/vali7394/grpc-springboot-repo
you can use this page.
dependency and build tags was provided.
'https://www.baeldung.com/grpc-introduction'