Skip to content

Commit bd812e1

Browse files
committed
Initial commit
0 parents  commit bd812e1

File tree

17 files changed

+977
-0
lines changed

17 files changed

+977
-0
lines changed

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
### IntelliJ IDEA ###
2+
.idea
3+
!.idea/
4+
.idea/*
5+
!.idea/runConfigurations/
6+
*.iws
7+
*.iml
8+
*.ipr
9+
*.log*
10+
target/
11+
12+
### STS ###
13+
.apt_generated
14+
.classpath
15+
.factorypath
16+
.project
17+
.settings
18+
.springBeans
19+
.sts4-cache
20+
21+
### NetBeans ###
22+
/nbproject/private/
23+
/nbbuild/
24+
/dist/
25+
/nbdist/
26+
/.nb-gradle/
27+
build/
28+
29+
### VS Code ###
30+
.vscode/

.idea/runConfigurations/ServerApplication.xml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright 2007-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import java.net.*;
17+
import java.io.*;
18+
import java.nio.channels.*;
19+
import java.util.Properties;
20+
21+
public class MavenWrapperDownloader {
22+
23+
private static final String WRAPPER_VERSION = "0.5.5";
24+
/**
25+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
26+
*/
27+
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
28+
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
29+
30+
/**
31+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
32+
* use instead of the default one.
33+
*/
34+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
35+
".mvn/wrapper/maven-wrapper.properties";
36+
37+
/**
38+
* Path where the maven-wrapper.jar will be saved to.
39+
*/
40+
private static final String MAVEN_WRAPPER_JAR_PATH =
41+
".mvn/wrapper/maven-wrapper.jar";
42+
43+
/**
44+
* Name of the property which should be used to override the default download url for the wrapper.
45+
*/
46+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
47+
48+
public static void main(String args[]) {
49+
System.out.println("- Downloader started");
50+
File baseDirectory = new File(args[0]);
51+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
52+
53+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
54+
// wrapperUrl parameter.
55+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
56+
String url = DEFAULT_DOWNLOAD_URL;
57+
if(mavenWrapperPropertyFile.exists()) {
58+
FileInputStream mavenWrapperPropertyFileInputStream = null;
59+
try {
60+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
61+
Properties mavenWrapperProperties = new Properties();
62+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
63+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
64+
} catch (IOException e) {
65+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
66+
} finally {
67+
try {
68+
if(mavenWrapperPropertyFileInputStream != null) {
69+
mavenWrapperPropertyFileInputStream.close();
70+
}
71+
} catch (IOException e) {
72+
// Ignore ...
73+
}
74+
}
75+
}
76+
System.out.println("- Downloading from: " + url);
77+
78+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
79+
if(!outputFile.getParentFile().exists()) {
80+
if(!outputFile.getParentFile().mkdirs()) {
81+
System.out.println(
82+
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
83+
}
84+
}
85+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
86+
try {
87+
downloadFileFromURL(url, outputFile);
88+
System.out.println("Done");
89+
System.exit(0);
90+
} catch (Throwable e) {
91+
System.out.println("- Error downloading");
92+
e.printStackTrace();
93+
System.exit(1);
94+
}
95+
}
96+
97+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
98+
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
99+
String username = System.getenv("MVNW_USERNAME");
100+
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
101+
Authenticator.setDefault(new Authenticator() {
102+
@Override
103+
protected PasswordAuthentication getPasswordAuthentication() {
104+
return new PasswordAuthentication(username, password);
105+
}
106+
});
107+
}
108+
URL website = new URL(urlString);
109+
ReadableByteChannel rbc;
110+
rbc = Channels.newChannel(website.openStream());
111+
FileOutputStream fos = new FileOutputStream(destination);
112+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
113+
fos.close();
114+
rbc.close();
115+
}
116+
117+
}

.mvn/wrapper/maven-wrapper.jar

49.5 KB
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar

.travis.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
notifications:
2+
email: false
3+
git:
4+
quiet: true
5+
depth: false
6+
language: python
7+
python: 3.8
8+
node_js: lts/*
9+
jdk: openjdk11
10+
os: linux
11+
arch: amd64
12+
addons:
13+
apt:
14+
update: false
15+
packages:
16+
- jq
17+
- curl
18+
install: true
19+
before_install:
20+
- |
21+
if [ ! -f ${HOME}/.local/daggerok/bash-functions/master/main.bash ] ; then
22+
mkdir -p ${HOME}/.local/daggerok/bash-functions/master ;
23+
curl -s https://raw.githubusercontent.com/daggerok/bash-functions/master/main.bash > ${HOME}/.local/daggerok/bash-functions/master/main.bash ;
24+
fi
25+
source ${HOME}/.local/daggerok/bash-functions/master/main.bash ;
26+
- stop_any 80 5432 8080
27+
#
28+
- |
29+
python -m pip install --upgrade pip setuptools pyopenssl
30+
python -m pip install --upgrade httpie
31+
jobs:
32+
include:
33+
- stage: test
34+
name: tests
35+
before_script:
36+
- cd $TRAVIS_BUILD_DIR && ./mvnw
37+
- bash $TRAVIS_BUILD_DIR/server/target/*.jar &
38+
- wait_for 8080
39+
script:
40+
- http :8080/ololo/trololo
41+
- cd $TRAVIS_BUILD_DIR && ./mvnw -f client integration-test
42+
after_script:
43+
- stop_any 80
44+
cache:
45+
npm: true
46+
pip: true
47+
packages: true
48+
directories:
49+
- ~/.m2
50+
- ~/.local/daggerok

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Java 11 embedded http client [![Build Status](https://travis-ci.org/daggerok/java-11-http-client.svg?branch=master)](https://travis-ci.org/daggerok/java-11-http-client)
2+
Using embedded HttpClient in Java 11
3+
4+
```bash
5+
./mvnw spring-boot:run
6+
./mvnw -f clioent -P it
7+
```
8+
9+
<!--
10+
## resources
11+
* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html)
12+
* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.2.4.RELEASE/maven-plugin/)
13+
* [Spring Web](https://docs.spring.io/spring-boot/docs/2.2.4.RELEASE/reference/htmlsingle/#boot-features-developing-web-applications)
14+
* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/)
15+
* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/)
16+
* [Building REST services with Spring](https://spring.io/guides/tutorials/bookmarks/)
17+
-->

client/pom.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
6+
<parent>
7+
<artifactId>java-11-http-client</artifactId>
8+
<groupId>org.example</groupId>
9+
<version>1.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<modelVersion>4.0.0</modelVersion>
13+
<artifactId>client</artifactId>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.apache.logging.log4j</groupId>
18+
<artifactId>log4j-core</artifactId>
19+
</dependency>
20+
<dependency>
21+
<groupId>org.projectlombok</groupId>
22+
<artifactId>lombok</artifactId>
23+
<optional>true</optional>
24+
<scope>provided</scope>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.junit.jupiter</groupId>
28+
<artifactId>junit-jupiter</artifactId>
29+
<scope>test</scope>
30+
</dependency>
31+
</dependencies>
32+
33+
<build>
34+
<plugins>
35+
<plugin>
36+
<groupId>org.apache.maven.plugins</groupId>
37+
<artifactId>maven-failsafe-plugin</artifactId>
38+
</plugin>
39+
</plugins>
40+
</build>
41+
42+
</project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.example.server;
2+
3+
import lombok.extern.log4j.Log4j2;
4+
import org.junit.jupiter.api.Test;
5+
6+
import java.io.IOException;
7+
import java.net.URI;
8+
import java.net.http.HttpClient;
9+
import java.net.http.HttpRequest;
10+
import java.net.http.HttpResponse;
11+
12+
@Log4j2
13+
class ServerApplicationIT {
14+
15+
@Test
16+
void embedded_java11_http_client_tests() throws IOException, InterruptedException {
17+
var client = HttpClient.newBuilder()
18+
.version(HttpClient.Version.HTTP_1_1)
19+
.build();
20+
var request = HttpRequest.newBuilder()
21+
.uri(URI.create("http://127.0.0.1:8080/ololo"))
22+
.GET()
23+
.build();
24+
log.info("req: {}", request);
25+
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
26+
log.info("resp: {}", response.body());
27+
}
28+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="INFO">
3+
<Properties>
4+
<Property name="LOG_LEVEL_PATTERN">%5p</Property>
5+
<Property name="LOG_EXCEPTION_CONVERSION_WORD">%xEx</Property>
6+
<Property name="LOG_DATEFORMAT_PATTERN">yyyy-MM-dd HH:mm:ss.SSS</Property>
7+
<Property name="LOG_PATTERN">%style{%d{${LOG_DATEFORMAT_PATTERN}}}{faint} %style{${LOG_LEVEL_PATTERN}} %style{%pid}{magenta} %style{---}{faint} %style{[%15.15t]}{faint} %style{%-40.40c{1.}}{cyan} %style{:}{faint} %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}</Property>
8+
</Properties>
9+
<Appenders>
10+
<Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">
11+
<PatternLayout pattern="${LOG_PATTERN}" />
12+
</Console>
13+
</Appenders>
14+
<Loggers>
15+
<logger name="org.jboss.weld" level="WARN" additivity="false">
16+
<appender-ref ref="ConsoleAppender"/>
17+
</logger>
18+
<logger name="daggerok" level="ALL" additivity="false">
19+
<appender-ref ref="ConsoleAppender"/>
20+
</logger>
21+
<Root level="INFO">
22+
<AppenderRef ref="ConsoleAppender"/>
23+
</Root>
24+
</Loggers>
25+
</Configuration>

0 commit comments

Comments
 (0)