Skip to content

Commit

Permalink
HttpSubscriptionProvider: remove method + payload
Browse files Browse the repository at this point in the history
  • Loading branch information
tbischoff2 authored and mjacoby committed Nov 11, 2024
1 parent bbb979f commit a2e4f1b
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.digitaltwin.aas4j.v3.model.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -88,9 +87,8 @@ private byte[] readRawValue() throws AssetConnectionException {
config.getPath(),
config.getFormat(),
DEFAULT_METHOD,
StringUtils.isBlank(config.getPayload())
? BodyPublishers.noBody()
: BodyPublishers.ofString(config.getPayload()),

BodyPublishers.noBody(),
BodyHandlers.ofByteArray(),
HttpHelper.mergeHeaders(connectionConfig.getHeaders(), config.getHeaders()));
if (!HttpHelper.is2xxSuccessful(response)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
public class HttpSubscriptionProviderConfig extends AbstractMultiFormatSubscriptionProviderConfig {

private String path;
private String method;
private String payload;
private long interval;
private Map<String, String> headers;

Expand All @@ -46,16 +44,6 @@ public void setPath(String path) {
}


public String getMethod() {
return method;
}


public void setMethod(String method) {
this.method = method;
}


public long getInterval() {
return interval;
}
Expand All @@ -66,16 +54,6 @@ public void setInterval(long interval) {
}


public String getPayload() {
return payload;
}


public void setPayload(String payload) {
this.payload = payload;
}


public Map<String, String> getHeaders() {
return headers;
}
Expand All @@ -97,16 +75,14 @@ public boolean equals(Object o) {
HttpSubscriptionProviderConfig that = (HttpSubscriptionProviderConfig) o;
return super.equals(that)
&& Objects.equals(path, that.path)
&& Objects.equals(method, that.method)
&& Objects.equals(payload, that.payload)
&& Objects.equals(interval, that.interval)
&& Objects.equals(headers, that.headers);
}


@Override
public int hashCode() {
return Objects.hash(super.hashCode(), path, method, payload, interval, headers);
return Objects.hash(super.hashCode(), path, interval, headers);
}


Expand All @@ -123,24 +99,12 @@ public B path(String value) {
}


public B method(String value) {
getBuildingInstance().setMethod(value);
return getSelf();
}


public B interval(long value) {
getBuildingInstance().setInterval(value);
return getSelf();
}


public B payload(String value) {
getBuildingInstance().setPayload(value);
return getSelf();
}


public B headers(Map<String, String> value) {
getBuildingInstance().setHeaders(value);
return getSelf();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
import java.util.function.Function;
import java.util.stream.Stream;
import javax.net.ssl.SSLHandshakeException;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.util.AasUtils;
import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable;
import org.eclipse.digitaltwin.aas4j.v3.model.Reference;
Expand Down Expand Up @@ -251,7 +250,7 @@ public void testSubscriptionProviderPropertyJsonGET()
List.of("{ \"value\": 1}",
"{ \"value\": 2}"),
"$.value",
null,
//null,
false,
PropertyValue.of(Datatype.INT, "1"),
PropertyValue.of(Datatype.INT, "2"));
Expand All @@ -272,7 +271,7 @@ public void testSubscriptionProviderPropertyJsonGET2()
+ " ]\n"
+ "}"),
"$.data[-1:].value",
null,
//null,
false,
PropertyValue.of(Datatype.INT, "42"));
}
Expand All @@ -287,7 +286,7 @@ public void testSubscriptionProviderPropertyJsonPOST()
List.of("{ \"value\": 1}",
"{ \"value\": 2}"),
"$.value",
"{ \"input\": \"foo\"}",
//"{ \"input\": \"foo\"}",
false,
PropertyValue.of(Datatype.INT, "1"),
PropertyValue.of(Datatype.INT, "2"));
Expand Down Expand Up @@ -599,7 +598,6 @@ private void assertSubscriptionProviderPropertyJson(Datatype datatype,
RequestMethod method,
List<String> httpResponseBodies,
String query,
String payload,
boolean useHttps,
PropertyValue... expected)
throws AssetConnectionException, ConfigurationInitializationException, InterruptedException, ResourceNotFoundException, PersistenceException {
Expand Down Expand Up @@ -638,7 +636,6 @@ private void assertSubscriptionProviderPropertyJson(Datatype datatype,
.path(path)
.format(JsonFormat.KEY)
.query(query)
.payload(payload)
.build());
HttpAssetConnection connection = new HttpAssetConnection(
CoreConfig.builder()
Expand All @@ -662,10 +659,6 @@ private void assertSubscriptionProviderPropertyJson(Datatype datatype,
connection.getSubscriptionProviders().get(REFERENCE).removeNewDataListener(listener);
Assert.assertArrayEquals(expected, actual);
RequestPatternBuilder verifier = new RequestPatternBuilder(method, urlEqualTo(path));
if (!StringUtils.isBlank(payload) && expected != null) {
verifier = verifier.withHeader(CONTENT_TYPE, equalTo(APPLICATION_JSON))
.withRequestBody(equalToJson(payload));
}
verify(exactly(httpResponseBodies.size()), verifier);
}
finally {
Expand Down
2 changes: 0 additions & 2 deletions docs/source/interfaces/asset-connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,7 @@ Validation of operation argument can be configured independently for in-, out-,
| format | JSON<br>XML | Content format of the payload. | |
| headers<br>*(optional)* | Map<String,String> | Headers to send with each request.<br>Overrides connection-level headers. | *empty list* |
| interval<br>*(optional)* | long | Interval to poll the server for changes (in ms). | 100 |
| method<br>*(optional)* | GET<br>PUT<br>POST | HTTP method to use when writing a value to HTTP. | GET |
| path | String | Path for the HTTP request, relative to the `baseUrl` of the connection. | |
| payload<br>*(optional)* | String | Static content to send with each request. | |
| query<br>*(optional)* | String | Additional information how to extract actual value from received messages.<br>Depends on `format`, e.g. for JSON this is a JSONPath expression. | |
:::

Expand Down
2 changes: 2 additions & 0 deletions docs/source/other/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
- Asset Connection
- General
- Fixed bug that caused FA³ST Service to crash when an Asset Connection threw an exception on startup
- HTTP
- Remove method and payload from Subscription Provider

## 1.1.0

Expand Down

0 comments on commit a2e4f1b

Please sign in to comment.