Skip to content

Commit dfbf50d

Browse files
max904-githubs-gromov
authored andcommitted
Implemented Armeria-based http client binding for ScribeJava.
Armeria (https://github.com/line/armeria/) is an open-source asynchronous HTTP/2/1 client/server library built on top of Netty and Java 8. Java 8 required to build this http client module.
1 parent 68a73ac commit dfbf50d

File tree

9 files changed

+782
-0
lines changed

9 files changed

+782
-0
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<module>scribejava-httpclient-ning</module>
2222
<module>scribejava-httpclient-okhttp</module>
2323
<module>scribejava-httpclient-apache</module>
24+
<module>scribejava-httpclient-armeria</module>
2425
</modules>
2526

2627
<licenses>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?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" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>com.github.scribejava</groupId>
7+
<artifactId>scribejava</artifactId>
8+
<version>6.9.1-SNAPSHOT</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
12+
<artifactId>scribejava-httpclient-armeria</artifactId>
13+
<name>ScribeJava Async Armeria Client support</name>
14+
<packaging>jar</packaging>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>com.github.scribejava</groupId>
19+
<artifactId>scribejava-core</artifactId>
20+
<version>${project.version}</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>com.linecorp.armeria</groupId>
24+
<artifactId>armeria</artifactId>
25+
<version>0.97.0</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>com.github.scribejava</groupId>
29+
<artifactId>scribejava-core</artifactId>
30+
<version>${project.version}</version>
31+
<type>test-jar</type>
32+
<scope>test</scope>
33+
</dependency>
34+
<dependency>
35+
<groupId>io.netty</groupId>
36+
<artifactId>netty-all</artifactId>
37+
<version>4.1.43.Final</version>
38+
<scope>test</scope>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.slf4j</groupId>
42+
<artifactId>slf4j-simple</artifactId>
43+
<version>1.7.30</version>
44+
<scope>test</scope>
45+
</dependency>
46+
</dependencies>
47+
48+
<build>
49+
<plugins>
50+
<plugin>
51+
<artifactId>maven-compiler-plugin</artifactId>
52+
<version>3.8.1</version>
53+
<configuration>
54+
<encoding>UTF-8</encoding>
55+
<release>8</release>
56+
<showDeprecation>true</showDeprecation>
57+
</configuration>
58+
</plugin>
59+
<plugin>
60+
<groupId>org.apache.felix</groupId>
61+
<artifactId>maven-bundle-plugin</artifactId>
62+
</plugin>
63+
<plugin>
64+
<groupId>org.apache.maven.plugins</groupId>
65+
<artifactId>maven-jar-plugin</artifactId>
66+
</plugin>
67+
</plugins>
68+
</build>
69+
</project>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.github.scribejava.core.httpclient.multipart;
2+
3+
import java.io.ByteArrayOutputStream;
4+
import java.io.IOException;
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
public abstract class MultipartUtils {
9+
10+
// copied from com.github.scribejava.core.httpclient.jdk.JDKHttpClient#getPayload
11+
public static ByteArrayOutputStream getPayload(MultipartPayload multipartPayload) throws IOException {
12+
final ByteArrayOutputStream os = new ByteArrayOutputStream();
13+
14+
final String preamble = multipartPayload.getPreamble();
15+
if (preamble != null) {
16+
os.write(preamble.getBytes());
17+
}
18+
final List<BodyPartPayload> bodyParts = multipartPayload.getBodyParts();
19+
if (!bodyParts.isEmpty()) {
20+
final String boundary = multipartPayload.getBoundary();
21+
final byte[] startBoundary = ("\r\n--" + boundary + "\r\n").getBytes();
22+
23+
for (BodyPartPayload bodyPart : bodyParts) {
24+
os.write(startBoundary);
25+
26+
final Map<String, String> bodyPartHeaders = bodyPart.getHeaders();
27+
if (bodyPartHeaders != null) {
28+
for (Map.Entry<String, String> header : bodyPartHeaders.entrySet()) {
29+
os.write((header.getKey() + ": " + header.getValue() + "\r\n").getBytes());
30+
}
31+
}
32+
33+
if (bodyPart instanceof MultipartPayload) {
34+
getPayload((MultipartPayload) bodyPart).writeTo(os);
35+
} else if (bodyPart instanceof ByteArrayBodyPartPayload) {
36+
os.write("\r\n".getBytes());
37+
os.write(((ByteArrayBodyPartPayload) bodyPart).getPayload());
38+
} else {
39+
throw new AssertionError(bodyPart.getClass());
40+
}
41+
}
42+
43+
os.write(("\r\n--" + boundary + "--\r\n").getBytes());
44+
final String epilogue = multipartPayload.getEpilogue();
45+
if (epilogue != null) {
46+
os.write((epilogue + "\r\n").getBytes());
47+
}
48+
49+
}
50+
return os;
51+
}
52+
53+
}

0 commit comments

Comments
 (0)