Skip to content

Commit

Permalink
additional rest connection and client updates. fixes #4758
Browse files Browse the repository at this point in the history
  • Loading branch information
bamaer committed Jan 16, 2025
1 parent 9fcb911 commit 77e9a33
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,15 @@ public RestConnection(IVariables variables) {
public String getResponse(String url) throws HopException {
WebTarget target = client.target(testUrl);
Invocation.Builder invocationBuilder = target.request();
if (!StringUtils.isEmpty(authorizationPrefix)) {
if (!StringUtils.isEmpty(variables.resolve(authorizationPrefix))) {
invocationBuilder.header(
authorizationHeaderName, authorizationPrefix + " " + authorizationHeaderValue);
variables.resolve(authorizationHeaderName),
variables.resolve(authorizationPrefix)
+ " "
+ variables.resolve(authorizationHeaderValue));
} else {
invocationBuilder.header(authorizationHeaderName, authorizationHeaderValue);
invocationBuilder.header(
variables.resolve(authorizationHeaderName), variables.resolve(authorizationHeaderValue));
}
Response response = invocationBuilder.get();

Expand All @@ -93,15 +97,20 @@ public void disconnect() throws HopException {
public void testConnection() throws HopException {
WebTarget target = client.target(variables.resolve(testUrl));
Invocation.Builder invocationBuilder = target.request();
if (!StringUtils.isEmpty(variables.resolve(authorizationPrefix))) {
invocationBuilder.header(
variables.resolve(authorizationHeaderName),
variables.resolve(authorizationPrefix)
+ " "
+ variables.resolve(authorizationHeaderValue));
} else {
invocationBuilder.header(
variables.resolve(authorizationHeaderName), variables.resolve(authorizationHeaderValue));

// only set the header if we have a header name
if (!StringUtils.isEmpty(variables.resolve(authorizationHeaderName))) {
if (!StringUtils.isEmpty(variables.resolve(authorizationPrefix))) {
invocationBuilder.header(
variables.resolve(authorizationHeaderName),
variables.resolve(authorizationPrefix)
+ " "
+ variables.resolve(authorizationHeaderValue));
} else {
invocationBuilder.header(
variables.resolve(authorizationHeaderName),
variables.resolve(authorizationHeaderValue));
}
}
Response response = invocationBuilder.get();
if (response.getStatus() != Response.Status.OK.getStatusCode()) {
Expand All @@ -110,6 +119,8 @@ public void testConnection() throws HopException {
response.close();
}

public RestConnection() {}

public RestConnection(RestConnection connection) {
this.baseUrl = connection.baseUrl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import org.apache.commons.lang.StringUtils;
import org.apache.hop.core.Const;
import org.apache.hop.core.encryption.Encr;
import org.apache.hop.core.exception.HopException;
Expand Down Expand Up @@ -175,10 +176,20 @@ protected Object[] callRest(Object[] rowData) throws HopException {
// 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());
}
if (!StringUtils.isEmpty(resolve(connection.getAuthorizationHeaderName())))
if (!Utils.isEmpty(resolve(connection.getAuthorizationHeaderName()))) {
if (!StringUtils.isEmpty(resolve(connection.getAuthorizationPrefix()))) {
invocationBuilder.header(
resolve(connection.getAuthorizationHeaderName()),
resolve(connection.getAuthorizationPrefix())
+ " "
+ resolve(connection.getAuthorizationHeaderValue()));
} else {
invocationBuilder.header(
resolve(connection.getAuthorizationHeaderName()),
resolve(connection.getAuthorizationHeaderValue()));
}
}
}

String contentType = null; // media type override, if not null
Expand Down

0 comments on commit 77e9a33

Please sign in to comment.