Skip to content

Commit 604c68f

Browse files
committed
http clients stuff should work now
1 parent 35241ba commit 604c68f

3 files changed

Lines changed: 25 additions & 27 deletions

File tree

IoTDBJDBC/src/main/java/com/oracle/demo/timg/iot/iotdbjdbc/messagehandler/outputs/http/IoTOutputHttiClientRequestFilter.java renamed to IoTDBJDBC/src/main/java/com/oracle/demo/timg/iot/iotdbjdbc/messagehandler/outputs/http/IoTOutputHttpClientRequestFilter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ Software and the Larger Work(s), and to sublicense the foregoing rights on
4949

5050
@ClientFilter(patterns = { "${messagehandler.output.iotoutputhttpclient:/api/v1/iotdata}/**"})
5151
@Log
52-
public class IoTOutputHttiClientRequestFilter {
52+
public class IoTOutputHttpClientRequestFilter {
5353
private final String username;
5454
private final String password;
5555

5656
@Inject
57-
public IoTOutputHttiClientRequestFilter(IoTOutputHttpClientSettings clientSettings) {
57+
public IoTOutputHttpClientRequestFilter(IoTOutputHttpClientSettings clientSettings) {
5858
this.username = clientSettings.getUsername();
5959
this.password = new String(Base64.getDecoder().decode(clientSettings.getPassword()));
6060
}
@@ -67,6 +67,6 @@ public void doFilter(MutableHttpRequest<?> request) {
6767

6868
@EventListener
6969
public void onStartup(StartupEvent event) {
70-
log.info("Startup event received for IoTOutputHttiClientRequestFilter username=" + this.username);
70+
log.info("Startup event received for IoTOutputHttpClientRequestFilter username=" + this.username);
7171
}
7272
}

IoTDBJDBC/src/main/java/com/oracle/demo/timg/iot/iotdbjdbc/messagehandler/outputs/http/IoTOutputHttpClientSettings.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ Software and the Larger Work(s), and to sublicense the foregoing rights on
4343
@Data
4444
public class IoTOutputHttpClientSettings {
4545
public static final String PREFIX = "messagehandler.output.iotoutputhttpclient";
46-
// @Property(name = IoTOutputHttpClientSettings.PREFIX + ".username",
47-
// defaultValue = "")
46+
// as we are operating as a configuration then the fields are set based on the
47+
// config tree
4848
private String username;
49-
// @Property(name = IoTOutputHttpClientSettings.PREFIX + ".password",
50-
// defaultValue = "")
5149
private String password;
5250
}

IoTDBJDBC/src/main/java/com/oracle/demo/timg/iot/iotdbjdbc/messagehandler/outputs/http/RawDataHttpOutput.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,53 +55,53 @@ public class RawDataHttpOutput implements RawDataMessageHandler {
5555
private final IoTOutputHttpClient httpClient;
5656
private final int order;
5757
private final HttpOutputType type;
58+
private final boolean sentDataIsCompleted;
5859

5960
@Inject
6061
public RawDataHttpOutput(IoTOutputHttpClient httpClient,
61-
@Property(name = "messagehandler.output.rawdata.httpclient.enabled.order") int order,
62-
@Property(name = "messagehandler.output.rawdata.httpclient.enabled.type", defaultValue = "STRING") HttpOutputType type) {
62+
@Property(name = "messagehandler.output.rawdata.httpclient.order") int order,
63+
@Property(name = "messagehandler.output.rawdata.httpclient.type", defaultValue = "STRING") HttpOutputType type,
64+
@Property(name = "messagehandler.output.rawdata.httpclient.sentdataiscompleted", defaultValue = "true") boolean sentDataIsCompleted) {
6365
this.httpClient = httpClient;
6466
this.order = order;
6567
this.type = type;
68+
this.sentDataIsCompleted = sentDataIsCompleted;
6669
}
6770

6871
@Override
6972
public RawData[] processRawData(RawData input) throws Exception {
7073
log.finer(() -> "RawData is " + input);
74+
boolean result;
7175
switch (type) {
7276
case BASE64_BYTES: {
7377
String bodyContent = Base64.getEncoder().encodeToString(input.getContent());
74-
boolean result = httpClient.postRawDataAsBase64(input.getDigitalTwinInstanceId(), input.getEndpoint(),
78+
result = httpClient.postRawDataAsBase64(input.getDigitalTwinInstanceId(), input.getEndpoint(),
7579
input.getContentType(), bodyContent);
76-
RawData results[] = new RawData[1];
77-
results[0] = input;
78-
return results;
80+
break;
7981
}
8082
case STRING: {
8183
if (input.getMediaType().isTextBased()) {
82-
boolean result = httpClient.postRawDataAsBase64(input.getDigitalTwinInstanceId(), input.getEndpoint(),
84+
result = httpClient.postRawDataAsString(input.getDigitalTwinInstanceId(), input.getEndpoint(),
8385
input.getContentType(), input.getContentString());
84-
85-
RawData results[] = new RawData[1];
86-
results[0] = input;
87-
return results;
8886
} else {
89-
throw new NotAStringBasedMediaType("Media type "+)
87+
throw new NotAStringBasedMediaType("Media type " + input.getMediaType());
9088
}
89+
break;
9190
}
9291
default:
9392
throw new InvalidHttpOutputTypeException("Processing type " + type + " is unknown");
94-
break;
95-
9693
}
97-
return new RawData[0];
9894
RawData results[];
99-
if (input.getContentType().equalsIgnoreCase(type)) {
100-
log.fine(() -> input.getContentType() + " is the same type as " + type);
101-
95+
if (result) {
96+
if (sentDataIsCompleted) {
97+
results = new RawData[1];
98+
results[0] = input;
99+
} else {
100+
results = new RawData[0];
101+
}
102102
} else {
103-
log.fine(() -> input.getContentType() + " is a different type than " + type);
104-
results = new RawData[0];
103+
results = new RawData[1];
104+
results[0] = input;
105105
}
106106
return results;
107107
}

0 commit comments

Comments
 (0)