This is an automated email from the ASF dual-hosted git repository. dominikriemer pushed a commit to branch extend-client-custom-api in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit 5448cdeb132ff2b881403c038fc6abd6cf9c96e5 Author: Dominik Riemer <[email protected]> AuthorDate: Tue May 19 14:32:33 2026 +0200 feat: Extend client API with methods for plain JSON retrieval and updates --- .../streampipes/client/api/ICustomRequestApi.java | 8 +++ .../streampipes/client/api/AbstractClientApi.java | 7 +++ .../streampipes/client/api/CustomRequestApi.java | 27 ++++++++++ .../client/http/PutRequestWithPayloadResponse.java | 60 ++++++++++++++++++++++ 4 files changed, 102 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..1bcc767900 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,17 @@ 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); + + Object sendPutJson(String apiPath, Object payload); + <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..8c521fdc30 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 @@ -24,6 +24,7 @@ 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,6 +68,12 @@ 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(); 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..86c3af6b78 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,27 @@ 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 Object sendPutJson(String apiPath, Object payload) { + return put(StreamPipesApiPath.fromStreamPipesBasePath(apiPath), payload, 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/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); + } +}
