Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
erunion committed May 27, 2020
2 parents f090b1c + cc8e368 commit 49bc69b
Show file tree
Hide file tree
Showing 19 changed files with 212 additions and 1 deletion.
55 changes: 55 additions & 0 deletions src/targets/java/asynchttp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @description
* Asynchronous Http and WebSocket Client library for Java
*
* @author
* @windard
*
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
*/

'use strict'

var CodeBuilder = require('../../helpers/code-builder')

module.exports = function (source, options) {
var opts = Object.assign({
indent: ' '
}, options)

var code = new CodeBuilder(opts.indent)

code.push('AsyncHttpClient client = new DefaultAsyncHttpClient();')

code.push(`client.prepare${source.method[0].toUpperCase()}${source.method.substring(1).toLowerCase()}("${source.fullUrl}")`)

// Add headers, including the cookies
var headers = Object.keys(source.allHeaders)

// construct headers
if (headers.length) {
headers.forEach(function (key) {
code.push(1, '.setHeader("%s", "%s")', key, source.allHeaders[key])
})
}

if (source.postData.text) {
code.push(1, '.setBody(%s)', JSON.stringify(source.postData.text))
}

code.push(1, '.execute()')
code.push(1, '.toCompletableFuture()')
code.push(1, '.thenAccept(System.out::println)')
code.push(1, '.join();')
code.blank()
code.push('client.close();')

return code.join()
}

module.exports.info = {
key: 'asynchttp',
title: 'AsyncHttp',
link: 'https://github.com/AsyncHttpClient/async-http-client',
description: 'Asynchronous Http and WebSocket Client library for Java'
}
4 changes: 3 additions & 1 deletion src/targets/java/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ module.exports = {
},

okhttp: require('./okhttp'),
unirest: require('./unirest')
unirest: require('./unirest'),
asynchttp: require('./asynchttp')

}
6 changes: 6 additions & 0 deletions test/fixtures/available-targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@
"title": "Unirest",
"link": "http://unirest.io/java.html",
"description": "Lightweight HTTP Request Client Library"
},
{
"key": "asynchttp",
"title": "AsyncHttp",
"link": "https://github.com/AsyncHttpClient/async-http-client",
"description": "Asynchronous Http and WebSocket Client library for Java"
}
]
},
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/output/java/asynchttp/application-form-encoded.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
AsyncHttpClient client = new DefaultAsyncHttpClient();
client.preparePost("http://mockbin.com/har")
.setHeader("content-type", "application/x-www-form-urlencoded")
.setBody("foo=bar&hello=world")
.execute()
.toCompletableFuture()
.thenAccept(System.out::println)
.join();

client.close();
10 changes: 10 additions & 0 deletions test/fixtures/output/java/asynchttp/application-json.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
AsyncHttpClient client = new DefaultAsyncHttpClient();
client.preparePost("http://mockbin.com/har")
.setHeader("content-type", "application/json")
.setBody("{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}],\"boolean\":false}")
.execute()
.toCompletableFuture()
.thenAccept(System.out::println)
.join();

client.close();
9 changes: 9 additions & 0 deletions test/fixtures/output/java/asynchttp/cookies.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
AsyncHttpClient client = new DefaultAsyncHttpClient();
client.preparePost("http://mockbin.com/har")
.setHeader("cookie", "foo=bar; bar=baz")
.execute()
.toCompletableFuture()
.thenAccept(System.out::println)
.join();

client.close();
8 changes: 8 additions & 0 deletions test/fixtures/output/java/asynchttp/custom-method.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
AsyncHttpClient client = new DefaultAsyncHttpClient();
client.preparePropfind("http://mockbin.com/har")
.execute()
.toCompletableFuture()
.thenAccept(System.out::println)
.join();

client.close();
12 changes: 12 additions & 0 deletions test/fixtures/output/java/asynchttp/full.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
AsyncHttpClient client = new DefaultAsyncHttpClient();
client.preparePost("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value")
.setHeader("cookie", "foo=bar; bar=baz")
.setHeader("accept", "application/json")
.setHeader("content-type", "application/x-www-form-urlencoded")
.setBody("foo=bar")
.execute()
.toCompletableFuture()
.thenAccept(System.out::println)
.join();

client.close();
10 changes: 10 additions & 0 deletions test/fixtures/output/java/asynchttp/headers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
AsyncHttpClient client = new DefaultAsyncHttpClient();
client.prepareGet("http://mockbin.com/har")
.setHeader("accept", "application/json")
.setHeader("x-foo", "Bar")
.execute()
.toCompletableFuture()
.thenAccept(System.out::println)
.join();

client.close();
8 changes: 8 additions & 0 deletions test/fixtures/output/java/asynchttp/https.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
AsyncHttpClient client = new DefaultAsyncHttpClient();
client.prepareGet("https://mockbin.com/har")
.execute()
.toCompletableFuture()
.thenAccept(System.out::println)
.join();

client.close();
10 changes: 10 additions & 0 deletions test/fixtures/output/java/asynchttp/jsonObj-multiline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
AsyncHttpClient client = new DefaultAsyncHttpClient();
client.preparePost("http://mockbin.com/har")
.setHeader("content-type", "application/json")
.setBody("{\n \"foo\": \"bar\"\n}")
.execute()
.toCompletableFuture()
.thenAccept(System.out::println)
.join();

client.close();
10 changes: 10 additions & 0 deletions test/fixtures/output/java/asynchttp/jsonObj-null-value.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
AsyncHttpClient client = new DefaultAsyncHttpClient();
client.preparePost("http://mockbin.com/har")
.setHeader("content-type", "application/json")
.setBody("{\"foo\":null}")
.execute()
.toCompletableFuture()
.thenAccept(System.out::println)
.join();

client.close();
10 changes: 10 additions & 0 deletions test/fixtures/output/java/asynchttp/multipart-data.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
AsyncHttpClient client = new DefaultAsyncHttpClient();
client.preparePost("http://mockbin.com/har")
.setHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001")
.setBody("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001--\r\n")
.execute()
.toCompletableFuture()
.thenAccept(System.out::println)
.join();

client.close();
10 changes: 10 additions & 0 deletions test/fixtures/output/java/asynchttp/multipart-file.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
AsyncHttpClient client = new DefaultAsyncHttpClient();
client.preparePost("http://mockbin.com/har")
.setHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001")
.setBody("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--\r\n")
.execute()
.toCompletableFuture()
.thenAccept(System.out::println)
.join();

client.close();
10 changes: 10 additions & 0 deletions test/fixtures/output/java/asynchttp/multipart-form-data.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
AsyncHttpClient client = new DefaultAsyncHttpClient();
client.preparePost("http://mockbin.com/har")
.setHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001")
.setBody("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n")
.execute()
.toCompletableFuture()
.thenAccept(System.out::println)
.join();

client.close();
8 changes: 8 additions & 0 deletions test/fixtures/output/java/asynchttp/query.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
AsyncHttpClient client = new DefaultAsyncHttpClient();
client.prepareGet("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value")
.execute()
.toCompletableFuture()
.thenAccept(System.out::println)
.join();

client.close();
8 changes: 8 additions & 0 deletions test/fixtures/output/java/asynchttp/short.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
AsyncHttpClient client = new DefaultAsyncHttpClient();
client.prepareGet("http://mockbin.com/har")
.execute()
.toCompletableFuture()
.thenAccept(System.out::println)
.join();

client.close();
10 changes: 10 additions & 0 deletions test/fixtures/output/java/asynchttp/text-plain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
AsyncHttpClient client = new DefaultAsyncHttpClient();
client.preparePost("http://mockbin.com/har")
.setHeader("content-type", "text/plain")
.setBody("Hello World")
.execute()
.toCompletableFuture()
.thenAccept(System.out::println)
.join();

client.close();
5 changes: 5 additions & 0 deletions test/targets/java/asynchttp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict'

require('should')

module.exports = function (snippet, fixtures) {}

0 comments on commit 49bc69b

Please sign in to comment.