Skip to content

Commit

Permalink
initial implementation rest connection, removed xml methodes, fixed t…
Browse files Browse the repository at this point in the history
…ests, before cleanup. apache#4369
  • Loading branch information
bamaer committed Oct 20, 2024
1 parent c82f95f commit 5f32b61
Show file tree
Hide file tree
Showing 19 changed files with 1,003 additions and 414 deletions.
6 changes: 6 additions & 0 deletions assemblies/plugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion plugins/misc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
<module>passwords</module>
<module>projects</module>
<module>reflection</module>
<module>rest</module>
<module>static-schema</module>
<module>testing</module>
<module>rest</module>
</modules>

</project>
4 changes: 2 additions & 2 deletions plugins/misc/rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
<parent>
<groupId>org.apache.hop</groupId>
<artifactId>hop-plugins-misc</artifactId>
<version>2.10.0-SNAPSHOT</version>
<version>2.11.0-SNAPSHOT</version>
</parent>

<artifactId>rest</artifactId>
<artifactId>hop-misc-rest</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down
51 changes: 51 additions & 0 deletions plugins/misc/rest/src/assembly/assembly.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!--
~ 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.
~
-->

<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-misc-rest</id>
<formats>
<format>zip</format>
</formats>
<baseDirectory>.</baseDirectory>
<files>
<file>
<source>${project.basedir}/src/main/resources/version.xml</source>
<outputDirectory>plugins/misc/rest</outputDirectory>
<filtered>true</filtered>
</file>
</files>

<fileSets>
<fileSet>
<directory>${project.basedir}/src/main/samples</directory>
<outputDirectory>config/projects/samples/</outputDirectory>
</fileSet>
</fileSets>

<dependencySets>
<dependencySet>
<includes>
<include>org.apache.hop:hop-misc-rest:jar</include>
</includes>
<outputDirectory>plugins/misc/rest</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,44 @@ public RestConnection() {
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;
}
Expand Down Expand Up @@ -147,19 +185,4 @@ public void setAuthorizationHeaderValue(String authorizationHeaderValue) {
this.authorizationHeaderValue = authorizationHeaderValue;
}

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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

public class RestConnectionLine extends Composite {

public RestConnectionLine(Composite parent, int style) {
super(parent, style);


}
public RestConnectionLine(Composite parent, int style) {
super(parent, style);
}
}
20 changes: 20 additions & 0 deletions plugins/misc/rest/src/main/resources/version.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->

<version>${project.version}</version>
2 changes: 1 addition & 1 deletion plugins/transforms/rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<dependencies>
<dependency>
<groupId>org.apache.hop</groupId>
<artifactId>rest</artifactId>
<artifactId>hop-misc-rest</artifactId>
<version>${version}</version>
</dependency>
<dependency>
Expand Down
5 changes: 5 additions & 0 deletions plugins/transforms/rest/src/assembly/assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,15 @@ public boolean processRow() throws HopException {
}
}
// 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++) {
// int nrargs = meta.getHeaderName() == null ? 0 : meta.getHeaderName().length;
if (meta.getHeaderFields().isEmpty()) {
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"));
}
Expand All @@ -446,14 +446,14 @@ public boolean processRow() throws HopException {
}
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"));
}
Expand All @@ -466,14 +466,14 @@ public boolean processRow() throws HopException {
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"));
Expand Down Expand Up @@ -533,10 +533,10 @@ public boolean processRow() throws HopException {
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());
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public RestData() {
this.resultCodeFieldName = null;
this.resultResponseFieldName = null;
this.resultHeaderFieldName = null;
this.nrheader = 0;
// this.nrheader = 0;
this.nrParams = 0;
this.nrMatrixParams = 0;
this.method = null;
Expand Down
Loading

0 comments on commit 5f32b61

Please sign in to comment.