Skip to content

Commit

Permalink
fixed function mismatches. apache#4369
Browse files Browse the repository at this point in the history
  • Loading branch information
bamaer committed Dec 21, 2024
1 parent 60d02cf commit a528fb6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang.StringUtils;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.variables.IVariables;
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.HopMetadataPropertyType;
import org.apache.hop.metadata.api.IHopMetadata;

@Getter
@Setter
@HopMetadata(
key = "restconnection",
name = "i18n::RestConnection.name",
Expand All @@ -39,6 +44,7 @@
hopMetadataPropertyType = HopMetadataPropertyType.REST_CONNECTION)
public class RestConnection extends HopMetadataBase implements IHopMetadata {

private IVariables variables;
private ClientBuilder builder;
private Client client;

Expand All @@ -57,7 +63,8 @@ public class RestConnection extends HopMetadataBase implements IHopMetadata {
@HopMetadataProperty(key = "auth_header_value", injectionKey = "AUTH_HEADER_VALUE")
private String authorizationHeaderValue;

public RestConnection() {
public RestConnection(IVariables variables) {
this.variables = variables;
builder = ClientBuilder.newBuilder();
client = builder.build();
}
Expand All @@ -84,13 +91,17 @@ public void disconnect() throws HopException {
}

public void testConnection() throws HopException {
WebTarget target = client.target(testUrl);
WebTarget target = client.target(variables.resolve(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();
if (response.getStatus() != Response.Status.OK.getStatusCode()) {
Expand Down Expand Up @@ -145,44 +156,4 @@ public String getName() {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@ public Button[] createButtonsForButtonBar(Composite composite) {

private void test() {
IVariables variables = hopGui.getVariables();
RestConnection restConnection = new RestConnection();
RestConnection restConnection = new RestConnection(variables);
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.setAuthorizationPrefix(wAuthorizationPrefix.getText());
restConnection.setAuthorizationHeaderValue(wAuthorizationValue.getText());
try {
restConnection.testConnection();
Expand All @@ -226,7 +226,7 @@ public void setWidgetsContent() {
wBaseUrl.setText(Const.NVL(metadata.getBaseUrl(), ""));
wTestUrl.setText(Const.NVL(metadata.getTestUrl(), ""));
wAuthorizationName.setText(Const.NVL(metadata.getAuthorizationHeaderName(), ""));
wAuthorizationPrefix.setText(Const.NVL(metadata.getAuthHeaderPrefix(), ""));
wAuthorizationPrefix.setText(Const.NVL(metadata.getAuthorizationPrefix(), ""));
wAuthorizationValue.setText(Const.NVL(metadata.getAuthorizationHeaderValue(), ""));
}

Expand All @@ -236,7 +236,7 @@ public void getWidgetsContent(RestConnection connection) {
connection.setBaseUrl(wBaseUrl.getText());
connection.setTestUrl(wTestUrl.getText());
connection.setAuthorizationHeaderName(wAuthorizationName.getText());
connection.setAuthHeaderPrefix(wAuthorizationPrefix.getText());
connection.setAuthorizationPrefix(wAuthorizationPrefix.getText());
connection.setAuthorizationHeaderValue(wAuthorizationValue.getText());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

import org.apache.hop.core.variables.Variables;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

Expand All @@ -27,7 +28,7 @@ public class RestTest {
@Test
@Disabled
public void testRestConnection() {
RestConnection restConnection = new RestConnection();
RestConnection restConnection = new RestConnection(Variables.getADefaultVariableSpace());
restConnection.setBaseUrl("");
restConnection.setTestUrl("");
restConnection.setAuthorizationHeaderName("authorization");
Expand Down

0 comments on commit a528fb6

Please sign in to comment.