Skip to content

Commit 391321e

Browse files
authored
Merge branch 'master' into tutorials/jerseyFiltersInterceptors
2 parents 660904a + 2df20b0 commit 391321e

366 files changed

Lines changed: 3186 additions & 3778 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
package com.baeldung.ec2;
2+
3+
import java.util.Arrays;
4+
5+
import com.amazonaws.auth.AWSCredentials;
6+
import com.amazonaws.auth.AWSStaticCredentialsProvider;
7+
import com.amazonaws.auth.BasicAWSCredentials;
8+
import com.amazonaws.regions.Regions;
9+
import com.amazonaws.services.ec2.AmazonEC2;
10+
import com.amazonaws.services.ec2.AmazonEC2ClientBuilder;
11+
import com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest;
12+
import com.amazonaws.services.ec2.model.CreateKeyPairRequest;
13+
import com.amazonaws.services.ec2.model.CreateKeyPairResult;
14+
import com.amazonaws.services.ec2.model.CreateSecurityGroupRequest;
15+
import com.amazonaws.services.ec2.model.DescribeInstancesRequest;
16+
import com.amazonaws.services.ec2.model.DescribeInstancesResult;
17+
import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest;
18+
import com.amazonaws.services.ec2.model.DescribeKeyPairsResult;
19+
import com.amazonaws.services.ec2.model.IpPermission;
20+
import com.amazonaws.services.ec2.model.IpRange;
21+
import com.amazonaws.services.ec2.model.MonitorInstancesRequest;
22+
import com.amazonaws.services.ec2.model.RebootInstancesRequest;
23+
import com.amazonaws.services.ec2.model.RunInstancesRequest;
24+
import com.amazonaws.services.ec2.model.StartInstancesRequest;
25+
import com.amazonaws.services.ec2.model.StopInstancesRequest;
26+
import com.amazonaws.services.ec2.model.UnmonitorInstancesRequest;
27+
28+
public class EC2Application {
29+
30+
private static final AWSCredentials credentials;
31+
32+
static {
33+
// put your accesskey and secretkey here
34+
credentials = new BasicAWSCredentials(
35+
"<AWS accesskey>",
36+
"<AWS secretkey>"
37+
);
38+
}
39+
40+
public static void main(String[] args) {
41+
42+
// Set up the client
43+
AmazonEC2 ec2Client = AmazonEC2ClientBuilder.standard()
44+
.withCredentials(new AWSStaticCredentialsProvider(credentials))
45+
.withRegion(Regions.US_EAST_1)
46+
.build();
47+
48+
// Create a security group
49+
CreateSecurityGroupRequest createSecurityGroupRequest = new CreateSecurityGroupRequest().withGroupName("BaeldungSecurityGroup")
50+
.withDescription("Baeldung Security Group");
51+
ec2Client.createSecurityGroup(createSecurityGroupRequest);
52+
53+
// Allow HTTP and SSH traffic
54+
IpRange ipRange1 = new IpRange().withCidrIp("0.0.0.0/0");
55+
56+
IpPermission ipPermission1 = new IpPermission().withIpv4Ranges(Arrays.asList(new IpRange[] { ipRange1 }))
57+
.withIpProtocol("tcp")
58+
.withFromPort(80)
59+
.withToPort(80);
60+
61+
IpPermission ipPermission2 = new IpPermission().withIpv4Ranges(Arrays.asList(new IpRange[] { ipRange1 }))
62+
.withIpProtocol("tcp")
63+
.withFromPort(22)
64+
.withToPort(22);
65+
66+
AuthorizeSecurityGroupIngressRequest authorizeSecurityGroupIngressRequest = new AuthorizeSecurityGroupIngressRequest()
67+
.withGroupName("BaeldungSecurityGroup")
68+
.withIpPermissions(ipPermission1, ipPermission2);
69+
70+
ec2Client.authorizeSecurityGroupIngress(authorizeSecurityGroupIngressRequest);
71+
72+
// Create KeyPair
73+
CreateKeyPairRequest createKeyPairRequest = new CreateKeyPairRequest()
74+
.withKeyName("baeldung-key-pair");
75+
CreateKeyPairResult createKeyPairResult = ec2Client.createKeyPair(createKeyPairRequest);
76+
String privateKey = createKeyPairResult
77+
.getKeyPair()
78+
.getKeyMaterial(); // make sure you keep it, the private key, Amazon doesn't store the private key
79+
80+
// See what key-pairs you've got
81+
DescribeKeyPairsRequest describeKeyPairsRequest = new DescribeKeyPairsRequest();
82+
DescribeKeyPairsResult describeKeyPairsResult = ec2Client.describeKeyPairs(describeKeyPairsRequest);
83+
84+
// Launch an Amazon Instance
85+
RunInstancesRequest runInstancesRequest = new RunInstancesRequest().withImageId("ami-97785bed") // https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html | https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/usingsharedamis-finding.html
86+
.withInstanceType("t2.micro") // https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html
87+
.withMinCount(1)
88+
.withMaxCount(1)
89+
.withKeyName("baeldung-key-pair") // optional - if not present, can't connect to instance
90+
.withSecurityGroups("BaeldungSecurityGroup");
91+
92+
String yourInstanceId = ec2Client.runInstances(runInstancesRequest).getReservation().getInstances().get(0).getInstanceId();
93+
94+
// Start an Instance
95+
StartInstancesRequest startInstancesRequest = new StartInstancesRequest()
96+
.withInstanceIds(yourInstanceId);
97+
98+
ec2Client.startInstances(startInstancesRequest);
99+
100+
// Monitor Instances
101+
MonitorInstancesRequest monitorInstancesRequest = new MonitorInstancesRequest()
102+
.withInstanceIds(yourInstanceId);
103+
104+
ec2Client.monitorInstances(monitorInstancesRequest);
105+
106+
UnmonitorInstancesRequest unmonitorInstancesRequest = new UnmonitorInstancesRequest()
107+
.withInstanceIds(yourInstanceId);
108+
109+
ec2Client.unmonitorInstances(unmonitorInstancesRequest);
110+
111+
// Reboot an Instance
112+
113+
RebootInstancesRequest rebootInstancesRequest = new RebootInstancesRequest()
114+
.withInstanceIds(yourInstanceId);
115+
116+
ec2Client.rebootInstances(rebootInstancesRequest);
117+
118+
// Stop an Instance
119+
StopInstancesRequest stopInstancesRequest = new StopInstancesRequest()
120+
.withInstanceIds(yourInstanceId);
121+
122+
ec2Client.stopInstances(stopInstancesRequest)
123+
.getStoppingInstances()
124+
.get(0)
125+
.getPreviousState()
126+
.getName();
127+
128+
// Describe an Instance
129+
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
130+
DescribeInstancesResult response = ec2Client.describeInstances(describeInstancesRequest);
131+
System.out.println(response.getReservations()
132+
.get(0)
133+
.getInstances()
134+
.get(0)
135+
.getKernelId());
136+
}
137+
}

‎core-groovy/pom.xml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
43
<modelVersion>4.0.0</modelVersion>
54

65
<artifactId>core-groovy</artifactId>

‎core-java-8/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@
4141
- [Primitive Type Streams in Java 8](http://www.baeldung.com/java-8-primitive-streams)
4242
- [Fail-Safe Iterator vs Fail-Fast Iterator](http://www.baeldung.com/java-fail-safe-vs-fail-fast-iterator)
4343
- [Shuffling Collections In Java](http://www.baeldung.com/java-shuffle-collection)
44+
- [Java 8 StringJoiner](http://www.baeldung.com/java-string-joiner)
45+
- [Introduction to Spliterator in Java](http://www.baeldung.com/java-spliterator)

‎core-java-io/.gitignore‎

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,5 @@
1-
*.class
2-
31
0.*
42

5-
#folders#
6-
/target
7-
/neoDb*
8-
/data
9-
/src/main/webapp/WEB-INF/classes
10-
*/META-INF/*
11-
.resourceCache
12-
13-
# Packaged files #
14-
*.jar
15-
*.war
16-
*.ear
17-
183
# Files generated by integration tests
19-
*.txt
20-
backup-pom.xml
21-
/bin/
22-
/temp
23-
24-
#IntelliJ specific
25-
.idea/
26-
*.iml
4+
# *.txt
5+
/temp

‎core-java-io/pom.xml‎

Lines changed: 7 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
32
<modelVersion>4.0.0</modelVersion>
43
<groupId>com.baeldung</groupId>
54
<artifactId>core-java-io</artifactId>
@@ -211,16 +210,6 @@
211210
<artifactId>jmh-generator-annprocess</artifactId>
212211
<version>1.19</version>
213212
</dependency>
214-
<dependency>
215-
<groupId>org.springframework</groupId>
216-
<artifactId>spring-web</artifactId>
217-
<version>4.3.4.RELEASE</version>
218-
</dependency>
219-
<dependency>
220-
<groupId>org.springframework.boot</groupId>
221-
<artifactId>spring-boot-starter</artifactId>
222-
<version>1.5.8.RELEASE</version>
223-
</dependency>
224213
<dependency>
225214
<groupId>org.hsqldb</groupId>
226215
<artifactId>hsqldb</artifactId>
@@ -264,99 +253,6 @@
264253
</configuration>
265254
</plugin>
266255

267-
<plugin>
268-
<groupId>org.apache.maven.plugins</groupId>
269-
<artifactId>maven-dependency-plugin</artifactId>
270-
<executions>
271-
<execution>
272-
<id>copy-dependencies</id>
273-
<phase>prepare-package</phase>
274-
<goals>
275-
<goal>copy-dependencies</goal>
276-
</goals>
277-
<configuration>
278-
<outputDirectory>${project.build.directory}/libs</outputDirectory>
279-
</configuration>
280-
</execution>
281-
</executions>
282-
</plugin>
283-
284-
<plugin>
285-
<groupId>org.apache.maven.plugins</groupId>
286-
<artifactId>maven-jar-plugin</artifactId>
287-
<configuration>
288-
<archive>
289-
<manifest>
290-
<addClasspath>true</addClasspath>
291-
<classpathPrefix>libs/</classpathPrefix>
292-
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
293-
</manifest>
294-
</archive>
295-
</configuration>
296-
</plugin>
297-
298-
<plugin>
299-
<groupId>org.apache.maven.plugins</groupId>
300-
<artifactId>maven-assembly-plugin</artifactId>
301-
<executions>
302-
<execution>
303-
<phase>package</phase>
304-
<goals>
305-
<goal>single</goal>
306-
</goals>
307-
<configuration>
308-
<archiveBaseDirectory>${project.basedir}</archiveBaseDirectory>
309-
<archive>
310-
<manifest>
311-
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
312-
</manifest>
313-
</archive>
314-
<descriptorRefs>
315-
<descriptorRef>jar-with-dependencies</descriptorRef>
316-
</descriptorRefs>
317-
</configuration>
318-
</execution>
319-
</executions>
320-
</plugin>
321-
322-
<plugin>
323-
<groupId>org.apache.maven.plugins</groupId>
324-
<artifactId>maven-shade-plugin</artifactId>
325-
<executions>
326-
<execution>
327-
<goals>
328-
<goal>shade</goal>
329-
</goals>
330-
<configuration>
331-
<shadedArtifactAttached>true</shadedArtifactAttached>
332-
<transformers>
333-
<transformer
334-
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
335-
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
336-
</transformer>
337-
</transformers>
338-
</configuration>
339-
</execution>
340-
</executions>
341-
</plugin>
342-
343-
<plugin>
344-
<groupId>com.jolira</groupId>
345-
<artifactId>onejar-maven-plugin</artifactId>
346-
<executions>
347-
<execution>
348-
<configuration>
349-
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
350-
<attachToBuild>true</attachToBuild>
351-
<filename>${project.build.finalName}-onejar.${project.packaging}</filename>
352-
</configuration>
353-
<goals>
354-
<goal>one-jar</goal>
355-
</goals>
356-
</execution>
357-
</executions>
358-
</plugin>
359-
360256
<plugin>
361257
<groupId>org.springframework.boot</groupId>
362258
<artifactId>spring-boot-maven-plugin</artifactId>
@@ -384,19 +280,19 @@
384280
<argument>-Xmx300m</argument>
385281
<argument>-XX:+UseParallelGC</argument>
386282
<argument>-classpath</argument>
387-
<classpath/>
283+
<classpath />
388284
<argument>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</argument>
389285
</arguments>
390286
</configuration>
391287
</plugin>
392-
288+
393289
<plugin>
394290
<groupId>org.apache.maven.plugins</groupId>
395291
<artifactId>maven-javadoc-plugin</artifactId>
396292
<version>3.0.0-M1</version>
397293
<configuration>
398294
<source>1.8</source>
399-
<target>1.8</target>
295+
<target>1.8</target>
400296
</configuration>
401297
</plugin>
402298

@@ -442,7 +338,7 @@
442338
<executions>
443339
<execution>
444340
<id>run-benchmarks</id>
445-
<!-- <phase>integration-test</phase>-->
341+
<!-- <phase>integration-test</phase> -->
446342
<phase>none</phase>
447343
<goals>
448344
<goal>exec</goal>
@@ -452,7 +348,7 @@
452348
<executable>java</executable>
453349
<arguments>
454350
<argument>-classpath</argument>
455-
<classpath/>
351+
<classpath />
456352
<argument>org.openjdk.jmh.Main</argument>
457353
<argument>.*</argument>
458354
</arguments>
@@ -490,7 +386,7 @@
490386
<protonpack.version>1.13</protonpack.version>
491387
<streamex.version>0.6.5</streamex.version>
492388
<vavr.version>0.9.0</vavr.version>
493-
389+
494390
<!-- testing -->
495391
<org.hamcrest.version>1.3</org.hamcrest.version>
496392
<junit.version>4.12</junit.version>

‎core-java-io/src/main/java/com/baeldung/java/nio2/watcher/DirectoryWatcherExample.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import java.nio.file.WatchService;
1111

1212
public class DirectoryWatcherExample {
13-
13+
1414
public static void main(String[] args) throws IOException, InterruptedException {
1515
WatchService watchService = FileSystems.getDefault().newWatchService();
1616
Path path = Paths.get(System.getProperty("user.home"));
@@ -25,5 +25,5 @@ public static void main(String[] args) throws IOException, InterruptedException
2525

2626
watchService.close();
2727
}
28-
28+
2929
}

‎core-java-io/src/main/resources/targetFile.tmp‎

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)