I'm trying to use the Java SDK to programmatically stop an EC2 instance. I'm very new the AWS api, but what I'm trying to do should be very basic:
BasicAWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);
AmazonEC2Client ec2 = new AmazonEC2Client(credentials); //ERROR caused by this line
I've seen several examples of this, for example here. I know the better way to do this is by using IAM roles, but I'm just trying to get something to work first. The line that creates the AmazonEC2 throws this error
java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper at com.amazonaws.util.json.Jackson.
I can't figure out why it's throwing a class definition not found error.
I figured out the issue. Apparently the AWS library requires three more dependencies in fasterxml.jackson.core. Because I was using Ivy to configure these, I had to add these manually
Related
My Spring boot app is able to make calls to Google pub sub APIs and works perfectly as expected but only when it is not behind a proxy.
I am looking to deploy my app in on-premises datacenter which requires proxy to make outbound HTTP call.
I used HTTPS_PROXY in my environment.. its not working
I used grpc_proxy in my environment.. its not working
Getting this exception
Caused by: java.net.UnknownHostException: pubsub.googleapis.com
at java.base/java.net.InetAddress$CachedAddresses.get(InetAddress.java:797)
at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1505)
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1364)
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1298)
at io.grpc.internal.DnsNameResolver$JdkAddressResolver.resolveAddress(DnsNameResolver.java:631)
at io.grpc.internal.DnsNameResolver.resolveAddresses(DnsNameResolver.java:219)
is there any other way to have proxy injected for google libraries ?
Got a solution for this. As mentioned here, we would have to use GRPC_PROXY_EXP.
I gave it this way GRPC_PROXY_EXP=internet.company.com:93 and it worked perfectly fine
grpc-java and many Java HTTP libraries use the Java-standard -Dhttps.proxyHost=HOST/-Dhttps.proxyPort=PORT for configuring use of a proxy server.
You can't configure them with an environment variable. It is common to just pass the -Ds on the command line. If you want to configure this globally you can change lib/net.properties in the JRE.
I need to run Spring Boot based app locally. It uses spring-cloud-starter-aws dependency.
The problem is that it tries to connect to EC2 metadata service always. Setting "cloud.aws.*" properties doesn't help.
I expect that default AWS credentials chain will be used, credentials and region will be read from one of AWS preferred way (e.g. ~/.aws/config and ~/.aws/credentials files).
I tried to set cloud.aws.credentials.useDefaultAwsCredentialsChain property but spring-cloud-starter-aws doesn't care
I found examples that use CloudFormation stack for very strange reason to run the app locally.
When I use AWS SDK for Java default AWS chain is used without any issues - I don't need to do anything specific for local running of the application (locally it reads credentials from files and on EC2 it uses instance metadata service). But with Spring Boot it doesn't work out of the box and I need to enable local running somehow.
I use 2.2.2.RELEASE version of Spring Boot and 2.2.1.RELEASE version of Spring Cloud. I have a feeling they introduced regression, because in previous versions it worked without problems.
Any ideas how to run the app locally?
Adding the following lines to configuration helps:
cloud.aws.region.static=my region
cloud.aws.stack.auto=false
spring.autoconfigure.exclude=org.springframework.cloud.aws.autoconfigure.metrics.CloudWatchExportAutoConfiguration
So Spring uses AWS default chain but only for credentials. AWS SDK uses it for region and other configuration parameters too. So this is Spring bug for sure.
It still gives a warning about no connection to instance metadata service once during application start but more or less this solution can be used for local running.
If we don't have the last line with excluding CloudWatchExportAutoConfiguration, there will be many exceptions in stack trace while closing the app. I use CloudWatch metrics in my app.
I guess rationale behind excluding aws auto configuration is that it has conflicts with boot actuator but I'm not sure.
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
I have working xmpp client on webapp using strophe.js ,as per my use case scenario i have to switch to different pages rapidly
Current approach is not secure as jid and password is visible in java script ,I was finding work around to implement security in strophe client an trying to make connection time(with bosh) more shorter ,while going through the book "XMPP Programming with JavaScript and jQuery"by jake moffitt i came across one solution which element both of my above problems is to implement session mechanism.which says that we can use strophe attach(jid,sid,rid) to connect to existing connection,so i need SID and RID ,which i can get from application server!!!
book has given an example of automated connection to bosh server when user logged in the web application,author has implement it using an Django project in python,As I am using java as server side language i tried to implement same example using java smcak-4.0.3 and smack-bosh-4.0.3
but unable to connect to bosh server(i am using ejabberd as xmpp server)
my code is as below
BOSHConfiguration config = new BOSHConfiguration(false,"192.168.0.106",5280,"/http-bind/","192.168.0.106");
XMPPBOSHConnection xbc=new XMPPBOSHConnection(config);
xbc.connect();
xbc.login("admin", "admin");
System.out.println(xbc.getConnectionID());
stack trace
java.lang.ClassNotFoundException: org.xmlpull.v1.XmlPullParserFactory
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at org.jivesoftware.smack.SmackConfiguration.processConfigFile(SmackConfiguration.java:352)
at org.jivesoftware.smack.SmackConfiguration.processConfigFile(SmackConfiguration.java:347)
at org.jivesoftware.smack.SmackConfiguration.<clinit>(SmackConfiguration.java:155)
at org.jivesoftware.smack.ConnectionConfiguration.<init>(ConnectionConfiguration.java:67)
When i tried to login to bosh server it fails every time,i am not sure what is wrong here can some one explain me?
One more thing i have find is one can get session identifier(SID) using "xbc.getConnectionID()" but how to find request identifier?
Any help on above problem will be appriciable!!!!
thanks in advance!
I had a similar problem.
I donwload all the smack github I import smack.jar from /lib/ and add the 3 java files from /src/main/java/org/jivesoftware/smack/
I tried to fix it by importing smack-bosh-3.2.2-jar-with-dependencies.jar from /target/. I don't know why this diddn't work.
Finally, I read here that you need to download all the dependencies libraries :
jbosh-0.6.0.jar
xlightweb-2.5.jar
xSocket-2.4.6.jar
xpp3-1.1.3.3.jar
dom4j-1.6.1.jar
So I used smack.jar from /lib/ with all thoses libraries and this problem was solved.
As i said in comments, you need after to retreive RID. I used jbosh sources and add following lines :
In com.kenai.jbosh.BOSHClient class
//I introduced a new property
private Long rid;
//commented the following code
//long rid = requestIDSeq.getNextRID();
//and at that place added
this.rid = requestIDSeq.getNextRID();
//and finally added a new getter for rid
public Long getRid() {
return rid;}
Then in smack-bosh :
In BOSHConnection.java
public Long getRid() {
return client.getRid();}
public String getSid() {
return sessionID;}
Now I'm blocked cause my session is disconected. According to my openFire logs, it's because of overactivity. So I'm looking for a solution to reduce the number of presence messages.
To get latest benefits in Android BOSH you need Smack Releases 4.1.1
SMACK --- smack-tcp smack-sasl-provided smack-resolver-minidns smack-resolver-dnsjava smack-extensions smack-core smack-bosh smack-android-extensions smack-android
You additionally Need
XPP3 1.1.4c delete the javax package from the JAR file for android because android already have javax....QName class
JXMMP, JXMMP CACHE, JBOSH, MINIDNS, DNSJAVA, JSTUN, XBILL DNS
No need for Apache HTTP Client which is already available in android
Unfortunately it comes around some 12 JAR files,
better use Maven Android Project in Eclipse
Otherwise search the above keywords at Maven Central http://search.maven.org/#search and get the JAR files one by one
stack trace
java.lang.ClassNotFoundException: org.xmlpull.v1.XmlPullParserFactory
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at org.jivesoftware.smack.SmackConfiguration.processConfigFile(SmackConfiguration.java:352)
at org.jivesoftware.smack.SmackConfiguration.processConfigFile(SmackConfiguration.java:347)
at org.jivesoftware.smack.SmackConfiguration.<clinit>(SmackConfiguration.java:155)
at org.jivesoftware.smack.ConnectionConfiguration.<init>(ConnectionConfiguration.java:67)
The exception here clearly states that Webapp cant find class org.xmlpull.v1.XmlPullParserFactory. That sounds like you are missing xml-apis library in your classpath, (or some other implementation of XmlPullParser interface).
I am quite new to Java Sesame. I have read through the documentation provided for Sesame. Unfortunately lots of things were not very clear to me. I started with creating the repository as in the code below:
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.manager.RemoteRepositoryManager;
import org.openrdf.repository.sail.SailRepository;
public class RDF{
public void create() throws RepositoryException
{
File dataDir = new File("myFile");
Repository repo = new SailRepository(new MemoryStore(dataDir));
repo.initialize();
String serverUrl = "http://localhost:8080/openrdf-sesame/repositories/rep";
RemoteRepositoryManager manager = new RemoteRepositoryManager(serverUrl);
manager.initialize();
}
}
I am using Tomcat 6. I run the code in Eclipse. I right click the Dynamic Project and select Run on server. The codes were taken from the documentation itself. My questions are what is creating the file dataDir for?
Is this address http://localhost:8080/openrdf-sesame/repositories/rep of the location where the repository is created? After starting Tomcat, I use the above link but it shows me there is an error.
How can I make sure that the repository has successfully been created and how can I start to use it. Your assistance would be very much appreciated.
You are mixing up two things:
creating a local repository (a MemoryStore persisted to dataDir), and
a remote repository living on the Sesame server
If you just want to create a persistent repository the first option is sufficient. If you want to also have a full Sesame server with all its UI and services then you have to install it, set it up first and use the second option.
In both cases, you can use the RepositoryManager API. An introduction to RepositoryManager.
You wouldn't typically start the Sesame server and workbench via Eclipse. You would use a standalone installation as described in the documentation.