This is an automated email from the ASF dual-hosted git repository.
hansva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/main by this push:
new aea89548c5 REST metadata type, REST client transform changes to use
REST metadata type #4369 (#4440)
aea89548c5 is described below
commit aea89548c5017cae7163a1df7efb872550dfd775
Author: Bart Maertens <[email protected]>
AuthorDate: Tue Oct 22 12:01:39 2024 +0200
REST metadata type, REST client transform changes to use REST metadata type
#4369 (#4440)
---
assemblies/plugins/pom.xml | 6 +
.../modules/ROOT/assets/images/icons/rest.svg | 75 ++++
.../ROOT/pages/metadata-types/rest-connection.adoc | 49 +++
.../ROOT/pages/pipeline/transforms/rest.adoc | 6 +
plugins/misc/pom.xml | 1 +
plugins/{transforms => misc}/rest/pom.xml | 20 +-
.../rest/src/assembly/assembly.xml | 16 +-
.../apache/hop/metadata/rest/RestConnection.java | 186 +++++++++
.../hop/metadata/rest/RestConnectionEditor.java | 249 ++++++++++++
.../rest/messages/messages_en_US.properties | 26 ++
plugins/misc/rest/src/main/resources/rest.svg | 75 ++++
.../rest/src/main/resources/version.xml} | 22 +-
.../org/apache/hop/metadata/rest/RestTest.java | 38 ++
plugins/transforms/rest/pom.xml | 5 +
plugins/transforms/rest/src/assembly/assembly.xml | 5 +
.../apache/hop/pipeline/transforms/rest/Rest.java | 79 +++-
.../hop/pipeline/transforms/rest/RestData.java | 2 +-
.../hop/pipeline/transforms/rest/RestDialog.java | 156 +++++---
.../hop/pipeline/transforms/rest/RestMeta.java | 421 +++++----------------
.../transforms/rest/fields/HeaderField.java | 52 +++
.../rest/fields/MatrixParameterField.java | 52 +++
.../transforms/rest/fields/ParameterField.java | 52 +++
.../transforms/rest/fields/ResultField.java | 74 ++++
.../rest/src/main/resources/dependencies.xml | 21 +
.../hop/pipeline/transforms/rest/RestMetaTest.java | 288 ++++++++++++--
25 files changed, 1498 insertions(+), 478 deletions(-)
diff --git a/assemblies/plugins/pom.xml b/assemblies/plugins/pom.xml
index be689b57c6..076493229b 100644
--- a/assemblies/plugins/pom.xml
+++ b/assemblies/plugins/pom.xml
@@ -684,6 +684,12 @@
<version>${project.version}</version>
<type>zip</type>
</dependency>
+ <dependency>
+ <groupId>org.apache.hop</groupId>
+ <artifactId>hop-misc-rest</artifactId>
+ <version>${project.version}</version>
+ <type>zip</type>
+ </dependency>
<dependency>
<groupId>org.apache.hop</groupId>
<artifactId>hop-misc-static-schema</artifactId>
diff --git a/docs/hop-user-manual/modules/ROOT/assets/images/icons/rest.svg
b/docs/hop-user-manual/modules/ROOT/assets/images/icons/rest.svg
new file mode 100644
index 0000000000..a894773268
--- /dev/null
+++ b/docs/hop-user-manual/modules/ROOT/assets/images/icons/rest.svg
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 17.0.0, SVG Export Plug-In . SVG Version:
6.00 Build 0) -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px"
+ width="42px" height="42px" viewBox="0 0 42 42" enable-background="new 0 0
42 42">
+ <g>
+ <path fill="none"
+
d="M4.788,3.785h-1.01v1.63h1.01c0.518,0,0.64-0.129,0.64-0.492V4.277C5.428,3.909,5.307,3.785,4.788,3.785z"/>
+ <path fill="#C9E8FB"
d="M16.364,14.859c-1.113-0.303-2.195-0.699-3.229-1.193c-1.923,2.015-3.131,4.709-3.232,7.684h5.256
+ C15.205,19.092,15.608,16.897,16.364,14.859z"/>
+ <path fill="#C9E8FB"
d="M18.76,10.388c-1.892,0.475-3.6,1.407-5.003,2.677c0.939,0.429,1.916,0.783,2.921,1.052
+ C17.234,12.796,17.921,11.54,18.76,10.388z"/>
+ <path fill="#C9E8FB"
d="M17.118,28.438c1.329-0.296,2.702-0.458,4.092-0.482v-5.804h-5.251
+ C16.001,24.351,16.394,26.476,17.118,28.438z"/>
+ <path fill="#C9E8FB"
+
d="M15.96,21.351h5.25v-5.8c-1.378-0.027-2.738-0.196-4.059-0.498C16.407,17.027,16.006,19.156,15.96,21.351z"
+ />
+ <path fill="#C9E8FB"
d="M15.158,22.151H9.903c0.101,2.962,1.299,5.645,3.208,7.657c1.026-0.484,2.105-0.877,3.223-1.175
+ C15.596,26.607,15.201,24.415,15.158,22.151z"/>
+ <path fill="#C9E8FB"
d="M13.723,30.405c1.394,1.271,3.09,2.208,4.972,2.692c-0.828-1.142-1.507-2.394-2.054-3.717
+ C15.632,29.642,14.655,29.984,13.723,30.405z"/>
+ <path fill="#C9E8FB"
d="M17.468,14.304c1.219,0.269,2.472,0.42,3.742,0.446v-4.706c-0.418,0.014-0.831,0.051-1.237,0.108
+ C18.95,11.411,18.111,12.806,17.468,14.304z"/>
+ <path fill="#C9E8FB"
d="M19.906,33.34c0.428,0.063,0.862,0.103,1.304,0.118v-4.702c-1.285,0.024-2.553,0.17-3.783,0.435
+ C18.062,30.697,18.892,32.093,19.906,33.34z"/>
+ <path fill="#0E3A5A"
d="M27.386,23.713c1.059,0,1.921-0.861,1.921-1.92s-0.862-1.921-1.921-1.921c-0.906,0-1.663,0.633-1.863,1.479
+
h-3.512v-5.787h6.397c0.171,0.885,0.95,1.556,1.884,1.556c1.059,0,1.92-0.862,1.92-1.921s-0.861-1.92-1.92-1.92
+
c-0.908,0-1.668,0.636-1.866,1.484h-6.415v-4.739h4.702c0.311,0.642,0.963,1.09,1.723,1.09c1.059,0,1.921-0.862,1.921-1.921
+
s-0.862-1.92-1.921-1.92c-0.745,0-1.384,0.431-1.703,1.052H21.61c-7.403,0-13.427,6.023-13.427,13.427
+
c0,6.952,5.312,12.686,12.09,13.359l1.737-1.607V22.151h3.491C25.671,23.039,26.45,23.713,27.386,23.713z
M27.386,20.673
+
c0.618,0,1.12,0.502,1.12,1.12c0,0.617-0.502,1.119-1.12,1.119c-0.617,0-1.119-0.502-1.119-1.119
+ C26.267,21.175,26.769,20.673,27.386,20.673z
M30.292,14.079c0.617,0,1.119,0.502,1.119,1.119c0,0.618-0.502,1.12-1.119,1.12
+
c-0.618,0-1.12-0.502-1.12-1.12C29.172,14.581,29.674,14.079,30.292,14.079z
M28.436,8.073c0.618,0,1.12,0.502,1.12,1.119
+
c0,0.618-0.502,1.12-1.12,1.12c-0.617,0-1.119-0.502-1.119-1.12C27.316,8.575,27.818,8.073,28.436,8.073z
M18.76,10.388
+
c-0.839,1.152-1.526,2.408-2.082,3.729c-1.006-0.268-1.982-0.622-2.921-1.052C15.161,11.796,16.868,10.863,18.76,10.388z
+
M13.136,13.666c1.033,0.493,2.115,0.889,3.229,1.193c-0.756,2.038-1.16,4.233-1.205,6.491H9.903
+ C10.004,18.376,11.212,15.682,13.136,13.666z
M9.903,22.151h5.255c0.042,2.264,0.438,4.455,1.176,6.482
+
c-1.118,0.298-2.197,0.69-3.223,1.175C11.203,27.796,10.004,25.113,9.903,22.151z
M13.723,30.405
+
c0.933-0.421,1.909-0.762,2.918-1.025c0.546,1.323,1.226,2.575,2.054,3.717C16.813,32.613,15.116,31.676,13.723,30.405z
+
M21.21,33.458c-0.441-0.015-0.876-0.055-1.304-0.118c-1.015-1.248-1.845-2.643-2.479-4.149c1.23-0.265,2.498-0.411,3.783-0.435
+ V33.458z
M21.21,27.956c-1.39,0.025-2.763,0.186-4.092,0.482c-0.724-1.962-1.117-4.087-1.159-6.287h5.251V27.956z
M21.21,21.351
+
h-5.25c0.046-2.195,0.447-4.324,1.191-6.298c1.321,0.302,2.681,0.471,4.059,0.498V21.351z
M21.21,14.75
+
c-1.27-0.026-2.522-0.177-3.742-0.446c0.643-1.498,1.482-2.893,2.505-4.152c0.406-0.057,0.818-0.093,1.237-0.108V14.75z"/>
+ <circle fill="#C9E8FB" cx="30.292" cy="15.199" r="1.12"/>
+ <circle fill="#C9E8FB" cx="28.436" cy="9.193" r="1.12"/>
+ <circle fill="#C9E8FB" cx="27.386" cy="21.792" r="1.12"/>
+ <path fill="#0E3A5A"
d="M6.206,4.916V4.27c0-0.748-0.388-1.203-1.397-1.203H3v4.68h0.778V6.126h0.943l1.117,1.621h0.908
+ L5.551,6.012C6.025,5.825,6.206,5.435,6.206,4.916z
M5.428,4.923c0,0.363-0.122,0.492-0.64,0.492h-1.01v-1.63h1.01
+ c0.519,0,0.64,0.124,0.64,0.492V4.923z"/>
+ <polygon fill="#0E3A5A" points="10.094,7.029 8.029,7.029 8.029,5.709
9.939,5.709 9.939,4.991 8.029,4.991 8.029,3.785
+ 10.087,3.785 10.087,3.067 7.251,3.067 7.251,7.747 10.094,7.747
"/>
+ <path fill="#0E3A5A"
d="M12.159,7.103c-0.399,0-0.82-0.066-1.221-0.19L10.832,6.88L10.7,7.541l0.077,0.03
+
c0.397,0.161,0.929,0.243,1.368,0.243c1.285,0,1.561-0.487,1.561-1.324c0-0.929-0.101-1.138-1.327-1.442
+
c-0.459-0.114-0.644-0.171-0.73-0.258c-0.035-0.036-0.057-0.082-0.069-0.162c-0.013-0.089-0.013-0.202-0.013-0.351
+
c0-0.444,0.069-0.565,0.768-0.565c0.363,0,0.778,0.046,1.128,0.125l0.111,0.025l0.066-0.689l-0.082-0.021
+
C13.191,3.055,12.719,3,12.321,3c-1.152,0-1.533,0.409-1.533,1.257c0,0.979,0.165,1.226,1.289,1.477
+
c0.474,0.107,0.67,0.169,0.762,0.259c0.038,0.038,0.062,0.086,0.074,0.166c0.015,0.089,0.014,0.201,0.014,0.346
+ C12.927,6.947,12.837,7.103,12.159,7.103z"/>
+ <polygon fill="#0E3A5A" points="15.416,7.747 16.194,7.747 16.194,3.785
17.532,3.785 17.532,3.067 14.077,3.067 14.077,3.785
+ 15.416,3.785 "/>
+ <path fill="#FF9C04"
d="M38.809,30.162l-0.376-0.376c-0.777-0.778-1.812-1.207-2.912-1.207c-1.027,0-1.989,0.387-2.747,1.071
+
c-0.003-0.002-0.006-0.004-0.008-0.007l-2.052,2.053c-1.149,1.198-1.437,2.921-0.853,4.379l1.414-1.414
+
c-0.033-0.659,0.193-1.329,0.696-1.832l0.67-0.671c0,0,0,0.001,0,0.001l1.264-1.264l0.008,0.008
+
c0.444-0.398,1.007-0.625,1.608-0.625c0.646,0,1.254,0.252,1.71,0.708l0.376,0.376c0.942,0.943,0.942,2.478,0,3.421l-1.842,1.842
+
c-0.694,0.692-1.777,0.855-2.658,0.499l-1.26,1.26c0.654,0.418,1.412,0.649,2.208,0.649c1.1,0,2.134-0.429,2.911-1.207l1.842-1.842
+ C40.414,34.38,40.414,31.768,38.809,30.162z"/>
+ <path fill="#FF9C04"
d="M32.992,36.307l0.321-0.322c1.204-1.203,1.505-2.972,0.905-4.458l-1.412,1.413
+
c0.031,0.551-0.125,1.104-0.468,1.568l0.017,0.017l-0.169,0.169c-0.026,0.029-0.045,0.062-0.074,0.09l-0.671,0.671
+
c-0.002-0.004-0.003-0.008-0.005-0.012l-1.379,1.379l-0.032,0.001c-0.934,0.699-2.339,0.639-3.175-0.197l-0.376-0.376
+
c-0.942-0.943-0.942-2.477,0.001-3.42l1.841-1.843c0.457-0.456,1.064-0.708,1.71-0.708c0.335,0,0.659,0.071,0.958,0.2l1.25-1.25
+
c-0.654-0.419-1.413-0.65-2.208-0.65c-1.1,0-2.134,0.429-2.912,1.207l-1.841,1.843c-1.605,1.605-1.605,4.217-0.001,5.822
+
l0.376,0.376c0.777,0.778,1.812,1.207,2.912,1.207c1.027,0,1.989-0.387,2.747-1.072c0.003,0.003,0.006,0.005,0.009,0.008
+ l1.672-1.671L32.992,36.307z"/>
+ </g>
+</svg>
diff --git
a/docs/hop-user-manual/modules/ROOT/pages/metadata-types/rest-connection.adoc
b/docs/hop-user-manual/modules/ROOT/pages/metadata-types/rest-connection.adoc
new file mode 100644
index 0000000000..95b1bfbe2d
--- /dev/null
+++
b/docs/hop-user-manual/modules/ROOT/pages/metadata-types/rest-connection.adoc
@@ -0,0 +1,49 @@
+////
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+////
+:page-pagination:
+:description:
+
+= REST connection
+
+image:icons/rest.svg[]
+
+A REST connection is a connection to a REST api that can be reused from
transforms like the xref:pipeline/transforms/rest.adoc[REST client].
+
+The REST connection is a generic purpose metadata item. A transform or action
that uses a REST connection can override its properties when required.
+
+== Related Plugins
+
+xref:pipeline/transforms/rest.adoc[REST client]
+
+== Options
+
+[options="header"]
+|===
+|Option |Description
+|Name|The name to be used for this REST connection
+|Base URL|The URL to use as the base URL for any API calls. The base URL will
need to be appended from client transforms or actions that use it to make
detailed API calls.
+|Test URL|A full URL that can be used to test this REST connection. If no test
URL is specified, the base URL will be used to perform connection tests.
+|Authorization header name|The Authentication/Authorization header name to use
for the connection.
+|Authorization prefix|An (optional) prefix to use for the
authentication/authorization header value (e.g. `Bearer`)
+|Authorization value|The Authentication/Authorization header value to use for
the connection. This could be a token, an API key etc.
+|===
+
+Use the `Test` button to authenticate against the test or base URL, using the
authentication/authorization header name, and (prefix + ) value.
+
+== Samples
+
+None
\ No newline at end of file
diff --git
a/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms/rest.adoc
b/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms/rest.adoc
index 71e26caafa..8fbc4a4f34 100644
--- a/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms/rest.adoc
+++ b/docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms/rest.adoc
@@ -27,6 +27,11 @@ under the License.
The REST Client transform enables you to consume RESTfull services.
Representational State Transfer (REST) is a key design idiom that embraces a
stateless client-server architecture in which the web services are viewed as
resources and can be identified by their URLs.
+The REST client transform can use a pre-defined
xref:metadata-types/rest-connection.adoc[REST connection] or use full URLs
directly. +
+When using a REST connection, the URL (hard-coded or accepted from a field)
will be considered a path relative to the base URL defined in the REST
connection. Header values that are specified in the `Headers` tab of the
transform will overwrite any headers with the same name that were defined in
the REST connection.
+
+When used without a REST connection, the full URL needs to be specified.
+
== Example
The REST client Transform returns a "result" field (can change the name), and
the field is often used in the next transform. For example, it can be read in
by a JSON input transform that extracts the fields specified on the Fields tab.
@@ -52,6 +57,7 @@ The General tab is where you enter basic connection
information for accessing a
|===
|Option|Description
|Transform name|Name of this transform as it appears in the pipeline workspace
+|REST Connection|The (optional) xref:metadata-types/rest-connection.adoc[REST
connection] to use for the base URL and authentication/authorization header
name and value.
|URL|Indicates the path to a resource
|Accept URL from field|Designates the path to a resource is defined from a
field
|URL field name|Indicates the field from which the path to a resource is
defined
diff --git a/plugins/misc/pom.xml b/plugins/misc/pom.xml
index 3e0624b55c..727436f0fe 100644
--- a/plugins/misc/pom.xml
+++ b/plugins/misc/pom.xml
@@ -36,6 +36,7 @@
<module>passwords</module>
<module>projects</module>
<module>reflection</module>
+ <module>rest</module>
<module>static-schema</module>
<module>testing</module>
</modules>
diff --git a/plugins/transforms/rest/pom.xml b/plugins/misc/rest/pom.xml
similarity index 74%
copy from plugins/transforms/rest/pom.xml
copy to plugins/misc/rest/pom.xml
index 55116f56d9..5a7e01d37b 100644
--- a/plugins/transforms/rest/pom.xml
+++ b/plugins/misc/rest/pom.xml
@@ -14,27 +14,21 @@
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
- ~
-->
<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">
<modelVersion>4.0.0</modelVersion>
-
<parent>
<groupId>org.apache.hop</groupId>
- <artifactId>hop-plugins-transforms</artifactId>
+ <artifactId>hop-plugins-misc</artifactId>
<version>2.11.0-SNAPSHOT</version>
</parent>
- <artifactId>hop-transform-rest</artifactId>
- <packaging>jar</packaging>
- <name>Hop Plugins Transforms REST</name>
+ <artifactId>hop-misc-rest</artifactId>
- <dependencies>
- <dependency>
- <groupId>org.glassfish.jersey.connectors</groupId>
- <artifactId>jersey-apache-connector</artifactId>
- <version>2.43</version>
- </dependency>
- </dependencies>
+ <properties>
+ <maven.compiler.source>17</maven.compiler.source>
+ <maven.compiler.target>17</maven.compiler.target>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
</project>
diff --git a/plugins/transforms/rest/src/assembly/assembly.xml
b/plugins/misc/rest/src/assembly/assembly.xml
similarity index 76%
copy from plugins/transforms/rest/src/assembly/assembly.xml
copy to plugins/misc/rest/src/assembly/assembly.xml
index f3a0852411..be7799c494 100644
--- a/plugins/transforms/rest/src/assembly/assembly.xml
+++ b/plugins/misc/rest/src/assembly/assembly.xml
@@ -13,12 +13,14 @@
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
+ ~
-->
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.2.0
http://maven.apache.org/xsd/assembly-2.2.0.xsd">
- <id>hop-transform-rest</id>
+
+ <id>hop-misc-rest</id>
<formats>
<format>zip</format>
</formats>
@@ -26,7 +28,7 @@
<files>
<file>
<source>${project.basedir}/src/main/resources/version.xml</source>
- <outputDirectory>plugins/transforms/rest</outputDirectory>
+ <outputDirectory>plugins/misc/rest</outputDirectory>
<filtered>true</filtered>
</file>
</files>
@@ -41,15 +43,9 @@
<dependencySets>
<dependencySet>
<includes>
- <include>org.apache.hop:hop-transform-rest:jar</include>
- </includes>
- <outputDirectory>plugins/transforms/rest</outputDirectory>
- </dependencySet>
- <dependencySet>
- <includes>
-
<include>org.glassfish.jersey.connectors:jersey-apache-connector:jar</include>
+ <include>org.apache.hop:hop-misc-rest:jar</include>
</includes>
- <outputDirectory>plugins/transforms/rest/lib</outputDirectory>
+ <outputDirectory>plugins/misc/rest</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>
\ No newline at end of file
diff --git
a/plugins/misc/rest/src/main/java/org/apache/hop/metadata/rest/RestConnection.java
b/plugins/misc/rest/src/main/java/org/apache/hop/metadata/rest/RestConnection.java
new file mode 100644
index 0000000000..124428eb13
--- /dev/null
+++
b/plugins/misc/rest/src/main/java/org/apache/hop/metadata/rest/RestConnection.java
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.metadata.rest;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+import org.apache.commons.lang.StringUtils;
+import org.apache.hop.core.exception.HopException;
+import org.apache.hop.metadata.api.HopMetadata;
+import org.apache.hop.metadata.api.HopMetadataBase;
+import org.apache.hop.metadata.api.HopMetadataProperty;
+import org.apache.hop.metadata.api.IHopMetadata;
+
+@HopMetadata(
+ key = "restconnection",
+ name = "i18n::RestConnection.name",
+ description = "i18n::RestConnection.description",
+ image = "rest.svg",
+ documentationUrl = "/metadata-types/rest-connection.html")
+public class RestConnection extends HopMetadataBase implements IHopMetadata {
+
+ private ClientBuilder builder;
+ private Client client;
+
+ @HopMetadataProperty(key = "base_url", injectionKey = "BASE_URL")
+ private String baseUrl;
+
+ @HopMetadataProperty(key = "test_url", injectionKey = "TEST_URL")
+ private String testUrl;
+
+ @HopMetadataProperty(key = "auth_header_name", injectionKey =
"AUTH_HEADER_NAME")
+ private String authorizationHeaderName;
+
+ @HopMetadataProperty(key = "auth_header_prefix", injectionKey =
"AUTH_HEADER_PREFIX")
+ private String authorizationPrefix;
+
+ @HopMetadataProperty(key = "auth_header_value", injectionKey =
"AUTH_HEADER_VALUE")
+ private String authorizationHeaderValue;
+
+ public RestConnection() {
+ builder = ClientBuilder.newBuilder();
+ client = builder.build();
+ }
+
+ public String getResponse(String url) throws HopException {
+ WebTarget target = client.target(testUrl);
+ Invocation.Builder invocationBuilder = target.request();
+ if (!StringUtils.isEmpty(authorizationPrefix)) {
+ invocationBuilder.header(
+ authorizationHeaderName, authorizationPrefix + " " +
authorizationHeaderValue);
+ } else {
+ invocationBuilder.header(authorizationHeaderName,
authorizationHeaderValue);
+ }
+ Response response = invocationBuilder.get();
+
+ if (response.getStatus() != Response.Status.OK.getStatusCode()) {
+ throw new HopException("Error connecting to " + testUrl + ": " +
response.getStatus());
+ }
+ return response.readEntity(String.class);
+ }
+
+ public void disconnect() throws HopException {
+ client.close();
+ }
+
+ public void testConnection() throws HopException {
+ WebTarget target = client.target(testUrl);
+ Invocation.Builder invocationBuilder = target.request();
+ if (!StringUtils.isEmpty(authorizationPrefix)) {
+ invocationBuilder.header(
+ authorizationHeaderName, authorizationPrefix + " " +
authorizationHeaderValue);
+ } else {
+ invocationBuilder.header(authorizationHeaderName,
authorizationHeaderValue);
+ }
+ Response response = invocationBuilder.get();
+ if (response.getStatus() != Response.Status.OK.getStatusCode()) {
+ throw new HopException("Error connecting to " + testUrl + ": " +
response.getStatus());
+ }
+ response.close();
+ }
+
+ public RestConnection(RestConnection connection) {
+ this.baseUrl = connection.baseUrl;
+ }
+
+ @Override
+ public String toString() {
+ return name == null ? super.toString() : name;
+ }
+
+ @Override
+ public int hashCode() {
+ return name == null ? super.hashCode() : name.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object object) {
+
+ if (object == this) {
+ return true;
+ }
+ if (!(object instanceof RestConnection)) {
+ return false;
+ }
+
+ RestConnection connection = (RestConnection) object;
+
+ return name != null && name.equalsIgnoreCase(connection.name);
+ }
+
+ /**
+ * Gets name
+ *
+ * @return value of name
+ */
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name The name to set
+ */
+ @Override
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getBaseUrl() {
+ return baseUrl;
+ }
+
+ public void setBaseUrl(String baseUrl) {
+ this.baseUrl = baseUrl;
+ }
+
+ public String getTestUrl() {
+ return testUrl;
+ }
+
+ public void setTestUrl(String testUrl) {
+ this.testUrl = testUrl;
+ }
+
+ public String getAuthorizationHeaderName() {
+ return authorizationHeaderName;
+ }
+
+ public void setAuthorizationHeaderName(String authorizationHeaderName) {
+ this.authorizationHeaderName = authorizationHeaderName;
+ }
+
+ public String getAuthHeaderPrefix() {
+ return authorizationPrefix;
+ }
+
+ public void setAuthHeaderPrefix(String authHeaderPrefix) {
+ this.authorizationPrefix = authHeaderPrefix;
+ }
+
+ public String getAuthorizationHeaderValue() {
+ return authorizationHeaderValue;
+ }
+
+ public void setAuthorizationHeaderValue(String authorizationHeaderValue) {
+ this.authorizationHeaderValue = authorizationHeaderValue;
+ }
+}
diff --git
a/plugins/misc/rest/src/main/java/org/apache/hop/metadata/rest/RestConnectionEditor.java
b/plugins/misc/rest/src/main/java/org/apache/hop/metadata/rest/RestConnectionEditor.java
new file mode 100644
index 0000000000..fd14bd28a9
--- /dev/null
+++
b/plugins/misc/rest/src/main/java/org/apache/hop/metadata/rest/RestConnectionEditor.java
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.metadata.rest;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.hop.core.Const;
+import org.apache.hop.core.variables.IVariables;
+import org.apache.hop.i18n.BaseMessages;
+import org.apache.hop.ui.core.PropsUi;
+import org.apache.hop.ui.core.dialog.ErrorDialog;
+import org.apache.hop.ui.core.dialog.MessageBox;
+import org.apache.hop.ui.core.metadata.MetadataEditor;
+import org.apache.hop.ui.core.metadata.MetadataManager;
+import org.apache.hop.ui.core.widget.PasswordTextVar;
+import org.apache.hop.ui.core.widget.TextVar;
+import org.apache.hop.ui.hopgui.HopGui;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class RestConnectionEditor extends MetadataEditor<RestConnection> {
+ private static final Class<?> PKG = RestConnectionEditor.class;
+
+ private Text wName;
+
+ private TextVar wBaseUrl;
+ private TextVar wTestUrl;
+ private TextVar wAuthorizationName;
+ private TextVar wAuthorizationPrefix;
+ private PasswordTextVar wAuthorizationValue;
+
+ public RestConnectionEditor(
+ HopGui hopGui, MetadataManager<RestConnection> manager, RestConnection
restConnection) {
+ super(hopGui, manager, restConnection);
+ }
+
+ @Override
+ public void createControl(Composite composite) {
+ PropsUi props = PropsUi.getInstance();
+
+ int middle = props.getMiddlePct();
+ int margin = props.getMargin();
+
+ IVariables variables = hopGui.getVariables();
+
+ // The name
+ Label wlName = new Label(composite, SWT.RIGHT);
+ PropsUi.setLook(wlName);
+ wlName.setText(BaseMessages.getString(PKG, "RestConnectionEditor.Name"));
+ FormData fdlName = new FormData();
+ fdlName.top = new FormAttachment(0, margin);
+ fdlName.left = new FormAttachment(0, 0); // First one in the left top
corner
+ fdlName.right = new FormAttachment(middle, -margin);
+ wlName.setLayoutData(fdlName);
+ wName = new Text(composite, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
+ PropsUi.setLook(wName);
+ FormData fdName = new FormData();
+ fdName.top = new FormAttachment(wlName, 0, SWT.CENTER);
+ fdName.left = new FormAttachment(middle, 0); // To the right of the label
+ fdName.right = new FormAttachment(95, 0);
+ wName.setLayoutData(fdName);
+ Control lastControl = wName;
+
+ Label wlBaseUrl = new Label(composite, SWT.RIGHT);
+ PropsUi.setLook(wlBaseUrl);
+ wlBaseUrl.setText(BaseMessages.getString(PKG,
"RestConnectionEditor.BaseUrl"));
+ FormData fdlBaseUrl = new FormData();
+ fdlBaseUrl.top = new FormAttachment(lastControl, margin);
+ fdlBaseUrl.left = new FormAttachment(0, 0);
+ fdlBaseUrl.right = new FormAttachment(middle, -margin);
+ wlBaseUrl.setLayoutData(fdlBaseUrl);
+ wBaseUrl = new TextVar(variables, composite, SWT.SINGLE | SWT.LEFT);
+ PropsUi.setLook(wBaseUrl);
+ FormData fdBaseUrl = new FormData();
+ fdBaseUrl.top = new FormAttachment(wlBaseUrl, 0, SWT.CENTER);
+ fdBaseUrl.left = new FormAttachment(middle, 0);
+ fdBaseUrl.right = new FormAttachment(95, 0);
+ wBaseUrl.setLayoutData(fdBaseUrl);
+ lastControl = wBaseUrl;
+
+ Label wlTestUrl = new Label(composite, SWT.RIGHT);
+ PropsUi.setLook(wlTestUrl);
+ wlTestUrl.setText(BaseMessages.getString(PKG,
"RestConnectionEditor.TestUrl"));
+ FormData fdlTestUrl = new FormData();
+ fdlTestUrl.top = new FormAttachment(lastControl, margin);
+ fdlTestUrl.left = new FormAttachment(0, 0);
+ fdlTestUrl.right = new FormAttachment(middle, -margin);
+ wlTestUrl.setLayoutData(fdlTestUrl);
+ wTestUrl = new TextVar(variables, composite, SWT.SINGLE | SWT.LEFT);
+ PropsUi.setLook(wTestUrl);
+ FormData fdTestUrl = new FormData();
+ fdTestUrl.top = new FormAttachment(wlTestUrl, 0, SWT.CENTER);
+ fdTestUrl.left = new FormAttachment(middle, 0);
+ fdTestUrl.right = new FormAttachment(95, 0);
+ wTestUrl.setLayoutData(fdTestUrl);
+ lastControl = wTestUrl;
+
+ Label wlAuthorizationName = new Label(composite, SWT.RIGHT);
+ PropsUi.setLook(wlAuthorizationName);
+ wlAuthorizationName.setText(
+ BaseMessages.getString(PKG, "RestConnectionEditor.AuthorizationName"));
+ FormData fdlAuthorizationName = new FormData();
+ fdlAuthorizationName.top = new FormAttachment(lastControl, margin);
+ fdlAuthorizationName.left = new FormAttachment(0, 0);
+ fdlAuthorizationName.right = new FormAttachment(middle, -margin);
+ wlAuthorizationName.setLayoutData(fdlAuthorizationName);
+ wAuthorizationName = new TextVar(variables, composite, SWT.SINGLE |
SWT.LEFT);
+ PropsUi.setLook(wAuthorizationName);
+ FormData fdAuthorizationName = new FormData();
+ fdAuthorizationName.top = new FormAttachment(wlAuthorizationName, 0,
SWT.CENTER);
+ fdAuthorizationName.left = new FormAttachment(middle, 0);
+ fdAuthorizationName.right = new FormAttachment(95, 0);
+ wAuthorizationName.setLayoutData(fdAuthorizationName);
+ lastControl = wAuthorizationName;
+
+ Label wlAuthorizationPrefix = new Label(composite, SWT.RIGHT);
+ PropsUi.setLook(wlAuthorizationPrefix);
+ wlAuthorizationPrefix.setText(
+ BaseMessages.getString(PKG,
"RestConnectionEditor.AuthorizationPrefix"));
+ FormData fdlAuthorizationPrefix = new FormData();
+ fdlAuthorizationPrefix.top = new FormAttachment(lastControl, margin);
+ fdlAuthorizationPrefix.left = new FormAttachment(0, 0);
+ fdlAuthorizationPrefix.right = new FormAttachment(middle, -margin);
+ wlAuthorizationPrefix.setLayoutData(fdlAuthorizationPrefix);
+
+ wAuthorizationPrefix = new TextVar(variables, composite, SWT.SINGLE |
SWT.LEFT);
+ PropsUi.setLook(wAuthorizationPrefix);
+ FormData fdAuthorizationPrefix = new FormData();
+ fdAuthorizationPrefix.top = new FormAttachment(wlAuthorizationPrefix, 0,
SWT.CENTER);
+ fdAuthorizationPrefix.left = new FormAttachment(middle, 0);
+ fdAuthorizationPrefix.right = new FormAttachment(95, 0);
+ wAuthorizationPrefix.setLayoutData(fdAuthorizationPrefix);
+ lastControl = wAuthorizationPrefix;
+
+ Label wlAuthorizationValue = new Label(composite, SWT.RIGHT);
+ PropsUi.setLook(wlAuthorizationValue);
+ wlAuthorizationValue.setText(
+ BaseMessages.getString(PKG,
"RestConnectionEditor.AuthorizationValue"));
+ FormData fdlAuthorizationValue = new FormData();
+ fdlAuthorizationValue.top = new FormAttachment(lastControl, margin);
+ fdlAuthorizationValue.left = new FormAttachment(0, 0);
+ fdlAuthorizationValue.right = new FormAttachment(middle, -margin);
+ wlAuthorizationValue.setLayoutData(fdlAuthorizationValue);
+ wAuthorizationValue = new PasswordTextVar(variables, composite, SWT.SINGLE
| SWT.LEFT);
+ PropsUi.setLook(wAuthorizationValue);
+ FormData fdAuthorizationValue = new FormData();
+ fdAuthorizationValue.top = new FormAttachment(wlAuthorizationValue, 0,
SWT.CENTER);
+ fdAuthorizationValue.left = new FormAttachment(middle, 0);
+ fdAuthorizationValue.right = new FormAttachment(95, 0);
+ wAuthorizationValue.setLayoutData(fdAuthorizationValue);
+ lastControl = wAuthorizationValue;
+
+ setWidgetsContent();
+
+ Control[] controls = {wName, wAuthorizationName, wAuthorizationValue,
wBaseUrl, wTestUrl};
+ for (Control control : controls) {
+ control.addListener(SWT.Modify, e -> setChanged());
+ control.addListener(SWT.Selection, e -> setChanged());
+ }
+ }
+
+ @Override
+ public Button[] createButtonsForButtonBar(Composite composite) {
+ Button wTest = new Button(composite, SWT.PUSH);
+ wTest.setText(BaseMessages.getString(PKG, "System.Button.Test"));
+ wTest.addListener(SWT.Selection, e -> test());
+
+ return new Button[] {wTest};
+ }
+
+ private void test() {
+ IVariables variables = hopGui.getVariables();
+ RestConnection restConnection = new RestConnection();
+ restConnection.setName(wName.getText());
+ if (StringUtils.isEmpty(wTestUrl.getText())) {
+ restConnection.setTestUrl(wBaseUrl.getText());
+ }
+ restConnection.setBaseUrl(wBaseUrl.getText());
+ restConnection.setTestUrl(wTestUrl.getText());
+ restConnection.setAuthorizationHeaderName(wAuthorizationName.getText());
+ restConnection.setAuthHeaderPrefix(wAuthorizationPrefix.getText());
+ restConnection.setAuthorizationHeaderValue(wAuthorizationValue.getText());
+ try {
+ restConnection.testConnection();
+ MessageBox box = new MessageBox(hopGui.getShell(), SWT.OK);
+ box.setText("OK");
+ String message =
+ BaseMessages.getString(PKG,
"RestConnectionEditor.ConnectionTestSuccess") + Const.CR;
+ message += Const.CR;
+ message += "URL : " + wTestUrl.getText();
+ box.setMessage(message);
+ box.open();
+ } catch (Exception e) {
+ new ErrorDialog(
+ hopGui.getShell(), "Error", "Error connecting to REST URL : " +
wTestUrl.getText(), e);
+ }
+ }
+
+ @Override
+ public void dispose() {}
+
+ @Override
+ public void setWidgetsContent() {
+ wName.setText(Const.NVL(metadata.getName(), ""));
+ wBaseUrl.setText(Const.NVL(metadata.getBaseUrl(), ""));
+ wTestUrl.setText(Const.NVL(metadata.getTestUrl(), ""));
+
wAuthorizationName.setText(Const.NVL(metadata.getAuthorizationHeaderName(),
""));
+ wAuthorizationPrefix.setText(Const.NVL(metadata.getAuthHeaderPrefix(),
""));
+
wAuthorizationValue.setText(Const.NVL(metadata.getAuthorizationHeaderValue(),
""));
+ }
+
+ @Override
+ public void getWidgetsContent(RestConnection connection) {
+ connection.setName(wName.getText());
+ connection.setBaseUrl(wBaseUrl.getText());
+ connection.setTestUrl(wTestUrl.getText());
+ connection.setAuthorizationHeaderName(wAuthorizationName.getText());
+ connection.setAuthHeaderPrefix(wAuthorizationPrefix.getText());
+ connection.setAuthorizationHeaderValue(wAuthorizationValue.getText());
+ }
+
+ @Override
+ public boolean setFocus() {
+ if (wName == null || wName.isDisposed()) {
+ return false;
+ }
+ return wName.setFocus();
+ }
+}
diff --git
a/plugins/misc/rest/src/main/resources/org/apache/hop/metadata/rest/messages/messages_en_US.properties
b/plugins/misc/rest/src/main/resources/org/apache/hop/metadata/rest/messages/messages_en_US.properties
new file mode 100644
index 0000000000..762152f1b2
--- /dev/null
+++
b/plugins/misc/rest/src/main/resources/org/apache/hop/metadata/rest/messages/messages_en_US.properties
@@ -0,0 +1,26 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+RestConnection.name=Rest Connection
+RestConnection.description=Connects to a REST API
+RestConnectionEditor.Name=REST Connection name
+RestConnectionEditor.BaseUrl=Base URL
+RestConnectionEditor.TestUrl=Test URL
+RestConnectionEditor.AuthorizationName=Authorization header name
+RestConnectionEditor.AuthorizationValue=Authorization header value
+RestConnectionEditor.AuthorizationPrefix=Authorization prefix
+RestConnectionEditor.ConnectionTestSuccess=Successfully connected to
\ No newline at end of file
diff --git a/plugins/misc/rest/src/main/resources/rest.svg
b/plugins/misc/rest/src/main/resources/rest.svg
new file mode 100644
index 0000000000..a894773268
--- /dev/null
+++ b/plugins/misc/rest/src/main/resources/rest.svg
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 17.0.0, SVG Export Plug-In . SVG Version:
6.00 Build 0) -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px"
+ width="42px" height="42px" viewBox="0 0 42 42" enable-background="new 0 0
42 42">
+ <g>
+ <path fill="none"
+
d="M4.788,3.785h-1.01v1.63h1.01c0.518,0,0.64-0.129,0.64-0.492V4.277C5.428,3.909,5.307,3.785,4.788,3.785z"/>
+ <path fill="#C9E8FB"
d="M16.364,14.859c-1.113-0.303-2.195-0.699-3.229-1.193c-1.923,2.015-3.131,4.709-3.232,7.684h5.256
+ C15.205,19.092,15.608,16.897,16.364,14.859z"/>
+ <path fill="#C9E8FB"
d="M18.76,10.388c-1.892,0.475-3.6,1.407-5.003,2.677c0.939,0.429,1.916,0.783,2.921,1.052
+ C17.234,12.796,17.921,11.54,18.76,10.388z"/>
+ <path fill="#C9E8FB"
d="M17.118,28.438c1.329-0.296,2.702-0.458,4.092-0.482v-5.804h-5.251
+ C16.001,24.351,16.394,26.476,17.118,28.438z"/>
+ <path fill="#C9E8FB"
+
d="M15.96,21.351h5.25v-5.8c-1.378-0.027-2.738-0.196-4.059-0.498C16.407,17.027,16.006,19.156,15.96,21.351z"
+ />
+ <path fill="#C9E8FB"
d="M15.158,22.151H9.903c0.101,2.962,1.299,5.645,3.208,7.657c1.026-0.484,2.105-0.877,3.223-1.175
+ C15.596,26.607,15.201,24.415,15.158,22.151z"/>
+ <path fill="#C9E8FB"
d="M13.723,30.405c1.394,1.271,3.09,2.208,4.972,2.692c-0.828-1.142-1.507-2.394-2.054-3.717
+ C15.632,29.642,14.655,29.984,13.723,30.405z"/>
+ <path fill="#C9E8FB"
d="M17.468,14.304c1.219,0.269,2.472,0.42,3.742,0.446v-4.706c-0.418,0.014-0.831,0.051-1.237,0.108
+ C18.95,11.411,18.111,12.806,17.468,14.304z"/>
+ <path fill="#C9E8FB"
d="M19.906,33.34c0.428,0.063,0.862,0.103,1.304,0.118v-4.702c-1.285,0.024-2.553,0.17-3.783,0.435
+ C18.062,30.697,18.892,32.093,19.906,33.34z"/>
+ <path fill="#0E3A5A"
d="M27.386,23.713c1.059,0,1.921-0.861,1.921-1.92s-0.862-1.921-1.921-1.921c-0.906,0-1.663,0.633-1.863,1.479
+
h-3.512v-5.787h6.397c0.171,0.885,0.95,1.556,1.884,1.556c1.059,0,1.92-0.862,1.92-1.921s-0.861-1.92-1.92-1.92
+
c-0.908,0-1.668,0.636-1.866,1.484h-6.415v-4.739h4.702c0.311,0.642,0.963,1.09,1.723,1.09c1.059,0,1.921-0.862,1.921-1.921
+
s-0.862-1.92-1.921-1.92c-0.745,0-1.384,0.431-1.703,1.052H21.61c-7.403,0-13.427,6.023-13.427,13.427
+
c0,6.952,5.312,12.686,12.09,13.359l1.737-1.607V22.151h3.491C25.671,23.039,26.45,23.713,27.386,23.713z
M27.386,20.673
+
c0.618,0,1.12,0.502,1.12,1.12c0,0.617-0.502,1.119-1.12,1.119c-0.617,0-1.119-0.502-1.119-1.119
+ C26.267,21.175,26.769,20.673,27.386,20.673z
M30.292,14.079c0.617,0,1.119,0.502,1.119,1.119c0,0.618-0.502,1.12-1.119,1.12
+
c-0.618,0-1.12-0.502-1.12-1.12C29.172,14.581,29.674,14.079,30.292,14.079z
M28.436,8.073c0.618,0,1.12,0.502,1.12,1.119
+
c0,0.618-0.502,1.12-1.12,1.12c-0.617,0-1.119-0.502-1.119-1.12C27.316,8.575,27.818,8.073,28.436,8.073z
M18.76,10.388
+
c-0.839,1.152-1.526,2.408-2.082,3.729c-1.006-0.268-1.982-0.622-2.921-1.052C15.161,11.796,16.868,10.863,18.76,10.388z
+
M13.136,13.666c1.033,0.493,2.115,0.889,3.229,1.193c-0.756,2.038-1.16,4.233-1.205,6.491H9.903
+ C10.004,18.376,11.212,15.682,13.136,13.666z
M9.903,22.151h5.255c0.042,2.264,0.438,4.455,1.176,6.482
+
c-1.118,0.298-2.197,0.69-3.223,1.175C11.203,27.796,10.004,25.113,9.903,22.151z
M13.723,30.405
+
c0.933-0.421,1.909-0.762,2.918-1.025c0.546,1.323,1.226,2.575,2.054,3.717C16.813,32.613,15.116,31.676,13.723,30.405z
+
M21.21,33.458c-0.441-0.015-0.876-0.055-1.304-0.118c-1.015-1.248-1.845-2.643-2.479-4.149c1.23-0.265,2.498-0.411,3.783-0.435
+ V33.458z
M21.21,27.956c-1.39,0.025-2.763,0.186-4.092,0.482c-0.724-1.962-1.117-4.087-1.159-6.287h5.251V27.956z
M21.21,21.351
+
h-5.25c0.046-2.195,0.447-4.324,1.191-6.298c1.321,0.302,2.681,0.471,4.059,0.498V21.351z
M21.21,14.75
+
c-1.27-0.026-2.522-0.177-3.742-0.446c0.643-1.498,1.482-2.893,2.505-4.152c0.406-0.057,0.818-0.093,1.237-0.108V14.75z"/>
+ <circle fill="#C9E8FB" cx="30.292" cy="15.199" r="1.12"/>
+ <circle fill="#C9E8FB" cx="28.436" cy="9.193" r="1.12"/>
+ <circle fill="#C9E8FB" cx="27.386" cy="21.792" r="1.12"/>
+ <path fill="#0E3A5A"
d="M6.206,4.916V4.27c0-0.748-0.388-1.203-1.397-1.203H3v4.68h0.778V6.126h0.943l1.117,1.621h0.908
+ L5.551,6.012C6.025,5.825,6.206,5.435,6.206,4.916z
M5.428,4.923c0,0.363-0.122,0.492-0.64,0.492h-1.01v-1.63h1.01
+ c0.519,0,0.64,0.124,0.64,0.492V4.923z"/>
+ <polygon fill="#0E3A5A" points="10.094,7.029 8.029,7.029 8.029,5.709
9.939,5.709 9.939,4.991 8.029,4.991 8.029,3.785
+ 10.087,3.785 10.087,3.067 7.251,3.067 7.251,7.747 10.094,7.747
"/>
+ <path fill="#0E3A5A"
d="M12.159,7.103c-0.399,0-0.82-0.066-1.221-0.19L10.832,6.88L10.7,7.541l0.077,0.03
+
c0.397,0.161,0.929,0.243,1.368,0.243c1.285,0,1.561-0.487,1.561-1.324c0-0.929-0.101-1.138-1.327-1.442
+
c-0.459-0.114-0.644-0.171-0.73-0.258c-0.035-0.036-0.057-0.082-0.069-0.162c-0.013-0.089-0.013-0.202-0.013-0.351
+
c0-0.444,0.069-0.565,0.768-0.565c0.363,0,0.778,0.046,1.128,0.125l0.111,0.025l0.066-0.689l-0.082-0.021
+
C13.191,3.055,12.719,3,12.321,3c-1.152,0-1.533,0.409-1.533,1.257c0,0.979,0.165,1.226,1.289,1.477
+
c0.474,0.107,0.67,0.169,0.762,0.259c0.038,0.038,0.062,0.086,0.074,0.166c0.015,0.089,0.014,0.201,0.014,0.346
+ C12.927,6.947,12.837,7.103,12.159,7.103z"/>
+ <polygon fill="#0E3A5A" points="15.416,7.747 16.194,7.747 16.194,3.785
17.532,3.785 17.532,3.067 14.077,3.067 14.077,3.785
+ 15.416,3.785 "/>
+ <path fill="#FF9C04"
d="M38.809,30.162l-0.376-0.376c-0.777-0.778-1.812-1.207-2.912-1.207c-1.027,0-1.989,0.387-2.747,1.071
+
c-0.003-0.002-0.006-0.004-0.008-0.007l-2.052,2.053c-1.149,1.198-1.437,2.921-0.853,4.379l1.414-1.414
+
c-0.033-0.659,0.193-1.329,0.696-1.832l0.67-0.671c0,0,0,0.001,0,0.001l1.264-1.264l0.008,0.008
+
c0.444-0.398,1.007-0.625,1.608-0.625c0.646,0,1.254,0.252,1.71,0.708l0.376,0.376c0.942,0.943,0.942,2.478,0,3.421l-1.842,1.842
+
c-0.694,0.692-1.777,0.855-2.658,0.499l-1.26,1.26c0.654,0.418,1.412,0.649,2.208,0.649c1.1,0,2.134-0.429,2.911-1.207l1.842-1.842
+ C40.414,34.38,40.414,31.768,38.809,30.162z"/>
+ <path fill="#FF9C04"
d="M32.992,36.307l0.321-0.322c1.204-1.203,1.505-2.972,0.905-4.458l-1.412,1.413
+
c0.031,0.551-0.125,1.104-0.468,1.568l0.017,0.017l-0.169,0.169c-0.026,0.029-0.045,0.062-0.074,0.09l-0.671,0.671
+
c-0.002-0.004-0.003-0.008-0.005-0.012l-1.379,1.379l-0.032,0.001c-0.934,0.699-2.339,0.639-3.175-0.197l-0.376-0.376
+
c-0.942-0.943-0.942-2.477,0.001-3.42l1.841-1.843c0.457-0.456,1.064-0.708,1.71-0.708c0.335,0,0.659,0.071,0.958,0.2l1.25-1.25
+
c-0.654-0.419-1.413-0.65-2.208-0.65c-1.1,0-2.134,0.429-2.912,1.207l-1.841,1.843c-1.605,1.605-1.605,4.217-0.001,5.822
+
l0.376,0.376c0.777,0.778,1.812,1.207,2.912,1.207c1.027,0,1.989-0.387,2.747-1.072c0.003,0.003,0.006,0.005,0.009,0.008
+ l1.672-1.671L32.992,36.307z"/>
+ </g>
+</svg>
diff --git a/plugins/transforms/rest/pom.xml
b/plugins/misc/rest/src/main/resources/version.xml
similarity index 52%
copy from plugins/transforms/rest/pom.xml
copy to plugins/misc/rest/src/main/resources/version.xml
index 55116f56d9..6be576acae 100644
--- a/plugins/transforms/rest/pom.xml
+++ b/plugins/misc/rest/src/main/resources/version.xml
@@ -16,25 +16,5 @@
~ limitations under the License.
~
-->
-<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">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.hop</groupId>
- <artifactId>hop-plugins-transforms</artifactId>
- <version>2.11.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>hop-transform-rest</artifactId>
- <packaging>jar</packaging>
- <name>Hop Plugins Transforms REST</name>
-
- <dependencies>
- <dependency>
- <groupId>org.glassfish.jersey.connectors</groupId>
- <artifactId>jersey-apache-connector</artifactId>
- <version>2.43</version>
- </dependency>
- </dependencies>
-
-</project>
+<version>${project.version}</version>
\ No newline at end of file
diff --git
a/plugins/misc/rest/src/test/java/org/apache/hop/metadata/rest/RestTest.java
b/plugins/misc/rest/src/test/java/org/apache/hop/metadata/rest/RestTest.java
new file mode 100644
index 0000000000..25f4150f66
--- /dev/null
+++ b/plugins/misc/rest/src/test/java/org/apache/hop/metadata/rest/RestTest.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.metadata.rest;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+public class RestTest {
+
+ @Test
+ @Disabled
+ public void testRestConnection() {
+ RestConnection restConnection = new RestConnection();
+ restConnection.setBaseUrl("");
+ restConnection.setTestUrl("");
+ restConnection.setAuthorizationHeaderName("authorization");
+ restConnection.setAuthorizationHeaderValue("Bearer " + "");
+
+ assertDoesNotThrow(restConnection::testConnection);
+ }
+}
diff --git a/plugins/transforms/rest/pom.xml b/plugins/transforms/rest/pom.xml
index 55116f56d9..cb2ad8137e 100644
--- a/plugins/transforms/rest/pom.xml
+++ b/plugins/transforms/rest/pom.xml
@@ -30,6 +30,11 @@
<name>Hop Plugins Transforms REST</name>
<dependencies>
+ <dependency>
+ <groupId>org.apache.hop</groupId>
+ <artifactId>hop-misc-rest</artifactId>
+ <version>${version}</version>
+ </dependency>
<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-apache-connector</artifactId>
diff --git a/plugins/transforms/rest/src/assembly/assembly.xml
b/plugins/transforms/rest/src/assembly/assembly.xml
index f3a0852411..fc990d0ca8 100644
--- a/plugins/transforms/rest/src/assembly/assembly.xml
+++ b/plugins/transforms/rest/src/assembly/assembly.xml
@@ -29,6 +29,11 @@
<outputDirectory>plugins/transforms/rest</outputDirectory>
<filtered>true</filtered>
</file>
+ <file>
+
<source>${project.basedir}/src/main/resources/dependencies.xml</source>
+ <outputDirectory>plugins/transforms/rest</outputDirectory>
+ <filtered>true</filtered>
+ </file>
</files>
<fileSets>
diff --git
a/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/Rest.java
b/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/Rest.java
index d6be4a0a8a..6cd55b273a 100644
---
a/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/Rest.java
+++
b/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/Rest.java
@@ -43,6 +43,7 @@ import org.apache.hop.core.row.RowDataUtil;
import org.apache.hop.core.util.HttpClientManager;
import org.apache.hop.core.util.Utils;
import org.apache.hop.i18n.BaseMessages;
+import org.apache.hop.metadata.rest.RestConnection;
import org.apache.hop.pipeline.Pipeline;
import org.apache.hop.pipeline.PipelineMeta;
import org.apache.hop.pipeline.transform.BaseTransform;
@@ -60,6 +61,8 @@ public class Rest extends BaseTransform<RestMeta, RestData> {
private static final Class<?> PKG = RestMeta.class;
public static final String CONST_REST_EXCEPTION_ERROR_FINDING_FIELD =
"Rest.Exception.ErrorFindingField";
+ private String baseUrl = "";
+ private RestConnection connection;
public Rest(
TransformMeta transformMeta,
@@ -87,10 +90,16 @@ public class Rest extends BaseTransform<RestMeta, RestData>
{
*/
@SuppressWarnings("java:S5527")
protected Object[] callRest(Object[] rowData) throws HopException {
+
// get dynamic url ?
if (meta.isUrlInField()) {
- data.realUrl = data.inputRowMeta.getString(rowData,
data.indexOfUrlField);
+ if (!Utils.isEmpty(meta.getConnectionName())) {
+ data.realUrl = baseUrl + data.inputRowMeta.getString(rowData,
data.indexOfUrlField);
+ } else {
+ data.realUrl = data.inputRowMeta.getString(rowData,
data.indexOfUrlField);
+ }
}
+
// get dynamic method?
if (meta.isDynamicMethod()) {
data.method = data.inputRowMeta.getString(rowData, data.indexOfMethod);
@@ -162,6 +171,16 @@ public class Rest extends BaseTransform<RestMeta,
RestData> {
logDebug(BaseMessages.getString(PKG, "Rest.Log.ConnectingToURL",
webResource.getUri()));
}
Invocation.Builder invocationBuilder = webResource.request();
+
+ // set the Authentication/Authorization header from the connection
first, if available.
+ // this transform's headers will override this value if available.
+ if (connection != null) {
+ if (!Utils.isEmpty(connection.getAuthorizationHeaderName())) {
+ invocationBuilder.header(
+ connection.getAuthorizationHeaderName(),
connection.getAuthorizationHeaderValue());
+ }
+ }
+
String contentType = null; // media type override, if not null
if (data.useHeaders) {
// Add headers
@@ -408,7 +427,11 @@ public class Rest extends BaseTransform<RestMeta,
RestData> {
}
} else {
// Static URL
- data.realUrl = resolve(meta.getUrl());
+ if (!Utils.isEmpty(meta.getConnectionName())) {
+ data.realUrl = baseUrl + resolve(meta.getUrl());
+ } else {
+ data.realUrl = resolve(meta.getUrl());
+ }
}
// Check Method
if (meta.isDynamicMethod()) {
@@ -424,15 +447,14 @@ public class Rest extends BaseTransform<RestMeta,
RestData> {
}
}
// set Headers
- int nrargs = meta.getHeaderName() == null ? 0 :
meta.getHeaderName().length;
- if (nrargs > 0) {
- data.nrheader = nrargs;
- data.indexOfHeaderFields = new int[nrargs];
- data.headerNames = new String[nrargs];
- for (int i = 0; i < nrargs; i++) {
+ if (!Utils.isEmpty(meta.getHeaderFields())) {
+ data.nrheader = meta.getHeaderFields().size();
+ data.indexOfHeaderFields = new int[meta.getHeaderFields().size()];
+ data.headerNames = new String[meta.getHeaderFields().size()];
+ for (int i = 0; i < meta.getHeaderFields().size(); i++) {
// split into body / header
- data.headerNames[i] = resolve(meta.getHeaderName()[i]);
- String field = resolve(meta.getHeaderField()[i]);
+ data.headerNames[i] =
resolve(meta.getHeaderFields().get(i).getName());
+ String field =
resolve(meta.getHeaderFields().get(i).getHeaderField());
if (Utils.isEmpty(field)) {
throw new HopException(BaseMessages.getString(PKG,
"Rest.Exception.HeaderFieldEmpty"));
}
@@ -446,14 +468,14 @@ public class Rest extends BaseTransform<RestMeta,
RestData> {
}
if (RestMeta.isActiveParameters(meta.getMethod())) {
// Parameters
- int nrparams = meta.getParameterField() == null ? 0 :
meta.getParameterField().length;
+ int nrparams = meta.getParameterFields() != null ? 0 :
meta.getParameterFields().size();
if (nrparams > 0) {
data.nrParams = nrparams;
data.paramNames = new String[nrparams];
data.indexOfParamFields = new int[nrparams];
for (int i = 0; i < nrparams; i++) {
- data.paramNames[i] = resolve(meta.getParameterName()[i]);
- String field = resolve(meta.getParameterField()[i]);
+ data.paramNames[i] =
resolve(meta.getParameterFields().get(i).getName());
+ String field =
resolve(meta.getParameterFields().get(i).getHeaderField());
if (Utils.isEmpty(field)) {
throw new HopException(BaseMessages.getString(PKG,
"Rest.Exception.ParamFieldEmpty"));
}
@@ -466,14 +488,14 @@ public class Rest extends BaseTransform<RestMeta,
RestData> {
data.useParams = true;
}
int nrmatrixparams =
- meta.getMatrixParameterField() == null ? 0 :
meta.getMatrixParameterField().length;
+ meta.getMatrixParameterFields() == null ? 0 :
meta.getMatrixParameterFields().size();
if (nrmatrixparams > 0) {
data.nrMatrixParams = nrmatrixparams;
data.matrixParamNames = new String[nrmatrixparams];
data.indexOfMatrixParamFields = new int[nrmatrixparams];
for (int i = 0; i < nrmatrixparams; i++) {
- data.matrixParamNames[i] =
resolve(meta.getMatrixParameterName()[i]);
- String field = resolve(meta.getMatrixParameterField()[i]);
+ data.matrixParamNames[i] =
resolve(meta.getMatrixParameterFields().get(i).getName());
+ String field =
resolve(meta.getMatrixParameterFields().get(i).getHeaderField());
if (Utils.isEmpty(field)) {
throw new HopException(
BaseMessages.getString(PKG,
"Rest.Exception.MatrixParamFieldEmpty"));
@@ -533,10 +555,27 @@ public class Rest extends BaseTransform<RestMeta,
RestData> {
public boolean init() {
if (super.init()) {
- data.resultFieldName = resolve(meta.getFieldName());
- data.resultCodeFieldName = resolve(meta.getResultCodeFieldName());
- data.resultResponseFieldName = resolve(meta.getResponseTimeFieldName());
- data.resultHeaderFieldName = resolve(meta.getResponseHeaderFieldName());
+
+ // use the information from the selection line if we have one.
+ if (!Utils.isEmpty(meta.getConnectionName())) {
+ try {
+ for (RestConnection connection :
+ metadataProvider.getSerializer(RestConnection.class).loadAll()) {
+ if (connection.getName().equals(meta.getConnectionName())) {
+ this.connection = connection;
+ baseUrl = resolve(connection.getBaseUrl());
+ }
+ }
+ } catch (HopException e) {
+ throw new RuntimeException(
+ "REST connection " + meta.getConnectionName() + " could not be
found");
+ }
+ }
+
+ data.resultFieldName = resolve(meta.getResultField().getFieldName());
+ data.resultCodeFieldName = resolve(meta.getResultField().getCode());
+ data.resultResponseFieldName =
resolve(meta.getResultField().getResponseTime());
+ data.resultHeaderFieldName =
resolve(meta.getResultField().getResponseHeader());
data.realConnectionTimeout =
Const.toInt(resolve(meta.getConnectionTimeout()), -1);
data.realReadTimeout = Const.toInt(resolve(meta.getReadTimeout()), -1);
diff --git
a/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/RestData.java
b/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/RestData.java
index 4de6a6a4cd..9386a6a1ab 100644
---
a/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/RestData.java
+++
b/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/RestData.java
@@ -116,7 +116,7 @@ public class RestData extends BaseTransformData implements
ITransformData {
this.resultCodeFieldName = null;
this.resultResponseFieldName = null;
this.resultHeaderFieldName = null;
- this.nrheader = 0;
+ // this.nrheader = 0;
this.nrParams = 0;
this.nrMatrixParams = 0;
this.method = null;
diff --git
a/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/RestDialog.java
b/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/RestDialog.java
index 7a1c525319..dce39cf0ca 100644
---
a/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/RestDialog.java
+++
b/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/RestDialog.java
@@ -26,14 +26,19 @@ import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.core.util.Utils;
import org.apache.hop.core.variables.IVariables;
import org.apache.hop.i18n.BaseMessages;
+import org.apache.hop.metadata.rest.RestConnection;
import org.apache.hop.pipeline.PipelineMeta;
import org.apache.hop.pipeline.transform.TransformMeta;
+import org.apache.hop.pipeline.transforms.rest.fields.HeaderField;
+import org.apache.hop.pipeline.transforms.rest.fields.MatrixParameterField;
+import org.apache.hop.pipeline.transforms.rest.fields.ParameterField;
import org.apache.hop.ui.core.PropsUi;
import org.apache.hop.ui.core.dialog.BaseDialog;
import org.apache.hop.ui.core.dialog.ErrorDialog;
import org.apache.hop.ui.core.gui.GuiResource;
import org.apache.hop.ui.core.widget.ColumnInfo;
import org.apache.hop.ui.core.widget.ComboVar;
+import org.apache.hop.ui.core.widget.MetaSelectionLine;
import org.apache.hop.ui.core.widget.PasswordTextVar;
import org.apache.hop.ui.core.widget.TableView;
import org.apache.hop.ui.core.widget.TextVar;
@@ -59,12 +64,16 @@ import org.eclipse.swt.widgets.Text;
public class RestDialog extends BaseTransformDialog {
private static final Class<?> PKG = RestMeta.class;
+ public static final String CONST_ERROR = "Error";
+
private ComboVar wApplicationType;
private Label wlMethod;
+
private ComboVar wMethod;
private Label wlUrl;
+
private TextVar wUrl;
private TextVar wResult;
@@ -76,6 +85,7 @@ public class RestDialog extends BaseTransformDialog {
private Button wUrlInField;
private Label wlUrlField;
+
private ComboVar wUrlField;
private Button wMethodInField;
@@ -83,6 +93,7 @@ public class RestDialog extends BaseTransformDialog {
private Button wPreemptive;
private Label wlMethodField;
+
private ComboVar wMethodField;
private final RestMeta input;
@@ -90,9 +101,11 @@ public class RestDialog extends BaseTransformDialog {
private final List<String> inputFields = new ArrayList<>();
private Label wlBody;
+
private ComboVar wBody;
private ColumnInfo[] colinf;
+
private ColumnInfo[] colinfoparams;
private TextVar wConnectionTimeout;
@@ -108,11 +121,15 @@ public class RestDialog extends BaseTransformDialog {
private TextVar wProxyPort;
private Label wlParameters;
+
private Label wlMatrixParameters;
+
private TableView wParameters;
+
private TableView wMatrixParameters;
private TextVar wResponseTime;
+
private TextVar wResponseHeader;
private TextVar wTrustStorePassword;
@@ -125,6 +142,8 @@ public class RestDialog extends BaseTransformDialog {
private Button wMatrixGet;
+ private MetaSelectionLine wSelectionLine;
+
public RestDialog(
Shell parent, IVariables variables, RestMeta transformMeta, PipelineMeta
pipelineMeta) {
super(parent, variables, transformMeta, pipelineMeta);
@@ -180,6 +199,7 @@ public class RestDialog extends BaseTransformDialog {
Group gSettings = setupSettingGroup(wGeneralComp);
+ setupRestConnectionLine(lsMod, middle, margin, wGeneralComp, gSettings);
setupUrlLine(lsMod, middle, margin, wGeneralComp, gSettings);
setupUrlInFieldLine(middle, margin, gSettings);
setupUrlFieldNameLine(lsMod, middle, margin, gSettings);
@@ -449,7 +469,7 @@ public class RestDialog extends BaseTransformDialog {
fdMatrixGet.right = new FormAttachment(100, 0);
wMatrixGet.setLayoutData(fdMatrixGet);
- int matrixParametersRows = input.getMatrixParameterField().length;
+ int matrixParametersRows = input.getMatrixParameterFields().size();
colinfoparams =
new ColumnInfo[] {
@@ -514,7 +534,7 @@ public class RestDialog extends BaseTransformDialog {
fdGet.right = new FormAttachment(100, 0);
wGet.setLayoutData(fdGet);
- final int ParametersRows = input.getParameterField().length;
+ final int ParametersRows = input.getParameterFields().size();
colinfoparams =
new ColumnInfo[] {
@@ -566,7 +586,7 @@ public class RestDialog extends BaseTransformDialog {
fdGetHeaders.right = new FormAttachment(100, 0);
wGetHeaders.setLayoutData(fdGetHeaders);
- final int FieldsRows = input.getHeaderName().length;
+ final int FieldsRows = input.getHeaderFields().size();
colinf =
new ColumnInfo[] {
@@ -1174,15 +1194,42 @@ public class RestDialog extends BaseTransformDialog {
});
}
+ private void setupRestConnectionLine(
+ ModifyListener lsMod, int middle, int margin, Composite wGeneralComp,
Group gSettings) {
+
+ wSelectionLine =
+ new MetaSelectionLine(
+ variables,
+ metadataProvider,
+ RestConnection.class,
+ gSettings,
+ SWT.SINGLE | SWT.LEFT | SWT.BORDER,
+ "REST Connection",
+ "The name of the REST connection to use.");
+ PropsUi.setLook(wSelectionLine);
+ FormData fdSelectionLine = new FormData();
+ fdSelectionLine.left = new FormAttachment(0, 0);
+ fdSelectionLine.top = new FormAttachment(wGeneralComp, margin);
+ fdSelectionLine.right = new FormAttachment(100, -margin);
+ wSelectionLine.setLayoutData(fdSelectionLine);
+ wSelectionLine.addListener(SWT.Selection, e -> input.setChanged(true));
+ try {
+ wSelectionLine.fillItems();
+ } catch (Exception e) {
+ new ErrorDialog(shell, CONST_ERROR, "Error getting list of REST
connections", e);
+ }
+ }
+
private void setupUrlLine(
ModifyListener lsMod, int middle, int margin, Composite wGeneralComp,
Group gSettings) {
+
wlUrl = new Label(gSettings, SWT.RIGHT);
wlUrl.setText(BaseMessages.getString(PKG, "RestDialog.URL.Label"));
PropsUi.setLook(wlUrl);
FormData fdlUrl = new FormData();
fdlUrl.left = new FormAttachment(0, 0);
fdlUrl.right = new FormAttachment(middle, -margin);
- fdlUrl.top = new FormAttachment(wGeneralComp, margin * 2);
+ fdlUrl.top = new FormAttachment(wSelectionLine, margin * 2);
wlUrl.setLayoutData(fdlUrl);
wUrl = new TextVar(variables, gSettings, SWT.SINGLE | SWT.LEFT |
SWT.BORDER);
@@ -1190,7 +1237,7 @@ public class RestDialog extends BaseTransformDialog {
wUrl.addModifyListener(lsMod);
FormData fdUrl = new FormData();
fdUrl.left = new FormAttachment(middle, 0);
- fdUrl.top = new FormAttachment(wGeneralComp, margin * 2);
+ fdUrl.top = new FormAttachment(wSelectionLine, margin * 2);
fdUrl.right = new FormAttachment(100, 0);
wUrl.setLayoutData(fdUrl);
}
@@ -1302,38 +1349,42 @@ public class RestDialog extends BaseTransformDialog {
logDebug(BaseMessages.getString(PKG, "RestDialog.Log.GettingKeyInfo"));
}
- if (input.getHeaderName() != null) {
- for (int i = 0; i < input.getHeaderName().length; i++) {
+ if (!Utils.isEmpty(input.getConnectionName())) {
+ wSelectionLine.setText(input.getConnectionName());
+ }
+
+ if (!input.getHeaderFields().isEmpty()) {
+ for (int i = 0; i < input.getHeaderFields().size(); i++) {
TableItem item = wFields.table.getItem(i);
- if (input.getHeaderField()[i] != null) {
- item.setText(1, input.getHeaderField()[i]);
+ if (input.getHeaderFields().get(i) != null) {
+ item.setText(1, input.getHeaderFields().get(i).getHeaderField());
}
- if (input.getHeaderName()[i] != null) {
- item.setText(2, input.getHeaderName()[i]);
+ if (input.getHeaderFields().get(i) != null) {
+ item.setText(2, input.getHeaderFields().get(i).getName());
}
}
}
- if (input.getParameterField() != null) {
- for (int i = 0; i < input.getParameterField().length; i++) {
+ if (!input.getParameterFields().isEmpty()) {
+ for (int i = 0; i < input.getParameterFields().size(); i++) {
TableItem item = wParameters.table.getItem(i);
- if (input.getParameterField()[i] != null) {
- item.setText(1, input.getParameterField()[i]);
+ if (input.getParameterFields().get(i) != null) {
+ item.setText(1, input.getParameterFields().get(i).getHeaderField());
}
- if (input.getParameterName()[i] != null) {
- item.setText(2, input.getParameterName()[i]);
+ if (input.getParameterFields().get(i) != null) {
+ item.setText(2, input.getParameterFields().get(i).getName());
}
}
}
- if (input.getMatrixParameterField() != null) {
- for (int i = 0; i < input.getMatrixParameterField().length; i++) {
+ if (!input.getMatrixParameterFields().isEmpty()) {
+ for (int i = 0; i < input.getMatrixParameterFields().size(); i++) {
TableItem item = wMatrixParameters.table.getItem(i);
- if (input.getMatrixParameterField()[i] != null) {
- item.setText(1, input.getMatrixParameterField()[i]);
+ if (input.getMatrixParameterFields().get(i) != null) {
+ item.setText(1,
input.getMatrixParameterFields().get(i).getHeaderField());
}
- if (input.getMatrixParameterField()[i] != null) {
- item.setText(2, input.getMatrixParameterField()[i]);
+ if (input.getMatrixParameterFields().get(i) != null) {
+ item.setText(2, input.getMatrixParameterFields().get(i).getName());
}
}
}
@@ -1353,14 +1404,14 @@ public class RestDialog extends BaseTransformDialog {
if (input.getUrlField() != null) {
wUrlField.setText(input.getUrlField());
}
- if (input.getFieldName() != null) {
- wResult.setText(input.getFieldName());
+ if (input.getResultField().getFieldName() != null) {
+ wResult.setText(input.getResultField().getFieldName());
}
- if (input.getResultCodeFieldName() != null) {
- wResultCode.setText(input.getResultCodeFieldName());
+ if (input.getResultField().getCode() != null) {
+ wResultCode.setText(input.getResultField().getCode());
}
- if (input.getResponseTimeFieldName() != null) {
- wResponseTime.setText(input.getResponseTimeFieldName());
+ if (input.getResultField().getResponseTime() != null) {
+ wResponseTime.setText(input.getResultField().getResponseTime());
}
if (input.getConnectionTimeout() != null) {
wConnectionTimeout.setText(input.getConnectionTimeout());
@@ -1389,8 +1440,8 @@ public class RestDialog extends BaseTransformDialog {
wTrustStorePassword.setText(input.getTrustStorePassword());
}
wIgnoreSsl.setSelection(input.isIgnoreSsl());
- if (input.getResponseHeaderFieldName() != null) {
- wResponseHeader.setText(input.getResponseHeaderFieldName());
+ if (input.getResultField().getResponseHeader() != null) {
+ wResponseHeader.setText(input.getResultField().getResponseHeader());
}
wApplicationType.setText(Const.NVL(input.getApplicationType(), ""));
@@ -1413,30 +1464,37 @@ public class RestDialog extends BaseTransformDialog {
return;
}
- int nrheaders = wFields.nrNonEmpty();
- int nrparams = wParameters.nrNonEmpty();
- int nrmatrixparams = wMatrixParameters.nrNonEmpty();
- input.allocate(nrheaders, nrparams, nrmatrixparams);
+ if (!Utils.isEmpty(wSelectionLine.getText())) {
+ input.setConnectionName(wSelectionLine.getText());
+ }
+
+ input.getHeaderFields().clear();
+ input.getParameterFields().clear();
+ input.getMatrixParameterFields().clear();
if (isDebug()) {
logDebug(
- BaseMessages.getString(PKG, "RestDialog.Log.FoundArguments",
String.valueOf(nrheaders)));
+ BaseMessages.getString(
+ PKG, "RestDialog.Log.FoundArguments",
String.valueOf(wFields.nrNonEmpty())));
}
- for (int i = 0; i < nrheaders; i++) {
+ for (int i = 0; i < wFields.nrNonEmpty(); i++) {
TableItem item = wFields.getNonEmpty(i);
- input.getHeaderField()[i] = item.getText(1);
- input.getHeaderName()[i] = item.getText(2);
+ HeaderField headerField = new HeaderField();
+ headerField.setHeaderField(item.getText(1));
+ headerField.setName(item.getText(2));
}
- for (int i = 0; i < nrparams; i++) {
+ for (int i = 0; i < wParameters.nrNonEmpty(); i++) {
TableItem item = wParameters.getNonEmpty(i);
- input.getParameterField()[i] = item.getText(1);
- input.getParameterName()[i] = item.getText(2);
+ ParameterField parameterField = new ParameterField();
+ parameterField.setHeaderField(item.getText(1));
+ parameterField.setName(item.getText(2));
}
- for (int i = 0; i < nrmatrixparams; i++) {
+ for (int i = 0; i < wMatrixParameters.nrNonEmpty(); i++) {
TableItem item = wMatrixParameters.getNonEmpty(i);
- input.getMatrixParameterField()[i] = item.getText(1);
- input.getMatrixParameterName()[i] = item.getText(2);
+ MatrixParameterField matrixParameterField = new MatrixParameterField();
+ matrixParameterField.setHeaderField(item.getText(1));
+ matrixParameterField.setName(item.getText(2));
}
input.setDynamicMethod(wMethodInField.getSelection());
@@ -1446,10 +1504,10 @@ public class RestDialog extends BaseTransformDialog {
input.setUrlField(wUrlField.getText());
input.setUrlInField(wUrlInField.getSelection());
input.setBodyField(wBody.getText());
- input.setFieldName(wResult.getText());
- input.setResultCodeFieldName(wResultCode.getText());
- input.setResponseTimeFieldName(wResponseTime.getText());
- input.setResponseHeaderFieldName(wResponseHeader.getText());
+ input.getResultField().setFieldName(wResult.getText());
+ input.getResultField().setCode(wResultCode.getText());
+ input.getResultField().setResponseTime(wResponseTime.getText());
+ input.getResultField().setResponseHeader(wResponseHeader.getText());
input.setConnectionTimeout(wConnectionTimeout.getText());
input.setReadTimeout(wReadTimeout.getText());
input.setHttpLogin(wHttpLogin.getText());
diff --git
a/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/RestMeta.java
b/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/RestMeta.java
index 97232b764a..f24ffc5905 100644
---
a/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/RestMeta.java
+++
b/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/RestMeta.java
@@ -17,27 +17,28 @@
package org.apache.hop.pipeline.transforms.rest;
+import java.util.ArrayList;
import java.util.List;
import org.apache.hop.core.CheckResult;
-import org.apache.hop.core.Const;
import org.apache.hop.core.ICheckResult;
import org.apache.hop.core.annotations.Transform;
-import org.apache.hop.core.encryption.Encr;
import org.apache.hop.core.exception.HopTransformException;
-import org.apache.hop.core.exception.HopXmlException;
import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.core.row.IValueMeta;
import org.apache.hop.core.row.value.ValueMetaInteger;
import org.apache.hop.core.row.value.ValueMetaString;
import org.apache.hop.core.util.Utils;
import org.apache.hop.core.variables.IVariables;
-import org.apache.hop.core.xml.XmlHandler;
import org.apache.hop.i18n.BaseMessages;
+import org.apache.hop.metadata.api.HopMetadataProperty;
import org.apache.hop.metadata.api.IHopMetadataProvider;
import org.apache.hop.pipeline.PipelineMeta;
import org.apache.hop.pipeline.transform.BaseTransformMeta;
import org.apache.hop.pipeline.transform.TransformMeta;
-import org.w3c.dom.Node;
+import org.apache.hop.pipeline.transforms.rest.fields.HeaderField;
+import org.apache.hop.pipeline.transforms.rest.fields.MatrixParameterField;
+import org.apache.hop.pipeline.transforms.rest.fields.ParameterField;
+import org.apache.hop.pipeline.transforms.rest.fields.ResultField;
@Transform(
id = "Rest",
@@ -84,6 +85,7 @@ public class RestMeta extends BaseTransformMeta<Rest,
RestData> {
public static final String CONST_SPACES = " ";
public static final String CONST_FIELD = "field";
+ @HopMetadataProperty(key = "applicationType", injectionKey =
"APPLICATION_TYPE")
private String applicationType;
public static final String[] HTTP_METHODS =
@@ -103,64 +105,99 @@ public class RestMeta extends BaseTransformMeta<Rest,
RestData> {
/** The default timeout for waiting for reading data (milliseconds) */
public static final int DEFAULT_READ_TIMEOUT = 10000;
+ @HopMetadataProperty(key = "connection_name", injectionKey =
"CONNECTION_NAME")
+ private String connectionName;
+
/** URL / service to be called */
+ @HopMetadataProperty(key = "url", injectionKey = "URL")
private String url;
+ @HopMetadataProperty(key = "urlInField", injectionKey = "URL_IN_FIELD")
private boolean urlInField;
- private String urlField;
-
- /** headers name */
- private String[] headerField;
-
- private String[] headerName;
-
- /** Query parameters name */
- private String[] parameterField;
- private String[] parameterName;
-
- /** Matrix parameters name */
- private String[] matrixParameterField;
-
- private String[] matrixParameterName;
-
- /** function result: new value name */
- private String fieldName;
-
- private String resultCodeFieldName;
- private String responseTimeFieldName;
- private String responseHeaderFieldName;
+ @HopMetadataProperty(key = "urlField", injectionKey = "URL_IN_FIELD")
+ private String urlField;
/** proxy */
+ @HopMetadataProperty(key = "proxyHost", injectionKey = "PROXY_HOST")
private String proxyHost;
+ @HopMetadataProperty(key = "proxyPort", injectionKey = "PROXY_PORT")
private String proxyPort;
+
+ @HopMetadataProperty(key = "httpLogin", injectionKey = "HTTP_LOGIN")
private String httpLogin;
+
+ @HopMetadataProperty(key = "httpPassword", injectionKey = "HTTP_PASSWORD")
private String httpPassword;
+
+ @HopMetadataProperty(key = "preemptive", injectionKey = "PREEMPTIVE")
private boolean preemptive;
/** Body fieldname */
+ @HopMetadataProperty(key = "bodyField", injectionKey = "BODY_FIELD")
private String bodyField;
/** HTTP Method */
+ @HopMetadataProperty(key = "method", injectionKey = "METHOD")
private String method;
+ @HopMetadataProperty(key = "dynamicMethod", injectionKey = "DYMAMIC_METHOD")
private boolean dynamicMethod;
+
+ @HopMetadataProperty(key = "methodFieldName", injectionKey =
"METHOD_FIELD_NAME")
private String methodFieldName;
/** Trust store */
+ @HopMetadataProperty(key = "trustStoreFile", injectionKey =
"TRUSTSTORE_FILE")
private String trustStoreFile;
+ @HopMetadataProperty(
+ key = "trustStorePassword",
+ injectionKey = "TRUSTSTORE_PASSWORD",
+ password = true)
private String trustStorePassword;
+ @HopMetadataProperty(key = "connectionTimeout", injectionKey =
"CONNECTION_TIMEOUT")
private String connectionTimeout;
+ @HopMetadataProperty(key = "readTimeout", injectionKey = "READ_TIMEOUT")
private String readTimeout;
+ @HopMetadataProperty(key = "ignoreSsl", injectionKey = "IGNORE_SSL")
private boolean ignoreSsl;
+ /** headers name */
+ @HopMetadataProperty(
+ key = "header",
+ groupKey = "headers",
+ injectionKey = "HEADERS",
+ injectionGroupKey = "HEADER")
+ private List<HeaderField> headerFields;
+
+ @HopMetadataProperty(
+ key = "parameter",
+ injectionKey = "PARAMETER",
+ groupKey = "parameters",
+ injectionGroupKey = "PARAMETERS")
+ private List<ParameterField> parameterFields;
+
+ @HopMetadataProperty(
+ key = "matrixParameter",
+ injectionKey = "MATRIX_PARAMETER",
+ groupKey = "matrixParameters",
+ injectionGroupKey = "MATRIX_PARAMETERS")
+ private List<MatrixParameterField> matrixParameterFields;
+
+ @HopMetadataProperty(key = "result", injectionKey = "RESULT")
+ private ResultField resultField;
+
public RestMeta() {
super(); // allocate BaseTransformMeta
+ headerFields = new ArrayList<>();
+ parameterFields = new ArrayList<>();
+ matrixParameterFields = new ArrayList<>();
+ resultField = new ResultField();
}
/**
@@ -191,88 +228,37 @@ public class RestMeta extends BaseTransformMeta<Rest,
RestData> {
this.bodyField = value;
}
- /**
- * @return Returns the headerName.
- */
- public String[] getHeaderName() {
- return headerName;
- }
-
- /**
- * @param value The headerName to set.
- */
- public void setHeaderName(String[] value) {
- this.headerName = value;
- }
-
/**
* @return Returns the parameterField.
*/
- public String[] getParameterField() {
- return parameterField;
- }
-
- /**
- * @param value The parameterField to set.
- */
- public void setParameterField(String[] value) {
- this.parameterField = value;
- }
-
- /**
- * @return Returns the parameterName.
- */
- public String[] getParameterName() {
- return parameterName;
- }
-
- /**
- * @param value The parameterName to set.
- */
- public void setParameterName(String[] value) {
- this.parameterName = value;
+ public List<ParameterField> getParameterFields() {
+ return parameterFields;
}
- /**
- * @return Returns the matrixParameterField.
- */
- public String[] getMatrixParameterField() {
- return matrixParameterField;
+ public void setParameterFields(List<ParameterField> value) {
+ this.parameterFields = value;
}
- /**
- * @param value The matrixParameterField to set.
- */
- public void setMatrixParameterField(String[] value) {
- this.matrixParameterField = value;
+ public List<MatrixParameterField> getMatrixParameterFields() {
+ return matrixParameterFields;
}
- /**
- * @return Returns the matrixParameterName.
- */
- public String[] getMatrixParameterName() {
- return matrixParameterName;
- }
-
- /**
- * @param value The matrixParameterName to set.
- */
- public void setMatrixParameterName(String[] value) {
- this.matrixParameterName = value;
+ public void setMatrixParameterFields(List<MatrixParameterField> value) {
+ this.matrixParameterFields = value;
}
/**
* @return Returns the headerField.
*/
- public String[] getHeaderField() {
- return headerField;
+ public List<HeaderField> getHeaderFields() {
+ return headerFields;
}
/**
* @param value The headerField to set.
*/
- public void setHeaderField(String[] value) {
- this.headerField = value;
+ public void setHeaderFields(List<HeaderField> value) {
+ this.headerFields = value;
}
/**
@@ -359,20 +345,6 @@ public class RestMeta extends BaseTransformMeta<Rest,
RestData> {
this.urlField = urlField;
}
- /**
- * @return Returns the resultName.
- */
- public String getFieldName() {
- return fieldName;
- }
-
- /**
- * @param resultName The resultName to set.
- */
- public void setFieldName(String resultName) {
- this.fieldName = resultName;
- }
-
public boolean isIgnoreSsl() {
return ignoreSsl;
}
@@ -381,48 +353,20 @@ public class RestMeta extends BaseTransformMeta<Rest,
RestData> {
this.ignoreSsl = ignoreSsl;
}
- @Override
- public void loadXml(Node transformNode, IHopMetadataProvider
metadataProvider)
- throws HopXmlException {
- readData(transformNode, metadataProvider);
- }
-
- public void allocate(int nrheaders, int nrparamers, int nrmatrixparameters) {
- headerField = new String[nrheaders];
- headerName = new String[nrheaders];
- parameterField = new String[nrparamers];
- parameterName = new String[nrparamers];
- matrixParameterField = new String[nrmatrixparameters];
- matrixParameterName = new String[nrmatrixparameters];
- }
-
@Override
public Object clone() {
RestMeta retval = (RestMeta) super.clone();
- int nrheaders = headerName.length;
- int nrparameters = parameterField.length;
- int nrmatrixparameters = matrixParameterField.length;
-
- retval.allocate(nrheaders, nrparameters, nrmatrixparameters);
- System.arraycopy(headerField, 0, retval.headerField, 0, nrheaders);
- System.arraycopy(headerName, 0, retval.headerName, 0, nrheaders);
- System.arraycopy(parameterField, 0, retval.parameterField, 0,
nrparameters);
- System.arraycopy(parameterName, 0, retval.parameterName, 0, nrparameters);
- System.arraycopy(matrixParameterField, 0, retval.matrixParameterField, 0,
nrmatrixparameters);
- System.arraycopy(matrixParameterName, 0, retval.matrixParameterName, 0,
nrmatrixparameters);
-
return retval;
}
@Override
public void setDefault() {
- allocate(0, 0, 0);
+ headerFields = new ArrayList<>();
+ parameterFields = new ArrayList<>();
+ matrixParameterFields = new ArrayList<>();
+ resultField = new ResultField();
- this.fieldName = CONST_RESULT;
- this.resultCodeFieldName = "";
- this.responseTimeFieldName = "";
- this.responseHeaderFieldName = "";
this.method = HTTP_METHOD_GET;
this.dynamicMethod = false;
this.methodFieldName = null;
@@ -443,23 +387,23 @@ public class RestMeta extends BaseTransformMeta<Rest,
RestData> {
IVariables variables,
IHopMetadataProvider metadataProvider)
throws HopTransformException {
- if (!Utils.isEmpty(fieldName)) {
- IValueMeta v = new ValueMetaString(variables.resolve(fieldName));
+ if (!Utils.isEmpty(resultField.getFieldName())) {
+ IValueMeta v = new
ValueMetaString(variables.resolve(resultField.getFieldName()));
v.setOrigin(name);
inputRowMeta.addValueMeta(v);
}
- if (!Utils.isEmpty(resultCodeFieldName)) {
- IValueMeta v = new
ValueMetaInteger(variables.resolve(resultCodeFieldName));
+ if (!Utils.isEmpty(resultField.getCode())) {
+ IValueMeta v = new
ValueMetaInteger(variables.resolve(resultField.getCode()));
v.setOrigin(name);
inputRowMeta.addValueMeta(v);
}
- if (!Utils.isEmpty(responseTimeFieldName)) {
- IValueMeta v = new
ValueMetaInteger(variables.resolve(responseTimeFieldName));
+ if (!Utils.isEmpty(resultField.getResponseTime())) {
+ IValueMeta v = new
ValueMetaInteger(variables.resolve(resultField.getResponseTime()));
v.setOrigin(name);
inputRowMeta.addValueMeta(v);
}
- String headerFieldName = variables.resolve(responseHeaderFieldName);
+ String headerFieldName =
variables.resolve(resultField.getResponseHeader());
if (!Utils.isEmpty(headerFieldName)) {
IValueMeta v = new ValueMetaString(headerFieldName);
v.setOrigin(name);
@@ -467,159 +411,6 @@ public class RestMeta extends BaseTransformMeta<Rest,
RestData> {
}
}
- @Override
- public String getXml() {
- StringBuilder retval = new StringBuilder();
- retval.append(" ").append(XmlHandler.addTagValue("applicationType",
applicationType));
- retval.append(" ").append(XmlHandler.addTagValue("method", method));
- retval.append(" ").append(XmlHandler.addTagValue("url", url));
- retval.append(" ").append(XmlHandler.addTagValue("urlInField",
urlInField));
- retval.append(" ").append(XmlHandler.addTagValue("dynamicMethod",
dynamicMethod));
- retval.append(" ").append(XmlHandler.addTagValue("methodFieldName",
methodFieldName));
-
- retval.append(" ").append(XmlHandler.addTagValue("urlField", urlField));
- retval.append(" ").append(XmlHandler.addTagValue("bodyField",
bodyField));
- retval.append(" ").append(XmlHandler.addTagValue("httpLogin",
httpLogin));
-
- retval.append(" ").append(XmlHandler.addTagValue("readTimeout",
readTimeout));
- retval.append(" ").append(XmlHandler.addTagValue("connectionTimeout",
connectionTimeout));
-
- retval
- .append(" ")
- .append(
- XmlHandler.addTagValue(
- "httpPassword",
Encr.encryptPasswordIfNotUsingVariables(httpPassword)));
-
- retval.append(" ").append(XmlHandler.addTagValue("proxyHost",
proxyHost));
- retval.append(" ").append(XmlHandler.addTagValue("proxyPort",
proxyPort));
- retval.append(" ").append(XmlHandler.addTagValue("preemptive",
preemptive));
-
- retval.append(" ").append(XmlHandler.addTagValue("trustStoreFile",
trustStoreFile));
- retval
- .append(" ")
- .append(
- XmlHandler.addTagValue(
- "trustStorePassword",
Encr.encryptPasswordIfNotUsingVariables(trustStorePassword)));
- retval.append(" ").append(XmlHandler.addTagValue("ignoreSsl",
ignoreSsl));
-
- retval.append(" <headers>").append(Const.CR);
- for (int i = 0, len = (headerName != null ? headerName.length : 0); i <
len; i++) {
- retval.append(" <header>").append(Const.CR);
-
retval.append(CONST_SPACES_LONG).append(XmlHandler.addTagValue(CONST_FIELD,
headerField[i]));
- retval.append(CONST_SPACES_LONG).append(XmlHandler.addTagValue("name",
headerName[i]));
- retval.append(" </header>").append(Const.CR);
- }
- retval.append(" </headers>").append(Const.CR);
-
- retval.append(" <parameters>").append(Const.CR);
- for (int i = 0, len = (parameterName != null ? parameterName.length : 0);
i < len; i++) {
- retval.append(" <parameter>").append(Const.CR);
- retval
- .append(CONST_SPACES_LONG)
- .append(XmlHandler.addTagValue(CONST_FIELD, parameterField[i]));
- retval.append(CONST_SPACES_LONG).append(XmlHandler.addTagValue("name",
parameterName[i]));
- retval.append(" </parameter>").append(Const.CR);
- }
- retval.append(" </parameters>").append(Const.CR);
-
- retval.append(" <matrixParameters>").append(Const.CR);
- for (int i = 0, len = (matrixParameterName != null ?
matrixParameterName.length : 0);
- i < len;
- i++) {
- retval.append(" <matrixParameter>").append(Const.CR);
- retval
- .append(CONST_SPACES_LONG)
- .append(XmlHandler.addTagValue(CONST_FIELD,
matrixParameterField[i]));
- retval
- .append(CONST_SPACES_LONG)
- .append(XmlHandler.addTagValue("name", matrixParameterName[i]));
- retval.append(" </matrixParameter>").append(Const.CR);
- }
- retval.append(" </matrixParameters>").append(Const.CR);
-
- retval.append(" <result>").append(Const.CR);
- retval.append(CONST_SPACES).append(XmlHandler.addTagValue("name",
fieldName));
- retval.append(CONST_SPACES).append(XmlHandler.addTagValue("code",
resultCodeFieldName));
- retval
- .append(CONST_SPACES)
- .append(XmlHandler.addTagValue("response_time",
responseTimeFieldName));
- retval
- .append(CONST_SPACES)
- .append(XmlHandler.addTagValue("response_header",
responseHeaderFieldName));
- retval.append(" </result>").append(Const.CR);
-
- return retval.toString();
- }
-
- private void readData(Node transformNode, IHopMetadataProvider
metadataProvider)
- throws HopXmlException {
- try {
- applicationType = XmlHandler.getTagValue(transformNode,
"applicationType");
- method = XmlHandler.getTagValue(transformNode, "method");
- url = XmlHandler.getTagValue(transformNode, "url");
- urlInField = "Y".equalsIgnoreCase(XmlHandler.getTagValue(transformNode,
"urlInField"));
- methodFieldName = XmlHandler.getTagValue(transformNode,
"methodFieldName");
-
- dynamicMethod =
"Y".equalsIgnoreCase(XmlHandler.getTagValue(transformNode, "dynamicMethod"));
- urlField = XmlHandler.getTagValue(transformNode, "urlField");
- bodyField = XmlHandler.getTagValue(transformNode, "bodyField");
- readTimeout = XmlHandler.getTagValue(transformNode, "readTimeout");
- connectionTimeout = XmlHandler.getTagValue(transformNode,
"connectionTimeout");
- httpLogin = XmlHandler.getTagValue(transformNode, "httpLogin");
- httpPassword =
- Encr.decryptPasswordOptionallyEncrypted(
- XmlHandler.getTagValue(transformNode, "httpPassword"));
-
- proxyHost = XmlHandler.getTagValue(transformNode, "proxyHost");
- proxyPort = XmlHandler.getTagValue(transformNode, "proxyPort");
- preemptive = "Y".equalsIgnoreCase(XmlHandler.getTagValue(transformNode,
"preemptive"));
-
- trustStoreFile = XmlHandler.getTagValue(transformNode, "trustStoreFile");
- trustStorePassword =
- Encr.decryptPasswordOptionallyEncrypted(
- XmlHandler.getTagValue(transformNode, "trustStorePassword"));
- ignoreSsl = "Y".equalsIgnoreCase(XmlHandler.getTagValue(transformNode,
"ignoreSsl"));
-
- Node headernode = XmlHandler.getSubNode(transformNode, "headers");
- int nrheaders = XmlHandler.countNodes(headernode, "header");
- Node paramnode = XmlHandler.getSubNode(transformNode, "parameters");
- int nrparameters = XmlHandler.countNodes(paramnode, "parameter");
- Node matrixparamnode = XmlHandler.getSubNode(transformNode,
"matrixParameters");
- int nrmatrixparameters = XmlHandler.countNodes(matrixparamnode,
"matrixParameter");
-
- allocate(nrheaders, nrparameters, nrmatrixparameters);
- for (int i = 0; i < nrheaders; i++) {
- Node anode = XmlHandler.getSubNodeByNr(headernode, "header", i);
- headerField[i] = XmlHandler.getTagValue(anode, CONST_FIELD);
- headerName[i] = XmlHandler.getTagValue(anode, "name");
- }
- for (int i = 0; i < nrparameters; i++) {
- Node anode = XmlHandler.getSubNodeByNr(paramnode, "parameter", i);
- parameterField[i] = XmlHandler.getTagValue(anode, CONST_FIELD);
- parameterName[i] = XmlHandler.getTagValue(anode, "name");
- }
- for (int i = 0; i < nrmatrixparameters; i++) {
- Node anode = XmlHandler.getSubNodeByNr(matrixparamnode,
"matrixParameter", i);
- matrixParameterField[i] = XmlHandler.getTagValue(anode, CONST_FIELD);
- matrixParameterName[i] = XmlHandler.getTagValue(anode, "name");
- }
-
- fieldName =
- XmlHandler.getTagValue(transformNode, CONST_RESULT, "name"); //
Optional, can be null
- resultCodeFieldName =
- XmlHandler.getTagValue(transformNode, CONST_RESULT, "code"); //
Optional, can be null
- responseTimeFieldName =
- XmlHandler.getTagValue(
- transformNode, CONST_RESULT, "response_time"); // Optional, can
be null
- responseHeaderFieldName =
- XmlHandler.getTagValue(
- transformNode, CONST_RESULT, "response_header"); // Optional,
can be null
- } catch (Exception e) {
- throw new HopXmlException(
- BaseMessages.getString(PKG,
"RestMeta.Exception.UnableToReadTransformMeta"), e);
- }
- }
-
@Override
public void check(
List<ICheckResult> remarks,
@@ -721,20 +512,6 @@ public class RestMeta extends BaseTransformMeta<Rest,
RestData> {
return true;
}
- /**
- * @return the resultCodeFieldName
- */
- public String getResultCodeFieldName() {
- return resultCodeFieldName;
- }
-
- /**
- * @param resultCodeFieldName the resultCodeFieldName to set
- */
- public void setResultCodeFieldName(String resultCodeFieldName) {
- this.resultCodeFieldName = resultCodeFieldName;
- }
-
/**
* Setter
*
@@ -855,20 +632,12 @@ public class RestMeta extends BaseTransformMeta<Rest,
RestData> {
return trustStorePassword;
}
- public String getResponseTimeFieldName() {
- return responseTimeFieldName;
+ public ResultField getResultField() {
+ return resultField;
}
- public void setResponseTimeFieldName(String responseTimeFieldName) {
- this.responseTimeFieldName = responseTimeFieldName;
- }
-
- public String getResponseHeaderFieldName() {
- return responseHeaderFieldName;
- }
-
- public void setResponseHeaderFieldName(String responseHeaderFieldName) {
- this.responseHeaderFieldName = responseHeaderFieldName;
+ public void setResultField(ResultField resultField) {
+ this.resultField = resultField;
}
public static boolean isActiveBody(String method) {
@@ -926,4 +695,12 @@ public class RestMeta extends BaseTransformMeta<Rest,
RestData> {
public void setReadTimeout(String timeout) {
this.readTimeout = timeout;
}
+
+ public String getConnectionName() {
+ return connectionName;
+ }
+
+ public void setConnectionName(String connectionName) {
+ this.connectionName = connectionName;
+ }
}
diff --git
a/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/fields/HeaderField.java
b/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/fields/HeaderField.java
new file mode 100644
index 0000000000..2f848555c5
--- /dev/null
+++
b/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/fields/HeaderField.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.pipeline.transforms.rest.fields;
+
+import org.apache.hop.metadata.api.HopMetadataProperty;
+
+public class HeaderField {
+
+ @HopMetadataProperty(key = "field", injectionKey = "HEADER_FIELD_FIELD")
+ private String headerField;
+
+ @HopMetadataProperty(key = "name", injectionKey = "HEADER_FIELD_NAME")
+ private String name;
+
+ public HeaderField() {}
+
+ public HeaderField(String headerField, String name) {
+ this.name = name;
+ this.headerField = headerField;
+ }
+
+ public String getHeaderField() {
+ return headerField;
+ }
+
+ public void setHeaderField(String headerField) {
+ this.headerField = headerField;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git
a/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/fields/MatrixParameterField.java
b/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/fields/MatrixParameterField.java
new file mode 100644
index 0000000000..6651f6b0a3
--- /dev/null
+++
b/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/fields/MatrixParameterField.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.pipeline.transforms.rest.fields;
+
+import org.apache.hop.metadata.api.HopMetadataProperty;
+
+public class MatrixParameterField {
+
+ @HopMetadataProperty(key = "field", injectionKey = "MATRIX_PARAMETER_FIELD")
+ private String headerField;
+
+ @HopMetadataProperty(key = "name", injectionKey = "MATRIX_PARAMETER_NAME")
+ private String name;
+
+ public MatrixParameterField() {}
+
+ public MatrixParameterField(String field, String name) {
+ this.headerField = field;
+ this.name = name;
+ }
+
+ public String getHeaderField() {
+ return headerField;
+ }
+
+ public void setHeaderField(String headerField) {
+ this.headerField = headerField;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git
a/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/fields/ParameterField.java
b/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/fields/ParameterField.java
new file mode 100644
index 0000000000..cf0b18317d
--- /dev/null
+++
b/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/fields/ParameterField.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.pipeline.transforms.rest.fields;
+
+import org.apache.hop.metadata.api.HopMetadataProperty;
+
+public class ParameterField {
+
+ @HopMetadataProperty(key = "field", injectionKey = "PARAMETER_FIELD")
+ private String headerField;
+
+ @HopMetadataProperty(key = "name", injectionKey = "PARAMETER_NAME")
+ private String name;
+
+ public ParameterField() {}
+
+ public ParameterField(String headerField, String name) {
+ this.headerField = headerField;
+ this.name = name;
+ }
+
+ public String getHeaderField() {
+ return headerField;
+ }
+
+ public void setHeaderField(String headerField) {
+ this.headerField = headerField;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git
a/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/fields/ResultField.java
b/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/fields/ResultField.java
new file mode 100644
index 0000000000..533799ea97
--- /dev/null
+++
b/plugins/transforms/rest/src/main/java/org/apache/hop/pipeline/transforms/rest/fields/ResultField.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.pipeline.transforms.rest.fields;
+
+import org.apache.hop.metadata.api.HopMetadataProperty;
+
+public class ResultField {
+
+ @HopMetadataProperty(key = "name", injectionKey = "RESULT_FIELD_NAME")
+ private String fieldName;
+
+ @HopMetadataProperty(key = "code", injectionKey = "RESULT_CODE")
+ private String code;
+
+ @HopMetadataProperty(key = "response_time", injectionKey = "RESPONSE_TIME")
+ private String responseTime;
+
+ @HopMetadataProperty(key = "response_header", injectionKey =
"RESPONSE_HEADER")
+ private String responseHeader;
+
+ public ResultField() {}
+
+ public ResultField(String fieldName, String code, String responseTime,
String responseHeader) {
+ this.fieldName = fieldName;
+ this.code = code;
+ }
+
+ public String getFieldName() {
+ return fieldName;
+ }
+
+ public void setFieldName(String fieldName) {
+ this.fieldName = fieldName;
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ public String getResponseTime() {
+ return responseTime;
+ }
+
+ public void setResponseTime(String responseTime) {
+ this.responseTime = responseTime;
+ }
+
+ public String getResponseHeader() {
+ return responseHeader;
+ }
+
+ public void setResponseHeader(String responseHeader) {
+ this.responseHeader = responseHeader;
+ }
+}
diff --git a/plugins/transforms/rest/src/main/resources/dependencies.xml
b/plugins/transforms/rest/src/main/resources/dependencies.xml
new file mode 100644
index 0000000000..b1869fc8c8
--- /dev/null
+++ b/plugins/transforms/rest/src/main/resources/dependencies.xml
@@ -0,0 +1,21 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ ~
+ -->
+
+<dependencies>
+ <folder>../../misc/rest/</folder>
+</dependencies>
diff --git
a/plugins/transforms/rest/src/test/java/org/apache/hop/pipeline/transforms/rest/RestMetaTest.java
b/plugins/transforms/rest/src/test/java/org/apache/hop/pipeline/transforms/rest/RestMetaTest.java
index 5ee6c6016f..6d61221cec 100644
---
a/plugins/transforms/rest/src/test/java/org/apache/hop/pipeline/transforms/rest/RestMetaTest.java
+++
b/plugins/transforms/rest/src/test/java/org/apache/hop/pipeline/transforms/rest/RestMetaTest.java
@@ -41,16 +41,26 @@ import org.apache.hop.core.variables.Variables;
import org.apache.hop.junit.rules.RestoreHopEngineEnvironment;
import org.apache.hop.metadata.api.IHopMetadataProvider;
import org.apache.hop.pipeline.PipelineMeta;
+import org.apache.hop.pipeline.transform.ITransformMeta;
import org.apache.hop.pipeline.transform.TransformMeta;
import org.apache.hop.pipeline.transforms.loadsave.LoadSaveTester;
-import
org.apache.hop.pipeline.transforms.loadsave.validator.ArrayLoadSaveValidator;
+import org.apache.hop.pipeline.transforms.loadsave.initializer.IInitializer;
import
org.apache.hop.pipeline.transforms.loadsave.validator.IFieldLoadSaveValidator;
-import
org.apache.hop.pipeline.transforms.loadsave.validator.StringLoadSaveValidator;
+import
org.apache.hop.pipeline.transforms.loadsave.validator.IFieldLoadSaveValidatorFactory;
+import org.apache.hop.pipeline.transforms.loadsave.validator.ObjectValidator;
+import org.apache.hop.pipeline.transforms.rest.fields.HeaderField;
+import org.apache.hop.pipeline.transforms.rest.fields.MatrixParameterField;
+import org.apache.hop.pipeline.transforms.rest.fields.ParameterField;
+import org.apache.hop.pipeline.transforms.rest.fields.ResultField;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
-public class RestMetaTest {
+public class RestMetaTest implements IInitializer<ITransformMeta> {
+
+ LoadSaveTester loadSaveTester;
+ Class<RestMeta> testMetaClass = RestMeta.class;
+
@ClassRule public static RestoreHopEngineEnvironment env = new
RestoreHopEngineEnvironment();
@BeforeClass
@@ -67,55 +77,208 @@ public class RestMetaTest {
List<String> attributes =
Arrays.asList(
"applicationType",
- "method",
"url",
"urlInField",
- "dynamicMethod",
- "methodFieldName",
"urlField",
- "bodyField",
- "connectionTimeout",
- "readTimeout",
- "httpLogin",
- "httpPassword",
"proxyHost",
"proxyPort",
+ "httpLogin",
+ "httpPassword",
"preemptive",
+ "bodyField",
+ "method",
+ "dynamicMethod",
+ "methodFieldName",
"trustStoreFile",
"trustStorePassword",
- "headerField",
- "headerName",
- "parameterField",
- "parameterName",
- "matrixParameterField",
- "matrixParameterName",
- "fieldName",
- "resultCodeFieldName",
- "responseTimeFieldName",
- "responseHeaderFieldName");
-
- Map<String, IFieldLoadSaveValidator<?>> fieldLoadSaveValidatorAttributeMap
= new HashMap<>();
-
- // Arrays need to be consistent length
- IFieldLoadSaveValidator<String[]> stringArrayLoadSaveValidator =
- new ArrayLoadSaveValidator<>(new StringLoadSaveValidator(), 25);
- fieldLoadSaveValidatorAttributeMap.put("headerField",
stringArrayLoadSaveValidator);
- fieldLoadSaveValidatorAttributeMap.put("headerName",
stringArrayLoadSaveValidator);
- fieldLoadSaveValidatorAttributeMap.put("parameterField",
stringArrayLoadSaveValidator);
- fieldLoadSaveValidatorAttributeMap.put("parameterName",
stringArrayLoadSaveValidator);
- fieldLoadSaveValidatorAttributeMap.put("matrixParameterField",
stringArrayLoadSaveValidator);
- fieldLoadSaveValidatorAttributeMap.put("matrixParameterName",
stringArrayLoadSaveValidator);
-
- LoadSaveTester<RestMeta> loadSaveTester =
- new LoadSaveTester<>(
- RestMeta.class,
+ "connectionTimeout",
+ "readTimeout",
+ "ignoreSsl",
+ "headerFields",
+ "parameterFields",
+ "matrixParameterFields",
+ "resultField"
+ // "headerField",
+ // "headerName",
+ // "parameterField",
+ // "parameterName",
+ // "matrixParameterField",
+ // "matrixParameterName",
+ // "fieldName",
+ // "resultCodeFieldName",
+ // "responseTimeFieldName",
+ // "responseHeaderFieldName"
+ );
+
+ Map<String, String> getterMap = new HashMap<>();
+ getterMap.put("applicationType", "getApplicationType");
+ getterMap.put("url", "getUrl");
+ getterMap.put("urlInField", "isUrlInField");
+ getterMap.put("urlField", "getUrlField");
+ getterMap.put("proxyHost", "getProxyHost");
+ getterMap.put("proxyPort", "getProxyPort");
+ getterMap.put("httpLogin", "getHttpLogin");
+ getterMap.put("httpPassword", "getHttpPassword");
+ getterMap.put("preemptive", "isPreemptive");
+ getterMap.put("bodyField", "getBodyField");
+ getterMap.put("method", "getMethod");
+ getterMap.put("dynamicMethod", "isDynamicMethod");
+ getterMap.put("methodFieldName", "getMethodFieldName");
+ getterMap.put("trustStoreFile", "getTrustStoreFile");
+ getterMap.put("trustStorePassword", "getTrustStorePassword");
+ getterMap.put("connectionTimeout", "getConnectionTimeout");
+ getterMap.put("readTimeout", "getReadTimeout");
+ getterMap.put("ignoreSsl", "isIgnoreSsl");
+ getterMap.put("headerFields", "getHeaderFields");
+ getterMap.put("parameterFields", "getParameterFields");
+ getterMap.put("matrixParameterFields", "getMatrixParameterFields");
+ getterMap.put("resultField", "getResultField");
+
+ Map<String, String> setterMap = new HashMap<>();
+ setterMap.put("applicationType", "setApplicationType");
+ setterMap.put("url", "setUrl");
+ setterMap.put("urlInField", "setUrlInField");
+ setterMap.put("urlField", "setUrlField");
+ setterMap.put("proxyHost", "setProxyHost");
+ setterMap.put("proxyPort", "setProxyPort");
+ setterMap.put("httpLogin", "setHttpLogin");
+ setterMap.put("httpPassword", "setHttpPassword");
+ setterMap.put("preemptive", "setPreemptive");
+ setterMap.put("bodyField", "setBodyField");
+ setterMap.put("method", "setMethod");
+ setterMap.put("dynamicMethod", "setDynamicMethod");
+ setterMap.put("methodFieldName", "setMethodFieldName");
+ setterMap.put("trustStoreFile", "setTrustStoreFile");
+ setterMap.put("trustStorePassword", "setTrustStorePassword");
+ setterMap.put("connectionTimeout", "setConnectionTimeout");
+ setterMap.put("readTimeout", "setReadTimeout");
+ setterMap.put("ignoreSsl", "setIgnoreSsl");
+ setterMap.put("headerFields", "setHeaderFields");
+ setterMap.put("parameterFields", "setParameterFields");
+ setterMap.put("matrixParameterFields", "setMatrixParameterFields");
+ setterMap.put("resultField", "setResultField");
+
+ Map<String, IFieldLoadSaveValidator<?>> attrValidatorMap = new HashMap<>();
+ Map<String, IFieldLoadSaveValidator<?>> typeValidatorMap = new HashMap<>();
+
+ loadSaveTester =
+ new LoadSaveTester(
+ testMetaClass,
attributes,
- new HashMap<>(),
- new HashMap<>(),
- fieldLoadSaveValidatorAttributeMap,
- new HashMap<>());
+ getterMap,
+ setterMap,
+ attrValidatorMap,
+ typeValidatorMap,
+ this);
+
+ IFieldLoadSaveValidatorFactory validatorFactory =
+ loadSaveTester.getFieldLoadSaveValidatorFactory();
+
+ validatorFactory.registerValidator(
+ validatorFactory.getName(ResultField.class),
+ new ObjectValidator<>(
+ validatorFactory,
+ ResultField.class,
+ Arrays.asList("fieldName", "code", "responseTime",
"responseHeader"),
+ new HashMap<String, String>() {
+ {
+ put("fieldname", "getFieldName");
+ put("code", "getCode");
+ put("responseTime", "getResponseTime");
+ put("responseHeader", "getResponseHeader");
+ }
+ },
+ new HashMap<String, String>() {
+ {
+ put("fieldname", "setFieldName");
+ put("code", "setCode");
+ put("responseTime", "setResponseTime");
+ put("responseHeader", "setResponseHeader");
+ }
+ }));
+
+ validatorFactory.registerValidator(
+ validatorFactory.getName(HeaderField.class),
+ new ObjectValidator<>(
+ validatorFactory,
+ HeaderField.class,
+ Arrays.asList("name", "headerField"),
+ new HashMap<String, String>() {
+ {
+ put("name", "getName");
+ put("headerField", "getHeaderField");
+ }
+ },
+ new HashMap<String, String>() {
+ {
+ put("bame", "setName");
+ put("headerField", "setHeaderField");
+ }
+ }));
- loadSaveTester.testSerialization();
+ validatorFactory.registerValidator(
+ validatorFactory.getName(ParameterField.class),
+ new ObjectValidator<>(
+ validatorFactory,
+ ParameterField.class,
+ Arrays.asList("name", "headerField"),
+ new HashMap<String, String>() {
+ {
+ put("name", "getName");
+ put("headerField", "getHeaderField");
+ }
+ },
+ new HashMap<String, String>() {
+ {
+ put("bame", "setName");
+ put("headerField", "setHeaderField");
+ }
+ }));
+
+ validatorFactory.registerValidator(
+ validatorFactory.getName(MatrixParameterField.class),
+ new ObjectValidator<>(
+ validatorFactory,
+ MatrixParameterField.class,
+ Arrays.asList("name", "headerField"),
+ new HashMap<String, String>() {
+ {
+ put("name", "getName");
+ put("headerField", "getHeaderField");
+ }
+ },
+ new HashMap<String, String>() {
+ {
+ put("bame", "setName");
+ put("headerField", "setHeaderField");
+ }
+ }));
+
+ // Map<String, IFieldLoadSaveValidator<?>>
fieldLoadSaveValidatorAttributeMap = new
+ // HashMap<>();
+ //
+ // // Arrays need to be consistent length
+ // IFieldLoadSaveValidator<String[]> stringArrayLoadSaveValidator =
+ // new ArrayLoadSaveValidator<>(new StringLoadSaveValidator(), 25);
+ // fieldLoadSaveValidatorAttributeMap.put("headerField",
stringArrayLoadSaveValidator);
+ // fieldLoadSaveValidatorAttributeMap.put("headerName",
stringArrayLoadSaveValidator);
+ // fieldLoadSaveValidatorAttributeMap.put("parameterField",
stringArrayLoadSaveValidator);
+ // fieldLoadSaveValidatorAttributeMap.put("parameterName",
stringArrayLoadSaveValidator);
+ // fieldLoadSaveValidatorAttributeMap.put("matrixParameterField",
+ // stringArrayLoadSaveValidator);
+ // fieldLoadSaveValidatorAttributeMap.put("matrixParameterName",
+ // stringArrayLoadSaveValidator);
+ //
+ // LoadSaveTester<RestMeta> loadSaveTester =
+ // new LoadSaveTester<>(
+ // RestMeta.class,
+ // attributes,
+ // new HashMap<>(),
+ // new HashMap<>(),
+ // fieldLoadSaveValidatorAttributeMap,
+ // new HashMap<>());
+
+ // loadSaveTester.testSerialization();
}
@Test
@@ -169,4 +332,45 @@ public class RestMetaTest {
assertFalse(RestMeta.isActiveBody(RestMeta.HTTP_METHOD_HEAD));
assertFalse(RestMeta.isActiveBody(RestMeta.HTTP_METHOD_OPTIONS));
}
+
+ @Override
+ public void modify(ITransformMeta someMeta) {
+ if (someMeta instanceof RestMeta) {
+ ((RestMeta) someMeta).getHeaderFields().clear();
+ ((RestMeta) someMeta).getParameterFields().clear();
+ ((RestMeta) someMeta).getMatrixParameterFields().clear();
+
+ ((RestMeta) someMeta)
+ .getHeaderFields()
+ .addAll(
+ Arrays.asList(
+ new HeaderField("field1", "name1"),
+ new HeaderField("field2", "name2"),
+ new HeaderField("field3", "name3"),
+ new HeaderField("field4", "name4"),
+ new HeaderField("field1", "name5")));
+
+ ((RestMeta) someMeta)
+ .getMatrixParameterFields()
+ .addAll(
+ Arrays.asList(
+ new MatrixParameterField("field1", "name1"),
+ new MatrixParameterField("field2", "name2"),
+ new MatrixParameterField("field3", "name3"),
+ new MatrixParameterField("field4", "name4"),
+ new MatrixParameterField("field5", "name5")));
+
+ ((RestMeta) someMeta)
+ .getParameterFields()
+ .addAll(
+ Arrays.asList(
+ new ParameterField("field1", "name1"),
+ new ParameterField("field2", "name2"),
+ new ParameterField("field3", "name3"),
+ new ParameterField("field4", "name4"),
+ new ParameterField("field5", "name5")));
+ ((RestMeta) someMeta).getResultField().setFieldName("fieldname");
+ ((RestMeta) someMeta).getResultField().setResponseHeader("headerfield");
+ }
+ }
}