NoSuchMethodError in com.google.api.client library - java

I'm trying to use the Google Cloud Storage SDK for Java into my Spring application.
Using Maven I've added it to my dependencies:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>1.31.0</version>
</dependency>
Then I try to initialize the Storage client with:
client = StorageOptions.newBuilder()
.setCredentials(ServiceAccountCredentials.fromStream(new ClassPathResource("/my/path/to.json").getInputStream()))
.build()
.getService();
but an error occurs
java.lang.NoSuchMethodError: com.google.api.client.googleapis.services.json.AbstractGoogleJsonClient$Builder.setBatchPath
I've noticed that in my google-api-client-1.23.0.jar libray loaded as dependency no setBatchPath was present.
I've tried to find the issue browsing on web but without fortune.
I cannot understand which library (and version) I need to install in order to make it works.

Eventually I solved, there was a library duplication between my Web Application and Its Business Layer Jar component (I have a multi-module Project).
What I cannot understand is why there was a call to a non-existing method (AbstractGoogleJsonClient$Builder.setBatchPath) that was solved in this way.
In google-api-client-1.20.0.jar that method does not exists nor in google-api-client-1.23.0.jar

Try reading this, and then you may be able to work around the error.

Related

Spring Boot-Activiti Integration with Sybase Database

I created a spring-boot project to read and write data to Sybase database. The project was working as intended. However, whenever I added activiti dependencies, It says "couldn't deduct database type from database product name 'Adaptive Server Enterprise'". According to my understanding, there are some classes conflicting each other in activiti and spring even though I do not use anything regarding activiti( except the fact that I just opened a folder called processes in the resources directory).
The activiti dependencies I added are:
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-rest-api</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-actuator</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-jpa</artifactId>
<version>5.21.0</version>
</dependency>
To clarify my point in this, I wanted to use activiti just for workflow purposes and leave the rest of the ETL or database job to spring. If I change database from Sybase to Mysql, the project also works fine even with activiti dependencies. As far as I know activiti has no support for Sybase and apparently, it tries to interfere everything possible and overrides something that was already working at the first place. How can I overcome this problem?
you are trying to use the spring boot starter which automatically tries to configure a database using spring autoconfiguration. Can you clarify with which database do you want to use Activiti? If you want to use Sybase you will need to contribute back to the project with Sybase support. Alternatively, you can not use the starter and depend on the engine directly, this will push you to provide the engine configurations for your spring environment. You can also check the -starter project and adapt as needed.
HTH

Error while creating S3 Client in Java

I'm having a problem.
I have a Java project that works fine (written by someone else), I cloned it to my computer (from GitHub) and opened it in Eclipse. When I'm trying to run it, I keep getting an error when the script tries to create a s3 client.
This is the code (this.client = AmazonS3Client instance):
ClientConfiguration clientConfiguration = new ClientConfiguration();
ClientConfiguration.setMaxConnections(10);
clientConfiguration.setConnectionTimeout(120000);
clientConfiguration.setSocketTimeout(120000);
clientConfiguration.setMaxErrorRetry(5);
this.client = new AmazonS3Client(new InstanceProfileCredentialsProvider(), clientConfiguration);
This is the error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
at com.amazonaws.internal.config.InternalConfig.<clinit>(InternalConfig.java:43)
at com.amazonaws.internal.config.InternalConfig$Factory.<clinit>(InternalConfig.java:304)
at com.amazonaws.util.VersionInfoUtils.userAgent(VersionInfoUtils.java:142)
at com.amazonaws.util.VersionInfoUtils.initializeUserAgent(VersionInfoUtils.java:137)
at com.amazonaws.util.VersionInfoUtils.getUserAgent(VersionInfoUtils.java:100)
at com.amazonaws.ClientConfiguration.<clinit>(ClientConfiguration.java:64)
I tried also "this.client = AmazonS3ClientBuilder.defaultClient();" with a "Amazon3Client" instance, but it didn't work as well - same problem, error when trying to define ClientConfiguration...
I'm using aws-java-sdk-1.11.160.jar (tried before with 1.11.111 and didn't work, so I thought maybe upgrading the jar would help... it didn't)
I'm on this a couple of days now, and I can't seem to find the problem...
Any help would be great... Thank you!
You miss the jackson-databind jar in your classpath.
If you use maven, you can add the following dependency to solve this error:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version><your version></version>
</dependency>
This code is written to grab the AWS secret and access key from the EC2 instance profile. When you clone it locally you'll need to provide a different way to authenticate to the AWS API.
http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html
When constructing the client this code is using the option for a IAM instance profile
new InstanceProfileCredentialsProvider(),
Credentials provider implementation that loads credentials from the Amazon EC2 Instance Metadata Service.
http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/InstanceProfileCredentialsProvider.html

ServiceBusConfiguration.configureWithConnectionString can't work, error "The key 'SharedAccessKeyName' is not valid for this connection string"

I'm using newest Azure java sdk(version 0.6), but I found I have problems when I use service bus configuration "configureWithConnectionString" function.
Here is my code below,
//get config
string connectionString = "Endpoint=sb://testservicebusnamespace.servicebus.windows.net/;SharedAccessKeyName=MySharedAccessKey;SharedAccessKey=<this is secret not show>";
config = new Configuration();
ServiceBusConfiguration.configureWithConnectionString(null, config, connectionString);
//create service
service = ServiceBusService.create(config);
And I get connection String from my service bus namespace portal in Azure. But When I run this code, it throws an exception "The key 'SharedAccessKeyName' is not valid for this connection string".
I don't know what's the problem, because I get the connection from Azure portal, and I've checked its content(the SharedAccessKeyName, SharedAccessKey), they are right.
So could anyone help me? Is it my problem or this SDK needs update(because I've heard portal already uses SAS, but SDK still uses ACS to authenticate)?
Thanks very much.
It looks like Java Azure SDK(0.6.0) still uses ACS to authenticate. See this github issue comments:
the current SDK works with service bus namespace with ACS auth mode, but not new created servicebus namespace which use SAS token auth mode. we will investigate this issue
and
One workaround is to create the service bus namespace via PowerShell.
This seems to enable the ACS auth mode by default. Command is:
New-AzureSBNameSpace -Name MyNameSpace -Location "West Europe"
Take a note of the "DefaultKey" you get after running the command. You
need to use that with the ServiceBusConfiguration and I'm not sure if
that is available via the Azure management portal. Use "owner" as the
authenticationName parameter to the configureWithWrapAuthentication.
I'm adding this answer, because I thought I was doomed. But found a new library.
This dependency (which 0.5.0 was latest version when I wrote this post)......gives you the issue.
<dependency>
<groupId>com.microsoft.windowsazure</groupId>
<artifactId>microsoft-azure-api-servicebus</artifactId>
<version>0.5.0</version>
</dependency>
Microsoft slightly altered the groupid. Here is a dependency that seems much more update to date.
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-servicebus</artifactId>
<version>0.9.7</version>
</dependency>
Maven link here : https://search.maven.org/#artifactdetails%7Ccom.microsoft.azure%7Cazure-servicebus%7C0.9.7%7Cjar
So its an old question. But hopefully this points somebody in the right direction.

error to integrate restful web service with spring and gdata api

Short version: A restful spring web service crashes when I include a dependency: com.google.gdata: core: 1.47.1
Long Version:
I was trying to make a restfull web service that consume certain information from a spreadsheet in google drive
this is my sequence of steps:
preparing classes that made the connection and the data obtained from drive (not web, only backend classes, unit and integration tests included): all ok
prepare a restfull web service with spring, basically download a spring tutorial (http://spring.io/guides/tutorials/rest/3/) and execute: all ok
then remove tutorial's business classes and include my components, change controllers to invoke my components, plus add gdata dependence in file graddle.build, try execute: houston we have a problem
It's strange, when start app context, log print something like this:
 
C:\Users\Grubhart\Documents\proyectos\error_Rest_Gdata\complete\src\main\java\com\yummynoodlebar\config\WebAppInitializer.java:39: error: can not find symbol
     servletContext.setInitParameter ("defaultHtmlEscape", "true");
                   ^
     symbol: method setInitParameter (String, String)
     location: Variable of type ServletContext ServletContext
but when the rest app is just downloaded (whitout my code, neither gdata dependency) it works, the only thing I did was add my code and the google api dependence, so I started to see what could cause the error
remove all my code (but leave the gdata jar) and... wait for it.. same error,
remove gdata dependency: it works
then add gdata dependency again and test: the same error again
So I think that by including the gdata jar does something that prevents start the entire app context
I created a repo on github to illustrate the error:
https://github.com/Grubhart/error_spring_restWS_gdata
the master branch has the code of a service that works without gdata dependence
gdata_error branch as you can imagine has added gdata dependency (only dependency, no extra code) in gradle.build file:
compile 'com.google.gdata: core: 1.47.1'
and presents the error
no need install anything (even gradle) only have jdk, download the code and run it as stated in the readme file to see errors
i do my homework, look in google, stackoverflow (great site!), spring forum but can't find nothing
if anyone has experience with this problem, or know where i can found more information would be great if you can share experiences or if you know where to look for more info about this error
The original post doesn't contains:
yummynoodlebar\config\WebAppInitializer.java:39: error: cannot find symbol
servletContext.setInitParameter("defaultHtmlEscape", "true");
ServletContext needs import javax.servlet.*; Maybe the error is for that.
Since the spring context configuration in java classes for web applications works with Servlet 3.0 maybe you have overwritten troubles between some dependencies that comes with gdata which may do use of dependencies other than the servlet version you are using to deploy the application or which it was originally configured, I hope this helps you!.

jars required for REST service using spring

I am trying to implement a REST services using spring. I have added below JARS in the WEB-INF/lib and in Build path as well.
Spring core
Spring web
Spring MVC
Spring Context
Spring aop
Spring aspects
Common loggin
JSTL.
I have integrated the server in my Eclipse and started. When i try to hit the URL given in Spring controller, I am getting Resource not found Error. Exception I ma getting is ClassNotFound.
In the same project i have a HTML page when i try to hit it, its working fine.
Any jar i have to import or what may be the possible reason?
Have you explored SpringBoot? It is much easier to implement a REST based service. There are just 3 or 4 dependencies. You can find an example to implement a REST service here http://projects.spring.io/spring-boot/#quick-start
Search for the class using some utility like http://findjar.com and make sure that required dependency has been included in your project.
Do mvn dependency:tree to make sure that the respective project has been included.
If the respective project has been included, make sure that the class is there in the included version of the project.

Categories

Resources