This is an automated email from the ASF dual-hosted git repository.
dominikriemer pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/streampipes.git
The following commit(s) were added to refs/heads/dev by this push:
new c69679b645 feat: Extend client API with methods for plain JSON
retrieval and upd… (#4488)
c69679b645 is described below
commit c69679b645186525339f0c338aef60e82e961824
Author: Dominik Riemer <[email protected]>
AuthorDate: Wed May 20 11:35:08 2026 +0200
feat: Extend client API with methods for plain JSON retrieval and upd…
(#4488)
---
.../streampipes/client/api/ICustomRequestApi.java | 14 +++++
.../streampipes/client/api/AbstractClientApi.java | 19 +++++++
.../streampipes/client/api/CustomRequestApi.java | 45 ++++++++++++++++
.../http/DeleteRequestWithoutPayloadResponse.java | 49 ++++++++++++++++++
.../client/http/PutRequestWithPayloadResponse.java | 60 ++++++++++++++++++++++
5 files changed, 187 insertions(+)
diff --git
a/streampipes-client-api/src/main/java/org/apache/streampipes/client/api/ICustomRequestApi.java
b/streampipes-client-api/src/main/java/org/apache/streampipes/client/api/ICustomRequestApi.java
index c29999ad34..98eea1ba53 100644
---
a/streampipes-client-api/src/main/java/org/apache/streampipes/client/api/ICustomRequestApi.java
+++
b/streampipes-client-api/src/main/java/org/apache/streampipes/client/api/ICustomRequestApi.java
@@ -24,9 +24,23 @@ import java.util.Map;
public interface ICustomRequestApi {
<T> void sendPost(String apiPath, T payload);
+ Object sendPostJson(String apiPath, Object payload);
+
<T> T sendGet(String apiPath, Class<T> responseClass);
<T> T sendGet(String apiPath, Map<String, String> queryParameters, Class<T>
responseClass);
+ Object sendGetJson(String apiPath);
+
+ Object sendGetJson(String apiPath, Map<String, String> queryParameters);
+
+ <T> void sendPut(String apiPath, T payload);
+
+ Object sendPutJson(String apiPath, Object payload);
+
+ void sendDelete(String apiPath);
+
+ Object sendDeleteJson(String apiPath);
+
<T> List<T> getList(String apiPath, Class<T> response);
}
diff --git
a/streampipes-client/src/main/java/org/apache/streampipes/client/api/AbstractClientApi.java
b/streampipes-client/src/main/java/org/apache/streampipes/client/api/AbstractClientApi.java
index e1da29f2f5..86eab3d78f 100644
---
a/streampipes-client/src/main/java/org/apache/streampipes/client/api/AbstractClientApi.java
+++
b/streampipes-client/src/main/java/org/apache/streampipes/client/api/AbstractClientApi.java
@@ -19,11 +19,13 @@ package org.apache.streampipes.client.api;
import org.apache.streampipes.client.http.DeleteRequest;
+import org.apache.streampipes.client.http.DeleteRequestWithoutPayloadResponse;
import org.apache.streampipes.client.http.GetRequest;
import org.apache.streampipes.client.http.PostRequestWithPayloadResponse;
import org.apache.streampipes.client.http.PostRequestWithoutPayload;
import org.apache.streampipes.client.http.PostRequestWithoutPayloadResponse;
import org.apache.streampipes.client.http.PutRequest;
+import org.apache.streampipes.client.http.PutRequestWithPayloadResponse;
import org.apache.streampipes.client.model.StreamPipesClientConfig;
import org.apache.streampipes.client.serializer.ListSerializer;
import org.apache.streampipes.client.serializer.ObjectSerializer;
@@ -67,11 +69,22 @@ public class AbstractClientApi {
new PutRequest<>(clientConfig, apiPath, serializer,
object).executeRequest();
}
+ protected <K, V> V put(StreamPipesApiPath apiPath, K object, Class<V>
responseClass) {
+ ObjectSerializer<K, V> serializer = new ObjectSerializer<>();
+ return new PutRequestWithPayloadResponse<>(clientConfig, apiPath,
serializer, object, responseClass)
+ .executeRequest();
+ }
+
protected <T> T delete(StreamPipesApiPath apiPath, Class<T> responseClass) {
Serializer<Void, T, T> serializer = new ObjectSerializer<>();
return new DeleteRequest<>(clientConfig, apiPath, responseClass,
serializer).executeRequest();
}
+ protected void delete(StreamPipesApiPath apiPath) {
+ Serializer<Void, Void, Void> serializer = new ObjectSerializer<>();
+ new DeleteRequestWithoutPayloadResponse<>(clientConfig, apiPath,
Void.class, serializer).executeRequest();
+ }
+
protected <K, V> V delete(StreamPipesApiPath apiPath,
K object,
Class<V> responseClass) {
@@ -79,6 +92,12 @@ public class AbstractClientApi {
return new DeleteRequest<>(clientConfig, apiPath, responseClass,
serializer, object).executeRequest();
}
+ protected <K> void delete(StreamPipesApiPath apiPath, K object) {
+ Serializer<K, Void, Void> serializer = new ObjectSerializer<>();
+ new DeleteRequestWithoutPayloadResponse<>(clientConfig, apiPath,
Void.class, serializer, object)
+ .executeRequest();
+ }
+
protected <K, V> V post(StreamPipesApiPath apiPath, K object, Class<V>
responseClass) {
ObjectSerializer<K, V> serializer = new ObjectSerializer<>();
return new PostRequestWithPayloadResponse<>(clientConfig, apiPath,
serializer, object, responseClass)
diff --git
a/streampipes-client/src/main/java/org/apache/streampipes/client/api/CustomRequestApi.java
b/streampipes-client/src/main/java/org/apache/streampipes/client/api/CustomRequestApi.java
index 8dcfbe0389..de5eaa3708 100644
---
a/streampipes-client/src/main/java/org/apache/streampipes/client/api/CustomRequestApi.java
+++
b/streampipes-client/src/main/java/org/apache/streampipes/client/api/CustomRequestApi.java
@@ -36,6 +36,12 @@ public class CustomRequestApi extends AbstractClientApi
implements ICustomReques
post(StreamPipesApiPath.fromStreamPipesBasePath(apiPath), payload);
}
+ @Override
+ @ExposedToScripts
+ public Object sendPostJson(String apiPath, Object payload) {
+ return post(StreamPipesApiPath.fromStreamPipesBasePath(apiPath), payload,
Object.class);
+ }
+
@Override
@ExposedToScripts
public <T> T sendGet(String apiPath, Class<T> responseClass) {
@@ -51,6 +57,45 @@ public class CustomRequestApi extends AbstractClientApi
implements ICustomReques
responseClass);
}
+ @Override
+ @ExposedToScripts
+ public Object sendGetJson(String apiPath) {
+ return getSingle(StreamPipesApiPath.fromStreamPipesBasePath(apiPath),
Object.class);
+ }
+
+ @Override
+ @ExposedToScripts
+ public Object sendGetJson(String apiPath, Map<String, String>
queryParameters) {
+ return getSingle(
+ StreamPipesApiPath.fromStreamPipesBasePath(apiPath)
+ .withQueryParameters(queryParameters),
+ Object.class);
+ }
+
+ @Override
+ @ExposedToScripts
+ public <T> void sendPut(String apiPath, T payload) {
+ put(StreamPipesApiPath.fromStreamPipesBasePath(apiPath), payload);
+ }
+
+ @Override
+ @ExposedToScripts
+ public Object sendPutJson(String apiPath, Object payload) {
+ return put(StreamPipesApiPath.fromStreamPipesBasePath(apiPath), payload,
Object.class);
+ }
+
+ @Override
+ @ExposedToScripts
+ public void sendDelete(String apiPath) {
+ delete(StreamPipesApiPath.fromStreamPipesBasePath(apiPath));
+ }
+
+ @Override
+ @ExposedToScripts
+ public Object sendDeleteJson(String apiPath) {
+ return delete(StreamPipesApiPath.fromStreamPipesBasePath(apiPath),
Object.class);
+ }
+
@Override
@ExposedToScripts
public <T> List<T> getList(String apiPath, Class<T> responseClass) {
diff --git
a/streampipes-client/src/main/java/org/apache/streampipes/client/http/DeleteRequestWithoutPayloadResponse.java
b/streampipes-client/src/main/java/org/apache/streampipes/client/http/DeleteRequestWithoutPayloadResponse.java
new file mode 100644
index 0000000000..180513dbcc
--- /dev/null
+++
b/streampipes-client/src/main/java/org/apache/streampipes/client/http/DeleteRequestWithoutPayloadResponse.java
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.streampipes.client.http;
+
+import org.apache.streampipes.client.model.StreamPipesClientConfig;
+import org.apache.streampipes.client.serializer.Serializer;
+import org.apache.streampipes.client.util.StreamPipesApiPath;
+
+import org.apache.http.HttpEntity;
+
+import java.io.IOException;
+
+public class DeleteRequestWithoutPayloadResponse<K, V> extends
DeleteRequest<K, V, Void> {
+
+ public DeleteRequestWithoutPayloadResponse(StreamPipesClientConfig
clientConfig,
+ StreamPipesApiPath apiPath,
+ Class<V> responseClass,
+ Serializer<K, V, Void>
serializer) {
+ super(clientConfig, apiPath, responseClass, serializer);
+ }
+
+ public DeleteRequestWithoutPayloadResponse(StreamPipesClientConfig
clientConfig,
+ StreamPipesApiPath apiPath,
+ Class<V> responseClass,
+ Serializer<K, V, Void> serializer,
+ K body) {
+ super(clientConfig, apiPath, responseClass, serializer, body);
+ }
+
+ @Override
+ protected Void afterRequest(Serializer<K, V, Void> serializer, HttpEntity
entity) throws IOException {
+ return null;
+ }
+}
diff --git
a/streampipes-client/src/main/java/org/apache/streampipes/client/http/PutRequestWithPayloadResponse.java
b/streampipes-client/src/main/java/org/apache/streampipes/client/http/PutRequestWithPayloadResponse.java
new file mode 100644
index 0000000000..c2865dc9fd
--- /dev/null
+++
b/streampipes-client/src/main/java/org/apache/streampipes/client/http/PutRequestWithPayloadResponse.java
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.streampipes.client.http;
+
+import org.apache.streampipes.client.model.StreamPipesClientConfig;
+import org.apache.streampipes.client.serializer.Serializer;
+import org.apache.streampipes.client.util.StreamPipesApiPath;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.client.fluent.Request;
+import org.apache.http.entity.ContentType;
+
+import java.io.IOException;
+
+public class PutRequestWithPayloadResponse<K, V, T> extends HttpRequest<K, V,
T> {
+
+ private final K body;
+ private final Class<V> responseClass;
+
+ public PutRequestWithPayloadResponse(StreamPipesClientConfig clientConfig,
+ StreamPipesApiPath apiPath,
+ Serializer<K, V, T> serializer,
+ K body,
+ Class<V> responseClass) {
+ super(clientConfig, apiPath, serializer);
+ this.body = body;
+ this.responseClass = responseClass;
+ }
+
+ @Override
+ protected Request makeRequest(Serializer<K, V, T> serializer) {
+ Request request = Request
+ .Put(makeUrl())
+ .setHeaders(standardPostHeaders());
+
+ request.bodyString(serializer.serialize(body),
ContentType.APPLICATION_JSON);
+
+ return request;
+ }
+
+ @Override
+ protected T afterRequest(Serializer<K, V, T> serializer, HttpEntity entity)
throws IOException {
+ return serializer.deserialize(entityAsString(entity), responseClass);
+ }
+}