From a981da34a93e502a9f5d0d767931fe559016e803 Mon Sep 17 00:00:00 2001 From: Jonathan <42983653+jonnyz32@users.noreply.github.com> Date: Tue, 8 Oct 2024 11:13:04 -0400 Subject: [PATCH] Add http docs, support https (#161) --- .../configuration/DestinationConfig.java | 3 ++- .../manzan/routes/dest/HttpDestination.java | 10 +++++----- docs/README.md | 2 +- docs/config/data.md | 7 ++++++- docs/config/dests.md | 19 ++++++++++++++++++- 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/camel/src/main/java/com/github/theprez/manzan/configuration/DestinationConfig.java b/camel/src/main/java/com/github/theprez/manzan/configuration/DestinationConfig.java index 3218339..2433564 100644 --- a/camel/src/main/java/com/github/theprez/manzan/configuration/DestinationConfig.java +++ b/camel/src/main/java/com/github/theprez/manzan/configuration/DestinationConfig.java @@ -99,8 +99,9 @@ public synchronized Map getRoutes(CamelContext context) { getUriAndHeaderParameters(name, sectionObj, "sid", "token"))); break; case "http": + case "https": final String url = getRequiredString(name, "url"); - ret.put(name, HttpDestination.get(name, url, format, getUriAndHeaderParameters(name, sectionObj, "url"))); + ret.put(name, HttpDestination.get(name, type, url, format, getUriAndHeaderParameters(name, sectionObj, "url"))); break; default: throw new RuntimeException("Unknown destination type: " + type); diff --git a/camel/src/main/java/com/github/theprez/manzan/routes/dest/HttpDestination.java b/camel/src/main/java/com/github/theprez/manzan/routes/dest/HttpDestination.java index efba9f9..8816e14 100644 --- a/camel/src/main/java/com/github/theprez/manzan/routes/dest/HttpDestination.java +++ b/camel/src/main/java/com/github/theprez/manzan/routes/dest/HttpDestination.java @@ -10,10 +10,10 @@ public class HttpDestination extends ManzanGenericCamelRoute { - public static HttpDestination get(final String _name, final String _url, final String _format, Map _parameters) { + public static HttpDestination get(final String _name, String _type, final String _url, final String _format, Map _parameters) { Map headerParameters = new LinkedHashMap(); Map uriParameters = new LinkedHashMap(); - String hostVal = _url.replaceFirst("^http://", "").replaceAll("\\/.*",""); + String hostVal = _url.replaceFirst("^http(s)?://", "").replaceAll("\\/.*",""); headerParameters.put("Host", hostVal); headerParameters.put("User-Agent", "Manzan/1.0"); for(Entry parmEntry : _parameters.entrySet()) { @@ -29,10 +29,10 @@ public static HttpDestination get(final String _name, final String _url, final S uriParameters.put(parmEntry.getKey(), parmEntry.getValue()); } } - return new HttpDestination(_name, _url, _format, uriParameters, headerParameters); + return new HttpDestination(_name, _type, _url, _format, uriParameters, headerParameters); } - private HttpDestination(final String _name, final String _url, final String _format, Map _uriParams, Map _headerParams) { - super(_name, "http", _url.replaceFirst("^http://", ""), _format, _uriParams, _headerParams); + private HttpDestination(final String _name, String _type, final String _url, final String _format, Map _uriParams, Map _headerParams) { + super(_name, _type, _url.replaceFirst("^http(s)?://", ""), _format, _uriParams, _headerParams); } @Override diff --git a/docs/README.md b/docs/README.md index 3687d8e..35cb34c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -42,7 +42,7 @@ Many other destinations will be available. Examples include: - [Google Pub/Sub](http://cloud.google.com/pubsub) ⏳ - [Grafana Loki](https://grafana.com/oss/loki/) ⏳ - HTTP endpoints (REST, etc) ✅ -- HTTPS endpoints (REST, etc) ⏳ +- HTTPS endpoints (REST, etc) ✅ - [Internet of Things (mqtt)](https://www.eclipse.org/paho/) ⏳ - [Kafka](http://kafka.apache.org) ✅ - [Mezmo](http://mezmo.com) ⏳ diff --git a/docs/config/data.md b/docs/config/data.md index 9613716..b196bad 100644 --- a/docs/config/data.md +++ b/docs/config/data.md @@ -14,7 +14,12 @@ Here are the requirements for each section. These are optional properties available on all types: -* `format` can be used to define a nicer messages to be sent to the destination +* `format` can be used to define a nicer messages to be sent to the destination.\ + For file events we have the following variables available: FILE_DATA, FILE_NAME, FILE_PATH.\ + For watch events we have the following variables available: SESSION_ID, MESSAGE_ID, MESSAGE_TYPE, SEVERITY, JOB, SENDING_USRPRF, SENDING_PROGRAM_NAME, SENDING_MODULE_NAME, SENDING_PROCEDURE_NAME, MESSAGE_TIMESTAMP, MESSAGE.\ + \ + By specifying the variable in your format string surrounded by dollar signs, the variables value will be replaced in your format string. Ex. For a file `a.txt` that received the data `hello world` the format string `Data: $FILE_DATA$, Name: $FILE_NAME$` will evaluate to `Data: hello world, Name: a.txt`. `format` can be provided in both data sources and destinations. + * `enabled` is a boolean (`true` or `false`) so a data source can be defined but disabled ```ini diff --git a/docs/config/dests.md b/docs/config/dests.md index 04fd0c6..0fddb1c 100644 --- a/docs/config/dests.md +++ b/docs/config/dests.md @@ -14,10 +14,11 @@ type= # other properties for here.. ``` +As well, each section can provide `format` as an optional type. ## Available types -Some types have additional properties that they required. +Some types have additional properties that they require. | id | Description | Required properties | Optional properties | |------------------|---------------------------------|------------------------------------------------------------| | @@ -27,6 +28,7 @@ Some types have additional properties that they required. | `smtp`/`smtps` | Sent data via email | * `server`
* `subject`
* `to`
* `from`
| * `port` | | `sentry` | Send data into Sentry | * `dsn` | | | `twilio` | Send via SMS | * `sid`
* `token`
* `to`
* `from` | | +| `http`/`https` | Send data via http/https | * `url` | * `httpMethod`
* `x` where x is any query parameter | ### Example @@ -57,4 +59,19 @@ from=+x type=slack channel=open-source-system-status webhook=https://hooks.slack.com/services/TA3EF58G4... + +[myLocalHttpServer] +type=http +url=http://localhost:3000 +a=54 +b=heybuddy +httpMethod=POST +format={"message": "$FILE_DATA$"} + +[myProdServer] +type=https +url=https://production.com +foo=bar +httpMethod=POST +format={"message": "$FILE_DATA$", "path": "$FILE_PATH$", "name": "$FILE_NAME$"} ```