Skip to content

Commit

Permalink
#349 extension: simplehttpclient fix put request, update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Mar 22, 2018
1 parent 3cfe7ee commit 25874d6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/extensions-howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function executeScript(scriptEvent) {
log.warn('hello from script with event: ' + scriptEvent);
log.warn('extension parameters are: ' + extensionParameters);
//this sample calls the https://csrng.net/ website and generates a random invoice number
var randomNumber = restTemplate.getForObject('https://csrng.net/csrng/csrng.php?min=0&max=100', Java.type('java.util.ArrayList').class)[0].random;
var randomNumber = simpleHttpClient.get('https://csrng.net/csrng/csrng.php?min=0&max=100').getJsonBody()[0].random;
log.warn('the invoice number will be: ' + randomNumber);
return {
invoiceNumber: randomNumber
Expand All @@ -71,8 +71,8 @@ alf.io provides some objects and properties to the script in the script scope:

* **log** Log4j logger
* **extensionLogger** a logger that write in the extension_log table. It implement the [ExtensionLogger](https://github.com/alfio-event/alf.io/blob/master/src/main/java/alfio/extension/ExtensionLogger.java) interface.
* **restTemplate** Spring Framework's [RestTemplate](https://docs.spring.io/spring/docs/4.3.13.RELEASE/javadoc-api/org/springframework/web/client/RestTemplate.html)
* **httpClient** instance of a [OkHttpClient](http://square.github.io/okhttp/)
* **simpleHttpClient** instance of a [SimpleHttpClient](https://github.com/alfio-event/alf.io/blob/master/src/main/java/alfio/extension/SimpleHttpClient.java)
* **GSON** Google's [JSON parser/generator](http://static.javadoc.io/com.google.code.gson/gson/2.8.2/com/google/gson/Gson.html)
* **returnClass** `java.lang.Class<?>` the expected result type
* **extensionParameters** a map containing the parameters of an extension
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/alfio/extension/ScriptingExecutionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
public class ScriptingExecutionService {

private static final OkHttpClient HTTP_CLIENT = new OkHttpClient();
private static final RestTemplate REST_TEMPLATE = new RestTemplate();
private static final SimpleHttpClient SIMPLE_HTTP_CLIENT = new SimpleHttpClient(HTTP_CLIENT);

private final static Compilable engine = (Compilable) new ScriptEngineManager().getEngineByName("nashorn");
Expand Down Expand Up @@ -106,7 +105,6 @@ private static <T> T executeScript(String name, CompiledScript script, Map<Strin
engineScope.put("log", log);
engineScope.put("extensionLogger", extensionLogger);
engineScope.put("GSON", Json.GSON);
engineScope.put("restTemplate", REST_TEMPLATE);
engineScope.put("httpClient", HTTP_CLIENT);
engineScope.put("simpleHttpClient", SIMPLE_HTTP_CLIENT);
engineScope.put("returnClass", clazz);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/alfio/extension/SimpleHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public HttpClientResponse put(String url, Map<String, String> headers) throws IO
}

public HttpClientResponse put(String url, Map<String, String> headers, Object body) throws IOException {
return doRequest(url, headers, "POST", body);
return doRequest(url, headers, "PUT", body);
}


Expand Down

0 comments on commit 25874d6

Please sign in to comment.