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>
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
Can not resolve configuration property '...
I have no problem accessing my properties through the #Value annotation or through an autowired Evironment. But all of my own defined properties get this warning in IDEA. What should I be doing to get IDEA to recognize these and not bother me?
In order for IntelliJ IDEA to know your Spring Boot properties, you can define Spring Boot configuration metadata in your project.
Option 1:
If you can use a #ConfigurationProperties-annotated class for your properties, you can add the Spring Boot configuration annotation processor to your classpath and IntelliJ IDEA will generate the configuration metadata for you in target or out:
Maven:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
Gradle:
implementation 'org.springframework.boot:spring-boot-configuration-processor'
Option 2:
Create the configuration metadata file yourself src/main/resources/META-INF/spring-configuration-metadata.json:
Content:
{
"properties": [
{
"name": "myapp.someprop",
"type": "java.lang.String"
},
{
"name": "myapp.someintprop",
"type": "java.lang.Integer"
}
]
}
Options 1 and 2:
In the IntelliJ IDEA tool window of your build system (Maven/Gradle), click the "Refresh" button.
Select Build > Rebuild Project from the menu.
If the warning still appears, you can try to restart the IDE. Select File > Invalidate Caches / Restart and click on Invalidate and Restart.
Please use the following for Gradle Kotlin Script for Kotlin project:
plugins {
kotlin("jvm")
kotlin("kapt")
}
/* ... */
dependencies {
val configurationProcessor ="org.springframework.boot:spring-boot-configuration-processor:${BuildConstants.springBootVersion}"
kapt(configurationProcessor) // for jar
kaptTest(configurationProcessor) // for jar
annotationProcessor(configurationProcessor) // for IntelliJ Idea
}
/* ... */
kapt {
annotationProcessor("org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor")
}
/* ... */
tasks {
withType<KotlinCompile> {
dependsOn(processResources)
}
}
Kotlin Kapt is needed to work with metadata and memory.
From official Spring documentation, Spring Boot Configuration Processor generates special json file with properties metadata.
Therefore, to distribute jar with property syntax highlight you need:
Ask Gradle to generate this file
Update task sequence to generate file before jar packaging by using dependsOn (not sure, that my code above is the most effective solution, however problem is solved)
However IntelliJ Idea works with annotationProcessor Gradle configuration (unfortunately, I don't have exact answer, why it requires exact it). Therefore you need add the same processor into the annotationProcessor configuration as well.
I had the same problem plus not showing auto completion found out that it works with IntelliJ Ultimate edition and not community version. link
couple of useful steps to take would be:
adding Maven dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
refresh Maven to download dependencies.
coping exact name of property from target/classes/META-INF/spring-configuration-metadata.js to prevent errors.
making sure that your config class is annotated with #ConfigurationProperties("name-here") and that you have enabled it by #EnableConfigurationProperties(NameOfTheConfigClass.class)
A Gradle-based workaround is this:
afterEvaluate {
val kaptKotlinTasks = tasks.named("kaptKotlin") {
doLast {
val kaptKotlin = this
tasks.named<ProcessResources>("processResources") {
from(kaptKotlin.outputs) {
include("META-INF/spring-configuration-metadata.json")
}
}
}
}
tasks.named("processResources") {
this.dependsOn(kaptKotlinTasks)
}
}
After running a build (or just the processResources task) from the Intellij Gradle panel, the warnings about the properties should disappear.
Not ideal, but IntelliJ not supporting kapt is not ideal either :-/
As an additional requirement for the answers above. After Spring-boot 2.2 you can use final keyword on the attributes together with the annotation #ConstructorBinding in order to see IntelliJ auto-complete the property name on the application.properties file. IntelliJ also recognizes if you add a java docs on the attribute.
#ConfigurationProperties(prefix = "my-config")
#ConstructorBinding
public class ConfigImportService {
/**
* the name of the bucket
* (IntelliJ shows this comment on the application.properties file)
*/
private final String bucketName;
private final String databaseName;
#Autowired
public ConfigImportService(
#Value("${bucket.name}") String bucketName,
#Value("${db.name}") String databaseName
) {
this.bucketName = bucketName;
this.databaseName = databaseName;
}
}
And still necessary the dependency, of course.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
Starting a small SpringBoot application by running the application (directly), the REST service localhost:8080/xyz/a gives a correct JSON result.
Via IntelliJ I configured a Tomcat server. I added this WAR with a context root of '/contextroot'. So I expected the URL REST to be localhost:8080/contextroot/xyz/a. This keeps on getting 404 errors.
Can you help me getting the right configuration or URL?
Is there a way to see which URL's are mapped from the controller to the URL's? Or: how can I solve these mapping issues more easily (from Tomcat)?
In the Maven Pom.xml I have:
<groupId>nl.xyz</groupId>
<artifactId>contextroot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>contextroot</name>
<packaging>war</packaging>
The within is also contextroot.
#Jonhib - thank you for helping.
The problem was the way I deployed a SpringBoot (jar) application as a WAR.
Take these 3 steps to change a SpringBoot standard application into a deployable (old fashioned) WAR. This is needed because I deploy it together with a Angular4 application.
Step 1 - Change the standard SpringBoot application:
#SpringBootApplication
public class Application extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application .class);
}
public static void main(String[] args) {
SpringApplication.run(Application .class, args);
}
}
Change the target of the building process from 'jar' into a 'war'.
<packaging>war</packaging>
Add a new dependency into the pom.xml maven file:
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
...
</dependencies>
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'
I have a multi module maven-spring project. Following is the structure-
ParentService
---ChildService-service
---ChildService-core
---ChildService-web
---ChildService-wsClient
---ChildService-mongo
I have created a new module called ChildService-wsService where I will write methods and expose as Axis2 SOAP web service. I have been able to write independent methods in classes of this module project and expose as service but I want to call methods of ChildService-service module.
When I try to call methods of ChildService-service module it gives me errors like NoClassDefFoundError.
Following is sample code--
public class HelloWorld {
#Autowired
private ITestService iTestService;
#Autowired
ICommonService commonService;
public String getVal(String s){
return s+"...testing...";
}
public String getValFfmService(){
iTestService=new TestServiceImpl();
return iTestService.test();
}
I am getting error as following--
Error: java.lang.NoClassDefFoundError: com/service/test/business/ITestService at java.lang.Class.forName0
If I include following line in class then also I am getting classnotfound error.
extends SpringBeanAutowiringSupport
You need to include your other projects that you need as dependencies, for instance, in your pom.xml:
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ChildService-service</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
...
</dependencies>
Then you need to install these dependencies in your local repository (mvn clean install will do it), or, in Eclipse, you need to activate Workspace resolution (right click on your module, Maven > Enable Workspace Resolution).