From bad09d4f3a20e3eb48082a773dfac1deb2e68fdc Mon Sep 17 00:00:00 2001 From: Ezequiel Werner Date: Tue, 18 Feb 2025 16:36:34 -0300 Subject: [PATCH 01/12] poc for sse --- .../http-api/src/main/java/module-info.java | 5 +- .../runtime/http/api/client/HttpClient.java | 9 ++++ .../http/api/domain/sse/ServerSentEvent.java | 52 +++++++++++++++++++ .../runtime/http/api/server/HttpServer.java | 6 +++ .../http/api/server/sse/SseClientHandler.java | 12 +++++ .../api/server/sse/SseHandlerManager.java | 12 +++++ .../http/api/server/sse/SseSender.java | 16 ++++++ 7 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEvent.java create mode 100644 modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClientHandler.java create mode 100644 modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseHandlerManager.java create mode 100644 modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseSender.java diff --git a/modules/http-api/src/main/java/module-info.java b/modules/http-api/src/main/java/module-info.java index 3c0cd906548f..dfb8b0cc64ee 100644 --- a/modules/http-api/src/main/java/module-info.java +++ b/modules/http-api/src/main/java/module-info.java @@ -17,6 +17,7 @@ // For the deprecated API methods still relying on org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate requires org.mule.runtime.core; requires com.github.benmanes.caffeine; + requires org.reactivestreams; exports org.mule.runtime.http.api; exports org.mule.runtime.http.api.client; @@ -30,13 +31,15 @@ exports org.mule.runtime.http.api.domain.message.request; exports org.mule.runtime.http.api.domain.message.response; exports org.mule.runtime.http.api.domain.request; + exports org.mule.runtime.http.api.domain.sse; exports org.mule.runtime.http.api.exception; exports org.mule.runtime.http.api.server; exports org.mule.runtime.http.api.server.async; + exports org.mule.runtime.http.api.server.sse; exports org.mule.runtime.http.api.server.ws; exports org.mule.runtime.http.api.utils; exports org.mule.runtime.http.api.tcp; exports org.mule.runtime.http.api.ws; exports org.mule.runtime.http.api.ws.exception; - + } diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java index 215188c5143e..f2c165cee1f7 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java @@ -11,6 +11,7 @@ import org.mule.runtime.http.api.client.ws.WebSocketCallback; import org.mule.runtime.http.api.domain.message.request.HttpRequest; import org.mule.runtime.http.api.domain.message.response.HttpResponse; +import org.mule.runtime.http.api.domain.sse.ServerSentEvent; import org.mule.runtime.http.api.ws.WebSocket; import java.io.IOException; @@ -19,6 +20,8 @@ import java.util.concurrent.TimeoutException; import java.util.function.BiConsumer; +import org.reactivestreams.Publisher; + /** * Object that sends an HTTP request, and returns the response. Notice it must be started to be used and stopped to be disposed * properly. Blocking and non-blocking options are available to execute requests. To extends it's functionality and not depend on @@ -166,4 +169,10 @@ default CompletableFuture openWebSocket(HttpRequest request, WebSocketCallback callback) { throw new UnsupportedOperationException("WebSockets are only supported in Enterprise Edition"); } + + default Publisher consumeServerSentEvents(HttpRequest request, + HttpRequestOptions requestOptions, + String streamId) { + throw new UnsupportedOperationException("Server-sent Events are not supported"); + } } diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEvent.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEvent.java new file mode 100644 index 000000000000..b39aeacc09e3 --- /dev/null +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEvent.java @@ -0,0 +1,52 @@ +/* + * Copyright 2023 Salesforce, Inc. All rights reserved. + * The software in this package is published under the terms of the CPAL v1.0 + * license, a copy of which has been included with this distribution in the + * LICENSE.txt file. + */ +package org.mule.runtime.http.api.domain.sse; + +import java.io.Serial; +import java.io.Serializable; +import java.util.Objects; + +public class ServerSentEvent implements Serializable { + + @Serial + private static final long serialVersionUID = -1211505868025654629L; + + private final String eventName; + private final String eventData; + + public ServerSentEvent(String eventName, String eventData) { + this.eventName = eventName; + this.eventData = eventData; + } + + public String getEventName() { + return eventName; + } + + public String getEventData() { + return eventData; + } + + @Override + public String toString() { + return "ServerSentEvent [eventName=" + eventName + ", eventData=" + eventData + "]"; + } + + @Override + public int hashCode() { + return Objects.hashCode(eventName) + Objects.hashCode(eventData); + } + + @Override + public boolean equals(Object o) { + if (null == o || getClass() != o.getClass()) { + return false; + } + ServerSentEvent that = (ServerSentEvent) o; + return Objects.equals(eventName, that.eventName) && Objects.equals(eventData, that.eventData); + } +} diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/HttpServer.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/HttpServer.java index 486ac02d62fb..29af3052b65d 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/HttpServer.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/HttpServer.java @@ -9,6 +9,8 @@ import org.mule.api.annotation.NoImplement; import org.mule.runtime.api.tls.TlsContextFactory; import org.mule.runtime.http.api.HttpConstants.Protocol; +import org.mule.runtime.http.api.server.sse.SseClientHandler; +import org.mule.runtime.http.api.server.sse.SseHandlerManager; import org.mule.runtime.http.api.server.ws.WebSocketHandler; import org.mule.runtime.http.api.server.ws.WebSocketHandlerManager; @@ -117,4 +119,8 @@ RequestHandlerManager addRequestHandler(final Collection methods, final default WebSocketHandlerManager addWebSocketHandler(WebSocketHandler handler) { throw new UnsupportedOperationException("WebSockets are only supported in Enterprise Edition"); } + + default SseHandlerManager sse(String ssePath, SseClientHandler sseClientHandler) { + throw new UnsupportedOperationException("Server-sent events are not supported"); + } } diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClientHandler.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClientHandler.java new file mode 100644 index 000000000000..f3d2f48730c6 --- /dev/null +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClientHandler.java @@ -0,0 +1,12 @@ +/* + * Copyright 2023 Salesforce, Inc. All rights reserved. + * The software in this package is published under the terms of the CPAL v1.0 + * license, a copy of which has been included with this distribution in the + * LICENSE.txt file. + */ +package org.mule.runtime.http.api.server.sse; + +public interface SseClientHandler { + + void handle(SseSender sender); +} diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseHandlerManager.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseHandlerManager.java new file mode 100644 index 000000000000..2d624d0845f7 --- /dev/null +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseHandlerManager.java @@ -0,0 +1,12 @@ +/* + * Copyright 2023 Salesforce, Inc. All rights reserved. + * The software in this package is published under the terms of the CPAL v1.0 + * license, a copy of which has been included with this distribution in the + * LICENSE.txt file. + */ +package org.mule.runtime.http.api.server.sse; + +public interface SseHandlerManager { + + // start stop blah +} diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseSender.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseSender.java new file mode 100644 index 000000000000..ac1c236a3bd4 --- /dev/null +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseSender.java @@ -0,0 +1,16 @@ +/* + * Copyright 2023 Salesforce, Inc. All rights reserved. + * The software in this package is published under the terms of the CPAL v1.0 + * license, a copy of which has been included with this distribution in the + * LICENSE.txt file. + */ +package org.mule.runtime.http.api.server.sse; + +import java.io.IOException; + +public interface SseSender { + + void sendEvent(String eventName, Object payload) throws IOException; + + void finishStream() throws IOException; +} From a91c70e38359be932397a6fe4018b03f04ec9c70 Mon Sep 17 00:00:00 2001 From: Ezequiel Werner Date: Wed, 19 Feb 2025 13:57:49 -0300 Subject: [PATCH 02/12] poc --- modules/http-api/src/main/java/module-info.java | 1 + .../org/mule/runtime/http/api/client/HttpClient.java | 5 +++++ .../mule/runtime/http/api/client/sse/EventSource.java | 10 ++++++++++ 3 files changed, 16 insertions(+) create mode 100644 modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/EventSource.java diff --git a/modules/http-api/src/main/java/module-info.java b/modules/http-api/src/main/java/module-info.java index dfb8b0cc64ee..2dce7a12fa06 100644 --- a/modules/http-api/src/main/java/module-info.java +++ b/modules/http-api/src/main/java/module-info.java @@ -23,6 +23,7 @@ exports org.mule.runtime.http.api.client; exports org.mule.runtime.http.api.client.auth; exports org.mule.runtime.http.api.client.proxy; + exports org.mule.runtime.http.api.client.sse; exports org.mule.runtime.http.api.client.ws; exports org.mule.runtime.http.api.domain; exports org.mule.runtime.http.api.domain.entity; diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java index f2c165cee1f7..f85700e2b7d2 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java @@ -8,6 +8,7 @@ import org.mule.api.annotation.NoImplement; import org.mule.runtime.http.api.client.auth.HttpAuthentication; +import org.mule.runtime.http.api.client.sse.EventSource; import org.mule.runtime.http.api.client.ws.WebSocketCallback; import org.mule.runtime.http.api.domain.message.request.HttpRequest; import org.mule.runtime.http.api.domain.message.response.HttpResponse; @@ -175,4 +176,8 @@ default Publisher consumeServerSentEvents(HttpRequest request, String streamId) { throw new UnsupportedOperationException("Server-sent Events are not supported"); } + + default EventSource sseSource(String url) { + throw new UnsupportedOperationException("Server-sent Events are not supported"); + } } diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/EventSource.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/EventSource.java new file mode 100644 index 000000000000..12d856cd8643 --- /dev/null +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/EventSource.java @@ -0,0 +1,10 @@ +/* + * Copyright 2023 Salesforce, Inc. All rights reserved. + * The software in this package is published under the terms of the CPAL v1.0 + * license, a copy of which has been included with this distribution in the + * LICENSE.txt file. + */ +package org.mule.runtime.http.api.client.sse; + +public interface EventSource { +} From acb5504f0cd6f96bd11c32f9f9bb4b0c27921b0c Mon Sep 17 00:00:00 2001 From: Ezequiel Werner Date: Thu, 20 Feb 2025 11:20:30 -0300 Subject: [PATCH 03/12] ref --- .../runtime/http/api/client/HttpClient.java | 4 ++-- .../client/sse/ServerSentEventListener.java | 20 +++++++++++++++++++ ...Source.java => ServerSentEventSource.java} | 6 +++++- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventListener.java rename modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/{EventSource.java => ServerSentEventSource.java} (71%) diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java index f85700e2b7d2..e0f5f58effd2 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java @@ -8,7 +8,7 @@ import org.mule.api.annotation.NoImplement; import org.mule.runtime.http.api.client.auth.HttpAuthentication; -import org.mule.runtime.http.api.client.sse.EventSource; +import org.mule.runtime.http.api.client.sse.ServerSentEventSource; import org.mule.runtime.http.api.client.ws.WebSocketCallback; import org.mule.runtime.http.api.domain.message.request.HttpRequest; import org.mule.runtime.http.api.domain.message.response.HttpResponse; @@ -177,7 +177,7 @@ default Publisher consumeServerSentEvents(HttpRequest request, throw new UnsupportedOperationException("Server-sent Events are not supported"); } - default EventSource sseSource(String url) { + default ServerSentEventSource sseSource(String url) { throw new UnsupportedOperationException("Server-sent Events are not supported"); } } diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventListener.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventListener.java new file mode 100644 index 000000000000..fa6ca9f0b4e2 --- /dev/null +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventListener.java @@ -0,0 +1,20 @@ +/* + * Copyright 2023 Salesforce, Inc. All rights reserved. + * The software in this package is published under the terms of the CPAL v1.0 + * license, a copy of which has been included with this distribution in the + * LICENSE.txt file. + */ +package org.mule.runtime.http.api.client.sse; + +import org.mule.runtime.http.api.domain.sse.ServerSentEvent; + +public interface ServerSentEventListener { + + default void onOpen() {} + + default void onClose() {} + + default void onError(Throwable error) {} + + default void onEvent(ServerSentEvent event) {} +} diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/EventSource.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventSource.java similarity index 71% rename from modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/EventSource.java rename to modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventSource.java index 12d856cd8643..1c7d385c5f9e 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/EventSource.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventSource.java @@ -6,5 +6,9 @@ */ package org.mule.runtime.http.api.client.sse; -public interface EventSource { +public interface ServerSentEventSource { + + void connect(); + + void addListener(ServerSentEventListener listener); } From 639a03735d154670ceb5e0e095e1091366e4d989 Mon Sep 17 00:00:00 2001 From: Ezequiel Werner Date: Thu, 20 Feb 2025 11:44:54 -0300 Subject: [PATCH 04/12] remove reactive --- modules/http-api/src/main/java/module-info.java | 1 - .../org/mule/runtime/http/api/client/HttpClient.java | 9 --------- 2 files changed, 10 deletions(-) diff --git a/modules/http-api/src/main/java/module-info.java b/modules/http-api/src/main/java/module-info.java index 2dce7a12fa06..54740640404e 100644 --- a/modules/http-api/src/main/java/module-info.java +++ b/modules/http-api/src/main/java/module-info.java @@ -17,7 +17,6 @@ // For the deprecated API methods still relying on org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate requires org.mule.runtime.core; requires com.github.benmanes.caffeine; - requires org.reactivestreams; exports org.mule.runtime.http.api; exports org.mule.runtime.http.api.client; diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java index e0f5f58effd2..e48a430adf58 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java @@ -12,7 +12,6 @@ import org.mule.runtime.http.api.client.ws.WebSocketCallback; import org.mule.runtime.http.api.domain.message.request.HttpRequest; import org.mule.runtime.http.api.domain.message.response.HttpResponse; -import org.mule.runtime.http.api.domain.sse.ServerSentEvent; import org.mule.runtime.http.api.ws.WebSocket; import java.io.IOException; @@ -21,8 +20,6 @@ import java.util.concurrent.TimeoutException; import java.util.function.BiConsumer; -import org.reactivestreams.Publisher; - /** * Object that sends an HTTP request, and returns the response. Notice it must be started to be used and stopped to be disposed * properly. Blocking and non-blocking options are available to execute requests. To extends it's functionality and not depend on @@ -171,12 +168,6 @@ default CompletableFuture openWebSocket(HttpRequest request, throw new UnsupportedOperationException("WebSockets are only supported in Enterprise Edition"); } - default Publisher consumeServerSentEvents(HttpRequest request, - HttpRequestOptions requestOptions, - String streamId) { - throw new UnsupportedOperationException("Server-sent Events are not supported"); - } - default ServerSentEventSource sseSource(String url) { throw new UnsupportedOperationException("Server-sent Events are not supported"); } From aa5ce22707dcbb08b8f3df0f2938757c88782f68 Mon Sep 17 00:00:00 2001 From: Ezequiel Werner Date: Wed, 26 Feb 2025 10:52:32 -0300 Subject: [PATCH 05/12] javadoc --- .../runtime/http/api/client/HttpClient.java | 6 ++ .../client/sse/ServerSentEventListener.java | 11 ++++ .../api/client/sse/ServerSentEventSource.java | 20 +++++- .../http/api/domain/sse/ServerSentEvent.java | 26 ++++++-- .../http/api/server/sse/SseClient.java | 65 +++++++++++++++++++ .../http/api/server/sse/SseClientHandler.java | 10 ++- .../http/api/server/sse/SseSender.java | 16 ----- 7 files changed, 132 insertions(+), 22 deletions(-) create mode 100644 modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClient.java delete mode 100644 modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseSender.java diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java index e48a430adf58..ed60ced3913d 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java @@ -168,6 +168,12 @@ default CompletableFuture openWebSocket(HttpRequest request, throw new UnsupportedOperationException("WebSockets are only supported in Enterprise Edition"); } + /** + * Creates a consumer of Server-sent events. The resulting {@link ServerSentEventSource} is not connected automatically. + * + * @param url the URL of the server. + * @return a non-connected instance of {@link ServerSentEventSource}. + */ default ServerSentEventSource sseSource(String url) { throw new UnsupportedOperationException("Server-sent Events are not supported"); } diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventListener.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventListener.java index fa6ca9f0b4e2..f1a43de8cfa7 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventListener.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventListener.java @@ -8,13 +8,24 @@ import org.mule.runtime.http.api.domain.sse.ServerSentEvent; +/** + * An observer of server-sent events. + */ public interface ServerSentEventListener { + // TODO: Move to another class, this one should only handle events. default void onOpen() {} + // TODO: Move to another class, this one should only handle events. default void onClose() {} + // TODO: Move to another class, this one should only handle events. default void onError(Throwable error) {} + /** + * Method to be invoked for each received {@link ServerSentEvent}. + * + * @param event the received event. + */ default void onEvent(ServerSentEvent event) {} } diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventSource.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventSource.java index 1c7d385c5f9e..6f07194f29dc 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventSource.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventSource.java @@ -6,9 +6,27 @@ */ package org.mule.runtime.http.api.client.sse; +/** + * A consumer of server-sent events. + */ public interface ServerSentEventSource { + // TODO: Reconnection void connect(); - void addListener(ServerSentEventListener listener); + /** + * Registers a {@link ServerSentEventListener listener} for a specific event name (a.k.a. topic, a.k.a. type). + * + * @param eventName The event name that the {@link ServerSentEventListener listener} will handle. + * @param listener The event handler. + */ + void register(String eventName, ServerSentEventListener listener); + + /** + * Registers a fallback {@link ServerSentEventListener listener} for all the events that aren't handled by any listener + * registered with {@link #register(String, ServerSentEventListener)}. + * + * @param listener The event handler. + */ + void register(ServerSentEventListener listener); } diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEvent.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEvent.java index b39aeacc09e3..9ea1f6dd31b7 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEvent.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEvent.java @@ -10,6 +10,9 @@ import java.io.Serializable; import java.util.Objects; +/** + * Server-sent event. + */ public class ServerSentEvent implements Serializable { @Serial @@ -17,28 +20,43 @@ public class ServerSentEvent implements Serializable { private final String eventName; private final String eventData; + private final String id; - public ServerSentEvent(String eventName, String eventData) { + public ServerSentEvent(String eventName, String eventData, String id) { this.eventName = eventName; this.eventData = eventData; + this.id = id; } + /** + * @return the event name, the topic of the event. + */ public String getEventName() { return eventName; } + /** + * @return the full data as string. // TODO: Add a method to iterate line-by-line. + */ public String getEventData() { return eventData; } + /** + * @return event id. + */ + public String getId() { + return id; + } + @Override public String toString() { - return "ServerSentEvent [eventName=" + eventName + ", eventData=" + eventData + "]"; + return "ServerSentEvent [name=" + eventName + ", data=" + eventData + ", id=" + id + "]"; } @Override public int hashCode() { - return Objects.hashCode(eventName) + Objects.hashCode(eventData); + return Objects.hashCode(eventName) + Objects.hashCode(eventData) + Objects.hashCode(id); } @Override @@ -47,6 +65,6 @@ public boolean equals(Object o) { return false; } ServerSentEvent that = (ServerSentEvent) o; - return Objects.equals(eventName, that.eventName) && Objects.equals(eventData, that.eventData); + return Objects.equals(eventName, that.eventName) && Objects.equals(eventData, that.eventData) && Objects.equals(id, that.id); } } diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClient.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClient.java new file mode 100644 index 000000000000..cba1cb60e04b --- /dev/null +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClient.java @@ -0,0 +1,65 @@ +/* + * Copyright 2023 Salesforce, Inc. All rights reserved. + * The software in this package is published under the terms of the CPAL v1.0 + * license, a copy of which has been included with this distribution in the + * LICENSE.txt file. + */ +package org.mule.runtime.http.api.server.sse; + +import java.io.IOException; + +/** + * Server-side abstraction of a connected client. + */ +public interface SseClient extends AutoCloseable { + + /** + * Sends an event to the client represented by this interface. + * + * @param name the event name (topic). + * @param data the data as string. + * @param id event id (used to resume an event stream on reconnection). + */ + void sendEvent(String name, String data, String id) throws IOException; + + /** + * Equivalent to call {@code sendEvent(name, data, null);} + * + * @param name the event name (topic). + * @param data the data as string. + */ + default void sendEvent(String name, String data) throws IOException { + sendEvent(name, data, null); + } + + /** + * Equivalent to call {@code sendEvent("message", data, null);} + *

+ * Note: If you want to send a message without topic, you can call {@code sendEvent(null, data);} + * + * @param data the data as string. + */ + default void sendEvent(String data) throws IOException { + sendEvent("message", data, null); + } + + /** + * Sends a comment. + * + * @param comment the comment. TODO: What's the format of a "comment"?. + */ + void sendComment(String comment); + + /** + * The callback will be called when the client closes its connection. + * + * @param callback to be called when the client closes its connection. + */ + void onClose(Runnable callback); + + /** + * Closes the connection. + */ + @Override + void close() throws IOException; +} diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClientHandler.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClientHandler.java index f3d2f48730c6..164d1f2b20ab 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClientHandler.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClientHandler.java @@ -6,7 +6,15 @@ */ package org.mule.runtime.http.api.server.sse; +/** + * Server-side of client connections. + */ public interface SseClientHandler { - void handle(SseSender sender); + /** + * Callback to be invoked when each client is connected. + * + * @param sseClient server-side abstraction of a connected client. + */ + void handle(SseClient sseClient); } diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseSender.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseSender.java deleted file mode 100644 index ac1c236a3bd4..000000000000 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseSender.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2023 Salesforce, Inc. All rights reserved. - * The software in this package is published under the terms of the CPAL v1.0 - * license, a copy of which has been included with this distribution in the - * LICENSE.txt file. - */ -package org.mule.runtime.http.api.server.sse; - -import java.io.IOException; - -public interface SseSender { - - void sendEvent(String eventName, Object payload) throws IOException; - - void finishStream() throws IOException; -} From 8354cbbff6fab3b66aa13c24af6ad8085ba0ab67 Mon Sep 17 00:00:00 2001 From: Ezequiel Werner Date: Wed, 26 Feb 2025 17:20:32 -0300 Subject: [PATCH 06/12] asd --- .../api/http/HttpServiceApiDelegate.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServiceApiDelegate.java diff --git a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServiceApiDelegate.java b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServiceApiDelegate.java new file mode 100644 index 000000000000..05bab51e25e6 --- /dev/null +++ b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServiceApiDelegate.java @@ -0,0 +1,17 @@ +/* + * Copyright 2023 Salesforce, Inc. All rights reserved. + * The software in this package is published under the terms of the CPAL v1.0 + * license, a copy of which has been included with this distribution in the + * LICENSE.txt file. + */ +package org.mule.runtime.module.extension.api.http; + +import org.mule.sdk.api.http.HttpServiceApi; + +public class HttpServiceApiDelegate implements HttpServiceApi { + + @Override + public void printThis(String message) { + System.out.println("I'm the implementation, and your message is: " + message); + } +} From 1c8ce868045bdf4f7b1c9c2ceea708c6911c8d55 Mon Sep 17 00:00:00 2001 From: Ezequiel Werner Date: Thu, 27 Feb 2025 16:13:15 -0300 Subject: [PATCH 07/12] asd --- .../core/api/config/MuleProperties.java | 1 + .../builders/MinimalConfigurationBuilder.java | 13 ++++ .../src/main/java/module-info.java | 1 + .../api/http/HttpServiceApiDelegate.java | 9 +++ .../SpringMuleContextServiceConfigurator.java | 60 ++----------------- 5 files changed, 30 insertions(+), 54 deletions(-) diff --git a/core/src/main/java/org/mule/runtime/core/api/config/MuleProperties.java b/core/src/main/java/org/mule/runtime/core/api/config/MuleProperties.java index 7456bc31cc7e..bdc974760c68 100644 --- a/core/src/main/java/org/mule/runtime/core/api/config/MuleProperties.java +++ b/core/src/main/java/org/mule/runtime/core/api/config/MuleProperties.java @@ -249,6 +249,7 @@ public class MuleProperties { public static final String SERVER_NOTIFICATION_MANAGER = "_serverNotificationManager"; public static final String OBJECT_ARTIFACT_TYPE_LOADER = "_artifactTypeLoader"; public static final String INTERCEPTOR_MANAGER_REGISTRY_KEY = "_muleInterceptorManager"; + public static final String MULE_HTTP_SERVICE_API_REGISTRY_KEY = "_httpServiceApi"; // Not currently used as these need to be instance variables of the MuleContext. public static final String OBJECT_NOTIFICATION_MANAGER = "_muleNotificationManager"; diff --git a/core/src/main/java/org/mule/runtime/core/internal/config/builders/MinimalConfigurationBuilder.java b/core/src/main/java/org/mule/runtime/core/internal/config/builders/MinimalConfigurationBuilder.java index d80c60274f84..c4b9540051d9 100644 --- a/core/src/main/java/org/mule/runtime/core/internal/config/builders/MinimalConfigurationBuilder.java +++ b/core/src/main/java/org/mule/runtime/core/internal/config/builders/MinimalConfigurationBuilder.java @@ -16,6 +16,7 @@ import static org.mule.runtime.core.api.config.MuleProperties.MULE_CORE_EVENT_TRACER_KEY; import static org.mule.runtime.core.api.config.MuleProperties.MULE_CORE_EXPORTER_FACTORY_KEY; import static org.mule.runtime.core.api.config.MuleProperties.MULE_ERROR_METRICS_FACTORY_KEY; +import static org.mule.runtime.core.api.config.MuleProperties.MULE_HTTP_SERVICE_API_REGISTRY_KEY; import static org.mule.runtime.core.api.config.MuleProperties.MULE_METER_PROVIDER_KEY; import static org.mule.runtime.core.api.config.MuleProperties.MULE_PROFILING_SERVICE_KEY; import static org.mule.runtime.core.api.config.MuleProperties.MULE_SPAN_EXPORTER_CONFIGURATION_KEY; @@ -116,6 +117,7 @@ import org.mule.runtime.tracer.api.EventTracer; import org.mule.runtime.tracer.api.component.ComponentTracerFactory; import org.mule.runtime.tracer.exporter.api.SpanExporterFactory; +import org.mule.sdk.api.http.HttpServiceApi; import java.io.Serializable; import java.util.HashSet; @@ -374,4 +376,15 @@ protected void configureSpanExporterConfiguration(MuleContext muleContext) throw registerObject(MULE_SPAN_EXPORTER_CONFIGURATION_KEY, new EmptySpanExporterConfiguration(), muleContext); } + protected void registerHttpServiceApi(MuleContext muleContext) throws RegistrationException { + registerObject(MULE_HTTP_SERVICE_API_REGISTRY_KEY, new NoopHttpServiceApi(), muleContext); + } + + private static class NoopHttpServiceApi implements HttpServiceApi { + + @Override + public void printThis(String message) { + System.out.println("THIS IS THE NOOP SERVICE"); + } + } } diff --git a/modules/extensions-support/src/main/java/module-info.java b/modules/extensions-support/src/main/java/module-info.java index 9f425e5a64b0..6f015e05c7f4 100644 --- a/modules/extensions-support/src/main/java/module-info.java +++ b/modules/extensions-support/src/main/java/module-info.java @@ -215,6 +215,7 @@ opens org.mule.runtime.module.extension.internal.resources.documentation to jakarta.xml.bind; + exports org.mule.runtime.module.extension.api.http; provides org.mule.runtime.api.connectivity.ConnectivityTestingStrategy with org.mule.runtime.module.extension.api.tooling.ExtensionConnectivityTestingStrategy; diff --git a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServiceApiDelegate.java b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServiceApiDelegate.java index 05bab51e25e6..59c46fbbb9a6 100644 --- a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServiceApiDelegate.java +++ b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServiceApiDelegate.java @@ -6,10 +6,19 @@ */ package org.mule.runtime.module.extension.api.http; +import org.mule.runtime.http.api.HttpService; import org.mule.sdk.api.http.HttpServiceApi; +import javax.inject.Inject; + +/** + * Definition of {@link HttpServiceApi} that just delegates all to the {@link HttpService}. + */ public class HttpServiceApiDelegate implements HttpServiceApi { + @Inject + private HttpService delegate; + @Override public void printThis(String message) { System.out.println("I'm the implementation, and your message is: " + message); diff --git a/modules/spring-config/src/main/java/org/mule/runtime/config/internal/context/SpringMuleContextServiceConfigurator.java b/modules/spring-config/src/main/java/org/mule/runtime/config/internal/context/SpringMuleContextServiceConfigurator.java index e8300244abbb..609169ac4043 100644 --- a/modules/spring-config/src/main/java/org/mule/runtime/config/internal/context/SpringMuleContextServiceConfigurator.java +++ b/modules/spring-config/src/main/java/org/mule/runtime/config/internal/context/SpringMuleContextServiceConfigurator.java @@ -15,60 +15,7 @@ import static org.mule.runtime.api.value.ValueProviderService.VALUE_PROVIDER_SERVICE_KEY; import static org.mule.runtime.config.api.LazyComponentInitializer.LAZY_COMPONENT_INITIALIZER_SERVICE_KEY; import static org.mule.runtime.core.api.config.MuleDeploymentProperties.MULE_ADD_ARTIFACT_AST_TO_REGISTRY_DEPLOYMENT_PROPERTY; -import static org.mule.runtime.core.api.config.MuleProperties.FORWARD_COMPATIBILITY_HELPER_KEY; -import static org.mule.runtime.core.api.config.MuleProperties.INTERCEPTOR_MANAGER_REGISTRY_KEY; -import static org.mule.runtime.core.api.config.MuleProperties.LOCAL_OBJECT_LOCK_FACTORY; -import static org.mule.runtime.core.api.config.MuleProperties.LOCAL_OBJECT_STORE_MANAGER; -import static org.mule.runtime.core.api.config.MuleProperties.MULE_ARTIFACT_METER_PROVIDER_KEY; -import static org.mule.runtime.core.api.config.MuleProperties.MULE_CORE_COMPONENT_TRACER_FACTORY_KEY; -import static org.mule.runtime.core.api.config.MuleProperties.MULE_CORE_EVENT_TRACER_KEY; -import static org.mule.runtime.core.api.config.MuleProperties.MULE_CORE_EXPORTER_FACTORY_KEY; -import static org.mule.runtime.core.api.config.MuleProperties.MULE_CORE_SPAN_FACTORY_KEY; -import static org.mule.runtime.core.api.config.MuleProperties.MULE_ERROR_METRICS_FACTORY_KEY; -import static org.mule.runtime.core.api.config.MuleProperties.MULE_MEMORY_MANAGEMENT_SERVICE; -import static org.mule.runtime.core.api.config.MuleProperties.MULE_METER_EXPORTER_CONFIGURATION_KEY; -import static org.mule.runtime.core.api.config.MuleProperties.MULE_METER_EXPORTER_FACTORY_KEY; -import static org.mule.runtime.core.api.config.MuleProperties.MULE_METER_PROVIDER_KEY; -import static org.mule.runtime.core.api.config.MuleProperties.MULE_PROFILING_SERVICE_KEY; -import static org.mule.runtime.core.api.config.MuleProperties.MULE_SPAN_EXPORTER_CONFIGURATION_KEY; -import static org.mule.runtime.core.api.config.MuleProperties.MULE_TRACER_INITIAL_SPAN_INFO_PROVIDER_KEY; -import static org.mule.runtime.core.api.config.MuleProperties.MULE_TRACING_LEVEL_CONFIGURATION_KEY; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_ARTIFACT_AST; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_CLUSTER_SERVICE; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_COMPONENT_INITIAL_STATE_MANAGER; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_CONFIGURATION_PROPERTIES; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_CONNECTION_MANAGER; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_CONNECTIVITY_TESTER_FACTORY; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_CONVERTER_RESOLVER; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_DEFAULT_MESSAGE_PROCESSING_MANAGER; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_EXCEPTION_LOCATION_PROVIDER; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_EXTENSION_MANAGER; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_LOCAL_QUEUE_MANAGER; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_LOCAL_STORE_IN_MEMORY; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_LOCAL_STORE_PERSISTENT; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_LOCK_FACTORY; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_LOCK_PROVIDER; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_MESSAGE_PROCESSING_FLOW_TRACE_MANAGER; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_MULE_CONFIGURATION; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_MULE_CONTEXT; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_MULE_STREAM_CLOSER_SERVICE; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_NOTIFICATION_DISPATCHER; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_NOTIFICATION_HANDLER; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_OBJECT_NAME_PROCESSOR; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_POLICY_MANAGER; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_PROCESSING_TIME_WATCHER; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_QUEUE_MANAGER; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_RESOURCE_LOCATOR; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_SECURITY_MANAGER; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_STATISTICS; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_STORE_MANAGER; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_STREAMING_GHOST_BUSTER; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_STREAMING_MANAGER; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_TIME_SUPPLIER; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_TRANSACTION_FACTORY_LOCATOR; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_TRANSACTION_MANAGER; -import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_TRANSFORMATION_SERVICE; -import static org.mule.runtime.core.api.config.MuleProperties.SDK_OBJECT_STORE_MANAGER; +import static org.mule.runtime.core.api.config.MuleProperties.*; import static org.mule.runtime.core.api.config.bootstrap.ArtifactType.APP; import static org.mule.runtime.core.api.config.bootstrap.ArtifactType.POLICY; import static org.mule.runtime.core.api.data.sample.SampleDataService.SAMPLE_DATA_SERVICE_KEY; @@ -100,6 +47,7 @@ import org.mule.runtime.config.internal.model.dsl.config.DefaultComponentInitialStateManager; import org.mule.runtime.config.internal.processor.MuleObjectNameProcessor; import org.mule.runtime.config.internal.registry.SpringRegistryBootstrap; +import org.mule.runtime.core.api.MuleContext; import org.mule.runtime.core.api.config.bootstrap.ArtifactType; import org.mule.runtime.core.api.event.EventContextService; import org.mule.runtime.core.api.management.stats.ArtifactMeterProvider; @@ -136,6 +84,7 @@ import org.mule.runtime.core.internal.util.store.DefaultObjectStoreFactoryBean; import org.mule.runtime.core.internal.util.store.MuleObjectStoreManager; import org.mule.runtime.core.internal.value.MuleValueProviderService; +import org.mule.runtime.core.privileged.registry.RegistrationException; import org.mule.runtime.metadata.internal.MuleMetadataService; import org.mule.runtime.metadata.internal.cache.DefaultPersistentMetadataCacheManager; import org.mule.runtime.metrics.api.MeterProvider; @@ -144,6 +93,7 @@ import org.mule.runtime.metrics.exporter.impl.optel.config.OpenTelemetryAutoConfigurableMeterExporterConfiguration; import org.mule.runtime.metrics.impl.DefaultMeterProvider; import org.mule.runtime.metrics.impl.meter.error.DefaultErrorMetricsFactory; +import org.mule.runtime.module.extension.api.http.HttpServiceApiDelegate; import org.mule.runtime.module.extension.api.runtime.compatibility.DefaultForwardCompatibilityHelper; import org.mule.runtime.module.extension.internal.data.sample.MuleSampleDataService; import org.mule.runtime.module.extension.internal.store.SdkObjectStoreManagerAdapter; @@ -154,6 +104,7 @@ import org.mule.runtime.tracer.impl.SelectableCoreEventTracer; import org.mule.runtime.tracer.impl.span.factory.ExecutionSpanFactory; import org.mule.runtime.tracing.level.impl.config.AutoConfigurableTracingLevelConfiguration; +import org.mule.sdk.api.http.HttpServiceApi; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; @@ -256,6 +207,7 @@ public class SpringMuleContextServiceConfigurator extends AbstractSpringMuleCont .put(MULE_TRACER_INITIAL_SPAN_INFO_PROVIDER_KEY, getBeanDefinition(DefaultInitialSpanInfoProvider.class)) .put(PROFILING_FEATURE_MANAGEMENT_SERVICE_KEY, getBeanDefinition(DefaultFeatureManagementService.class)) .put(FORWARD_COMPATIBILITY_HELPER_KEY, getBeanDefinition(DefaultForwardCompatibilityHelper.class)) + .put(MULE_HTTP_SERVICE_API_REGISTRY_KEY, getBeanDefinition(HttpServiceApiDelegate.class)) .build(); // Do not use static field. BeanDefinitions are reused and produce weird behaviour From f382e572cddd2dd93fcc03aeef5a27cf0842976f Mon Sep 17 00:00:00 2001 From: Ezequiel Werner Date: Wed, 5 Mar 2025 19:36:46 -0300 Subject: [PATCH 08/12] step --- .../builders/MinimalConfigurationBuilder.java | 14 ------ .../api/http/HttpClientFactoryWrapper.java | 29 ++++++++++++ .../extension/api/http/HttpClientWrapper.java | 44 +++++++++++++++++++ .../api/http/HttpServiceApiDelegate.java | 26 +++++++++-- modules/http-api/pom.xml | 4 ++ .../http-api/src/main/java/module-info.java | 2 +- .../runtime/http/api/client/HttpClient.java | 6 +-- .../http/api/client/HttpClientFactory.java | 5 ++- .../http/api/client/HttpRequestOptions.java | 2 +- .../api/client/HttpRequestOptionsBuilder.java | 3 +- .../client/sse/ServerSentEventListener.java | 31 ------------- .../api/client/sse/ServerSentEventSource.java | 32 -------------- ...entEvent.java => ServerSentEventImpl.java} | 6 +-- 13 files changed, 114 insertions(+), 90 deletions(-) create mode 100644 modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpClientFactoryWrapper.java create mode 100644 modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpClientWrapper.java delete mode 100644 modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventListener.java delete mode 100644 modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventSource.java rename modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/{ServerSentEvent.java => ServerSentEventImpl.java} (86%) diff --git a/core/src/main/java/org/mule/runtime/core/internal/config/builders/MinimalConfigurationBuilder.java b/core/src/main/java/org/mule/runtime/core/internal/config/builders/MinimalConfigurationBuilder.java index c4b9540051d9..6d595cc40ef3 100644 --- a/core/src/main/java/org/mule/runtime/core/internal/config/builders/MinimalConfigurationBuilder.java +++ b/core/src/main/java/org/mule/runtime/core/internal/config/builders/MinimalConfigurationBuilder.java @@ -16,7 +16,6 @@ import static org.mule.runtime.core.api.config.MuleProperties.MULE_CORE_EVENT_TRACER_KEY; import static org.mule.runtime.core.api.config.MuleProperties.MULE_CORE_EXPORTER_FACTORY_KEY; import static org.mule.runtime.core.api.config.MuleProperties.MULE_ERROR_METRICS_FACTORY_KEY; -import static org.mule.runtime.core.api.config.MuleProperties.MULE_HTTP_SERVICE_API_REGISTRY_KEY; import static org.mule.runtime.core.api.config.MuleProperties.MULE_METER_PROVIDER_KEY; import static org.mule.runtime.core.api.config.MuleProperties.MULE_PROFILING_SERVICE_KEY; import static org.mule.runtime.core.api.config.MuleProperties.MULE_SPAN_EXPORTER_CONFIGURATION_KEY; @@ -117,7 +116,6 @@ import org.mule.runtime.tracer.api.EventTracer; import org.mule.runtime.tracer.api.component.ComponentTracerFactory; import org.mule.runtime.tracer.exporter.api.SpanExporterFactory; -import org.mule.sdk.api.http.HttpServiceApi; import java.io.Serializable; import java.util.HashSet; @@ -375,16 +373,4 @@ protected void configureSpanExporterFactory(MuleContext muleContext) throws Regi protected void configureSpanExporterConfiguration(MuleContext muleContext) throws RegistrationException { registerObject(MULE_SPAN_EXPORTER_CONFIGURATION_KEY, new EmptySpanExporterConfiguration(), muleContext); } - - protected void registerHttpServiceApi(MuleContext muleContext) throws RegistrationException { - registerObject(MULE_HTTP_SERVICE_API_REGISTRY_KEY, new NoopHttpServiceApi(), muleContext); - } - - private static class NoopHttpServiceApi implements HttpServiceApi { - - @Override - public void printThis(String message) { - System.out.println("THIS IS THE NOOP SERVICE"); - } - } } diff --git a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpClientFactoryWrapper.java b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpClientFactoryWrapper.java new file mode 100644 index 000000000000..ef28059c2ab5 --- /dev/null +++ b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpClientFactoryWrapper.java @@ -0,0 +1,29 @@ +/* + * Copyright 2023 Salesforce, Inc. All rights reserved. + * The software in this package is published under the terms of the CPAL v1.0 + * license, a copy of which has been included with this distribution in the + * LICENSE.txt file. + */ +package org.mule.runtime.module.extension.api.http; + +import org.mule.runtime.http.api.client.HttpClientConfiguration; +import org.mule.runtime.http.api.client.HttpRequestOptions; +import org.mule.runtime.http.api.domain.message.request.HttpRequest; +import org.mule.runtime.http.api.domain.message.response.HttpResponse; +import org.mule.sdk.api.http.HttpClient; +import org.mule.sdk.api.http.HttpClientFactory; + +public class HttpClientFactoryWrapper + implements HttpClientFactory { + + private final org.mule.runtime.http.api.client.HttpClientFactory delegate; + + public HttpClientFactoryWrapper(org.mule.runtime.http.api.client.HttpClientFactory delegate) { + this.delegate = delegate; + } + + @Override + public HttpClient create(HttpClientConfiguration configuration) { + return new HttpClientWrapper(delegate.create(configuration)); + } +} diff --git a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpClientWrapper.java b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpClientWrapper.java new file mode 100644 index 000000000000..f668bf427ee6 --- /dev/null +++ b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpClientWrapper.java @@ -0,0 +1,44 @@ +/* + * Copyright 2023 Salesforce, Inc. All rights reserved. + * The software in this package is published under the terms of the CPAL v1.0 + * license, a copy of which has been included with this distribution in the + * LICENSE.txt file. + */ +package org.mule.runtime.module.extension.api.http; + +import org.mule.runtime.http.api.client.HttpRequestOptions; +import org.mule.runtime.http.api.domain.message.request.HttpRequest; +import org.mule.runtime.http.api.domain.message.response.HttpResponse; +import org.mule.sdk.api.http.HttpClient; +import org.mule.sdk.api.http.sse.ServerSentEventSource; + +import java.util.concurrent.CompletableFuture; + +public class HttpClientWrapper implements HttpClient { + + private final org.mule.runtime.http.api.client.HttpClient delegate; + + public HttpClientWrapper(org.mule.runtime.http.api.client.HttpClient delegate) { + this.delegate = delegate; + } + + @Override + public CompletableFuture sendAsync(HttpRequest request, HttpRequestOptions httpRequestOptions) { + return delegate.sendAsync(request, httpRequestOptions); + } + + @Override + public ServerSentEventSource sseSource(String url) { + return delegate.sseSource(url); + } + + @Override + public void start() { + delegate.start(); + } + + @Override + public void stop() { + delegate.stop(); + } +} diff --git a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServiceApiDelegate.java b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServiceApiDelegate.java index 59c46fbbb9a6..2d8d72a48b15 100644 --- a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServiceApiDelegate.java +++ b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServiceApiDelegate.java @@ -7,6 +7,15 @@ package org.mule.runtime.module.extension.api.http; import org.mule.runtime.http.api.HttpService; +import org.mule.runtime.http.api.client.HttpClientConfiguration; +import org.mule.runtime.http.api.client.HttpRequestOptions; +import org.mule.runtime.http.api.client.auth.HttpAuthentication; +import org.mule.runtime.http.api.client.proxy.ProxyConfig; +import org.mule.runtime.http.api.domain.message.request.HttpRequest; +import org.mule.runtime.http.api.domain.message.response.HttpResponse; +import org.mule.runtime.http.api.server.HttpServerFactory; +import org.mule.sdk.api.http.HttpClientFactory; +import org.mule.sdk.api.http.HttpRequestOptionsBuilder; import org.mule.sdk.api.http.HttpServiceApi; import javax.inject.Inject; @@ -14,13 +23,24 @@ /** * Definition of {@link HttpServiceApi} that just delegates all to the {@link HttpService}. */ -public class HttpServiceApiDelegate implements HttpServiceApi { +public class HttpServiceApiDelegate implements + HttpServiceApi, HttpServerFactory, HttpAuthentication, ProxyConfig> { @Inject private HttpService delegate; @Override - public void printThis(String message) { - System.out.println("I'm the implementation, and your message is: " + message); + public HttpClientFactory getClientFactory() { + return new HttpClientFactoryWrapper(delegate.getClientFactory()); + } + + @Override + public HttpServerFactory getServerFactory() { + return delegate.getServerFactory(); + } + + @Override + public HttpRequestOptionsBuilder requestOptionsBuilder() { + return HttpRequestOptions.builder(); } } diff --git a/modules/http-api/pom.xml b/modules/http-api/pom.xml index d5527d964c63..9193a21d8c46 100644 --- a/modules/http-api/pom.xml +++ b/modules/http-api/pom.xml @@ -29,6 +29,10 @@ com.github.ben-manes.caffeine caffeine + + org.mule.sdk + mule-sdk-api + diff --git a/modules/http-api/src/main/java/module-info.java b/modules/http-api/src/main/java/module-info.java index 54740640404e..9234a9f74abb 100644 --- a/modules/http-api/src/main/java/module-info.java +++ b/modules/http-api/src/main/java/module-info.java @@ -17,12 +17,12 @@ // For the deprecated API methods still relying on org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate requires org.mule.runtime.core; requires com.github.benmanes.caffeine; + requires org.mule.sdk.api; exports org.mule.runtime.http.api; exports org.mule.runtime.http.api.client; exports org.mule.runtime.http.api.client.auth; exports org.mule.runtime.http.api.client.proxy; - exports org.mule.runtime.http.api.client.sse; exports org.mule.runtime.http.api.client.ws; exports org.mule.runtime.http.api.domain; exports org.mule.runtime.http.api.domain.entity; diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java index ed60ced3913d..786637e4e3c9 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java @@ -8,11 +8,11 @@ import org.mule.api.annotation.NoImplement; import org.mule.runtime.http.api.client.auth.HttpAuthentication; -import org.mule.runtime.http.api.client.sse.ServerSentEventSource; import org.mule.runtime.http.api.client.ws.WebSocketCallback; import org.mule.runtime.http.api.domain.message.request.HttpRequest; import org.mule.runtime.http.api.domain.message.response.HttpResponse; import org.mule.runtime.http.api.ws.WebSocket; +import org.mule.sdk.api.http.sse.ServerSentEventSource; import java.io.IOException; import java.util.concurrent.CompletableFuture; @@ -28,7 +28,7 @@ * @since 4.0 */ @NoImplement -public interface HttpClient { +public interface HttpClient extends org.mule.sdk.api.http.HttpClient { /** * Fully configures the client, leaving it ready to use. Must be executed before any requests are attempted. @@ -170,7 +170,7 @@ default CompletableFuture openWebSocket(HttpRequest request, /** * Creates a consumer of Server-sent events. The resulting {@link ServerSentEventSource} is not connected automatically. - * + * * @param url the URL of the server. * @return a non-connected instance of {@link ServerSentEventSource}. */ diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClientFactory.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClientFactory.java index abda59ab3857..9744ed721224 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClientFactory.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClientFactory.java @@ -7,6 +7,8 @@ package org.mule.runtime.http.api.client; import org.mule.api.annotation.NoImplement; +import org.mule.runtime.http.api.domain.message.request.HttpRequest; +import org.mule.runtime.http.api.domain.message.response.HttpResponse; /** * Factory object for {@link HttpClient}. @@ -14,7 +16,8 @@ * @since 4.0 */ @NoImplement -public interface HttpClientFactory { +public interface HttpClientFactory + extends org.mule.sdk.api.http.HttpClientFactory { /** * @param configuration the {@link HttpClientConfiguration} specifying the desired client. diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpRequestOptions.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpRequestOptions.java index ee17db39ba45..8f69a14d92a4 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpRequestOptions.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpRequestOptions.java @@ -19,7 +19,7 @@ * @since 4.2 */ @NoImplement -public interface HttpRequestOptions { +public interface HttpRequestOptions extends org.mule.sdk.api.http.HttpRequestOptions { /** * @return a fresh {@link HttpRequestOptionsBuilder} to create instances. diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpRequestOptionsBuilder.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpRequestOptionsBuilder.java index 01cf8c6bdd56..18136ecd97a1 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpRequestOptionsBuilder.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpRequestOptionsBuilder.java @@ -16,7 +16,8 @@ * * @since 4.2 */ -public final class HttpRequestOptionsBuilder { +public final class HttpRequestOptionsBuilder + implements org.mule.sdk.api.http.HttpRequestOptionsBuilder { private int responseTimeout = 30000; private boolean followsRedirect = true; diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventListener.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventListener.java deleted file mode 100644 index f1a43de8cfa7..000000000000 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventListener.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2023 Salesforce, Inc. All rights reserved. - * The software in this package is published under the terms of the CPAL v1.0 - * license, a copy of which has been included with this distribution in the - * LICENSE.txt file. - */ -package org.mule.runtime.http.api.client.sse; - -import org.mule.runtime.http.api.domain.sse.ServerSentEvent; - -/** - * An observer of server-sent events. - */ -public interface ServerSentEventListener { - - // TODO: Move to another class, this one should only handle events. - default void onOpen() {} - - // TODO: Move to another class, this one should only handle events. - default void onClose() {} - - // TODO: Move to another class, this one should only handle events. - default void onError(Throwable error) {} - - /** - * Method to be invoked for each received {@link ServerSentEvent}. - * - * @param event the received event. - */ - default void onEvent(ServerSentEvent event) {} -} diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventSource.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventSource.java deleted file mode 100644 index 6f07194f29dc..000000000000 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/sse/ServerSentEventSource.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2023 Salesforce, Inc. All rights reserved. - * The software in this package is published under the terms of the CPAL v1.0 - * license, a copy of which has been included with this distribution in the - * LICENSE.txt file. - */ -package org.mule.runtime.http.api.client.sse; - -/** - * A consumer of server-sent events. - */ -public interface ServerSentEventSource { - - // TODO: Reconnection - void connect(); - - /** - * Registers a {@link ServerSentEventListener listener} for a specific event name (a.k.a. topic, a.k.a. type). - * - * @param eventName The event name that the {@link ServerSentEventListener listener} will handle. - * @param listener The event handler. - */ - void register(String eventName, ServerSentEventListener listener); - - /** - * Registers a fallback {@link ServerSentEventListener listener} for all the events that aren't handled by any listener - * registered with {@link #register(String, ServerSentEventListener)}. - * - * @param listener The event handler. - */ - void register(ServerSentEventListener listener); -} diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEvent.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEventImpl.java similarity index 86% rename from modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEvent.java rename to modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEventImpl.java index 9ea1f6dd31b7..9960d28751e5 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEvent.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEventImpl.java @@ -13,7 +13,7 @@ /** * Server-sent event. */ -public class ServerSentEvent implements Serializable { +public class ServerSentEventImpl implements Serializable, org.mule.sdk.api.http.sse.ServerSentEvent { @Serial private static final long serialVersionUID = -1211505868025654629L; @@ -22,7 +22,7 @@ public class ServerSentEvent implements Serializable { private final String eventData; private final String id; - public ServerSentEvent(String eventName, String eventData, String id) { + public ServerSentEventImpl(String eventName, String eventData, String id) { this.eventName = eventName; this.eventData = eventData; this.id = id; @@ -64,7 +64,7 @@ public boolean equals(Object o) { if (null == o || getClass() != o.getClass()) { return false; } - ServerSentEvent that = (ServerSentEvent) o; + ServerSentEventImpl that = (ServerSentEventImpl) o; return Objects.equals(eventName, that.eventName) && Objects.equals(eventData, that.eventData) && Objects.equals(id, that.id); } } From 7da6f5805c340b99c91d987d9b49dbd8a6c10e82 Mon Sep 17 00:00:00 2001 From: Ezequiel Werner Date: Fri, 7 Mar 2025 13:42:16 -0300 Subject: [PATCH 09/12] reconnection --- .../module/extension/api/http/HttpClientWrapper.java | 5 +++-- .../java/org/mule/runtime/http/api/client/HttpClient.java | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpClientWrapper.java b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpClientWrapper.java index f668bf427ee6..a91c1c9f19bd 100644 --- a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpClientWrapper.java +++ b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpClientWrapper.java @@ -11,6 +11,7 @@ import org.mule.runtime.http.api.domain.message.response.HttpResponse; import org.mule.sdk.api.http.HttpClient; import org.mule.sdk.api.http.sse.ServerSentEventSource; +import org.mule.sdk.api.http.sse.SseRetryConfig; import java.util.concurrent.CompletableFuture; @@ -28,8 +29,8 @@ public CompletableFuture sendAsync(HttpRequest request, HttpReques } @Override - public ServerSentEventSource sseSource(String url) { - return delegate.sseSource(url); + public ServerSentEventSource sseSource(String url, SseRetryConfig retryConfig) { + return delegate.sseSource(url, retryConfig); } @Override diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java index 786637e4e3c9..231db1d72ab5 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java @@ -13,6 +13,7 @@ import org.mule.runtime.http.api.domain.message.response.HttpResponse; import org.mule.runtime.http.api.ws.WebSocket; import org.mule.sdk.api.http.sse.ServerSentEventSource; +import org.mule.sdk.api.http.sse.SseRetryConfig; import java.io.IOException; import java.util.concurrent.CompletableFuture; @@ -171,10 +172,11 @@ default CompletableFuture openWebSocket(HttpRequest request, /** * Creates a consumer of Server-sent events. The resulting {@link ServerSentEventSource} is not connected automatically. * - * @param url the URL of the server. + * @param url the URL of the server. + * @param retryConfig configuration for the retry mechanism. * @return a non-connected instance of {@link ServerSentEventSource}. */ - default ServerSentEventSource sseSource(String url) { + default ServerSentEventSource sseSource(String url, SseRetryConfig retryConfig) { throw new UnsupportedOperationException("Server-sent Events are not supported"); } } From d54a73505c5ba47ecd44abf0d44cf1a35efae8f6 Mon Sep 17 00:00:00 2001 From: Ezequiel Werner Date: Fri, 7 Mar 2025 17:55:06 -0300 Subject: [PATCH 10/12] opts --- .../api/domain/sse/ServerSentEventImpl.java | 40 ++++++++++++------- .../http/api/server/sse/SseClient.java | 14 ++++++- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEventImpl.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEventImpl.java index 9960d28751e5..698b56bdbff6 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEventImpl.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEventImpl.java @@ -6,9 +6,16 @@ */ package org.mule.runtime.http.api.domain.sse; +import static java.util.Objects.requireNonNull; +import static java.util.Optional.ofNullable; +import static java.util.OptionalLong.empty; +import static java.util.OptionalLong.of; + import java.io.Serial; import java.io.Serializable; import java.util.Objects; +import java.util.Optional; +import java.util.OptionalLong; /** * Server-sent event. @@ -21,37 +28,41 @@ public class ServerSentEventImpl implements Serializable, org.mule.sdk.api.http. private final String eventName; private final String eventData; private final String id; + private final Long retryDelay; + + public ServerSentEventImpl(String eventName, String eventData, String id, Long retryDelay) { + requireNonNull(eventName, "eventName cannot be null"); + requireNonNull(eventData, "eventData cannot be null"); - public ServerSentEventImpl(String eventName, String eventData, String id) { this.eventName = eventName; this.eventData = eventData; this.id = id; + this.retryDelay = retryDelay; } - /** - * @return the event name, the topic of the event. - */ + @Override public String getEventName() { return eventName; } - /** - * @return the full data as string. // TODO: Add a method to iterate line-by-line. - */ + @Override public String getEventData() { return eventData; } - /** - * @return event id. - */ - public String getId() { - return id; + @Override + public Optional getId() { + return ofNullable(id); + } + + @Override + public OptionalLong getRetryDelay() { + return null != retryDelay ? of(retryDelay) : empty(); } @Override public String toString() { - return "ServerSentEvent [name=" + eventName + ", data=" + eventData + ", id=" + id + "]"; + return "ServerSentEvent [name=" + eventName + ", data=" + eventData + ", id=" + id + ", retryDelay=" + retryDelay + "]"; } @Override @@ -65,6 +76,7 @@ public boolean equals(Object o) { return false; } ServerSentEventImpl that = (ServerSentEventImpl) o; - return Objects.equals(eventName, that.eventName) && Objects.equals(eventData, that.eventData) && Objects.equals(id, that.id); + return Objects.equals(eventName, that.eventName) && Objects.equals(eventData, that.eventData) && Objects.equals(id, that.id) + && Objects.equals(retryDelay, that.retryDelay); } } diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClient.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClient.java index cba1cb60e04b..fd7aefccf01d 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClient.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClient.java @@ -16,11 +16,23 @@ public interface SseClient extends AutoCloseable { /** * Sends an event to the client represented by this interface. * + * @param name the event name (topic). + * @param data the data as string. + * @param id event id (used to resume an event stream on reconnection). + * @param retryDelay new retry delay, in milliseconds. + */ + void sendEvent(String name, String data, String id, Long retryDelay) throws IOException; + + /** + * Equivalent to call {@code sendEvent(name, data, id, null);} + * * @param name the event name (topic). * @param data the data as string. * @param id event id (used to resume an event stream on reconnection). */ - void sendEvent(String name, String data, String id) throws IOException; + default void sendEvent(String name, String data, String id) throws IOException { + sendEvent(name, data, id, null); + } /** * Equivalent to call {@code sendEvent(name, data, null);} From fbfceb48e1c89dea3f2ebd35f7bec6cfb0058ca2 Mon Sep 17 00:00:00 2001 From: Ezequiel Werner Date: Mon, 10 Mar 2025 14:05:50 -0300 Subject: [PATCH 11/12] srv --- .../api/http/HttpServerFactoryWrapper.java | 26 +++++++ .../extension/api/http/HttpServerWrapper.java | 65 ++++++++++++++++ .../api/http/HttpServiceApiDelegate.java | 10 ++- .../http-api/src/main/java/module-info.java | 1 - .../runtime/http/api/server/HttpServer.java | 7 +- .../http/api/server/sse/SseClient.java | 77 ------------------- .../http/api/server/sse/SseClientHandler.java | 20 ----- .../api/server/sse/SseHandlerManager.java | 12 --- 8 files changed, 101 insertions(+), 117 deletions(-) create mode 100644 modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServerFactoryWrapper.java create mode 100644 modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServerWrapper.java delete mode 100644 modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClient.java delete mode 100644 modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClientHandler.java delete mode 100644 modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseHandlerManager.java diff --git a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServerFactoryWrapper.java b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServerFactoryWrapper.java new file mode 100644 index 000000000000..581fba855759 --- /dev/null +++ b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServerFactoryWrapper.java @@ -0,0 +1,26 @@ +/* + * Copyright 2023 Salesforce, Inc. All rights reserved. + * The software in this package is published under the terms of the CPAL v1.0 + * license, a copy of which has been included with this distribution in the + * LICENSE.txt file. + */ +package org.mule.runtime.module.extension.api.http; + +import org.mule.runtime.http.api.server.HttpServerConfiguration; +import org.mule.runtime.http.api.server.ServerCreationException; +import org.mule.sdk.api.http.HttpServer; +import org.mule.sdk.api.http.HttpServerFactory; + +public class HttpServerFactoryWrapper implements HttpServerFactory { + + private final org.mule.runtime.http.api.server.HttpServerFactory delegate; + + public HttpServerFactoryWrapper(org.mule.runtime.http.api.server.HttpServerFactory delegate) { + this.delegate = delegate; + } + + @Override + public HttpServer create(HttpServerConfiguration configuration) throws ServerCreationException { + return new HttpServerWrapper(delegate.create(configuration)); + } +} diff --git a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServerWrapper.java b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServerWrapper.java new file mode 100644 index 000000000000..133cd0b316d7 --- /dev/null +++ b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServerWrapper.java @@ -0,0 +1,65 @@ +/* + * Copyright 2023 Salesforce, Inc. All rights reserved. + * The software in this package is published under the terms of the CPAL v1.0 + * license, a copy of which has been included with this distribution in the + * LICENSE.txt file. + */ +package org.mule.runtime.module.extension.api.http; + +import org.mule.sdk.api.http.HttpServer; +import org.mule.sdk.api.http.sse.SseClient; +import org.mule.sdk.api.http.sse.SseHandlerManager; + +import java.io.IOException; +import java.util.function.Consumer; + +public class HttpServerWrapper implements HttpServer { + + org.mule.runtime.http.api.server.HttpServer delegate; + + public HttpServerWrapper(org.mule.runtime.http.api.server.HttpServer delegate) { + this.delegate = delegate; + } + + @Override + public HttpServer start() throws IOException { + delegate.start(); + return this; + } + + @Override + public boolean isStopped() { + return delegate.isStopped(); + } + + @Override + public HttpServer stop() { + delegate.stop(); + return this; + } + + @Override + public void dispose() { + delegate.dispose(); + } + + @Override + public boolean isStopping() { + return delegate.isStopping(); + } + + @Override + public String getHost() { + return delegate.getServerAddress().getIp(); + } + + @Override + public int getPort() { + return delegate.getServerAddress().getPort(); + } + + @Override + public SseHandlerManager sse(String path, Consumer clientHandler) { + return delegate.sse(path, clientHandler); + } +} diff --git a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServiceApiDelegate.java b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServiceApiDelegate.java index 2d8d72a48b15..919f17f8b240 100644 --- a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServiceApiDelegate.java +++ b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServiceApiDelegate.java @@ -13,9 +13,11 @@ import org.mule.runtime.http.api.client.proxy.ProxyConfig; import org.mule.runtime.http.api.domain.message.request.HttpRequest; import org.mule.runtime.http.api.domain.message.response.HttpResponse; -import org.mule.runtime.http.api.server.HttpServerFactory; +import org.mule.runtime.http.api.server.HttpServerConfiguration; +import org.mule.runtime.http.api.server.ServerCreationException; import org.mule.sdk.api.http.HttpClientFactory; import org.mule.sdk.api.http.HttpRequestOptionsBuilder; +import org.mule.sdk.api.http.HttpServerFactory; import org.mule.sdk.api.http.HttpServiceApi; import javax.inject.Inject; @@ -24,7 +26,7 @@ * Definition of {@link HttpServiceApi} that just delegates all to the {@link HttpService}. */ public class HttpServiceApiDelegate implements - HttpServiceApi, HttpServerFactory, HttpAuthentication, ProxyConfig> { + HttpServiceApi, HttpServerFactory, HttpAuthentication, ProxyConfig> { @Inject private HttpService delegate; @@ -35,8 +37,8 @@ public HttpClientFactory getServerFactory() { + return new HttpServerFactoryWrapper(delegate.getServerFactory()); } @Override diff --git a/modules/http-api/src/main/java/module-info.java b/modules/http-api/src/main/java/module-info.java index 9234a9f74abb..1533c00fc032 100644 --- a/modules/http-api/src/main/java/module-info.java +++ b/modules/http-api/src/main/java/module-info.java @@ -35,7 +35,6 @@ exports org.mule.runtime.http.api.exception; exports org.mule.runtime.http.api.server; exports org.mule.runtime.http.api.server.async; - exports org.mule.runtime.http.api.server.sse; exports org.mule.runtime.http.api.server.ws; exports org.mule.runtime.http.api.utils; exports org.mule.runtime.http.api.tcp; diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/HttpServer.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/HttpServer.java index 29af3052b65d..84ab2192d2ec 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/HttpServer.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/HttpServer.java @@ -9,13 +9,14 @@ import org.mule.api.annotation.NoImplement; import org.mule.runtime.api.tls.TlsContextFactory; import org.mule.runtime.http.api.HttpConstants.Protocol; -import org.mule.runtime.http.api.server.sse.SseClientHandler; -import org.mule.runtime.http.api.server.sse.SseHandlerManager; import org.mule.runtime.http.api.server.ws.WebSocketHandler; import org.mule.runtime.http.api.server.ws.WebSocketHandlerManager; +import org.mule.sdk.api.http.sse.SseClient; +import org.mule.sdk.api.http.sse.SseHandlerManager; import java.io.IOException; import java.util.Collection; +import java.util.function.Consumer; /** * Represents a ServerSocket connection. Notice it should be started to be bound, stopped to be unbound and finally disposed to @@ -120,7 +121,7 @@ default WebSocketHandlerManager addWebSocketHandler(WebSocketHandler handler) { throw new UnsupportedOperationException("WebSockets are only supported in Enterprise Edition"); } - default SseHandlerManager sse(String ssePath, SseClientHandler sseClientHandler) { + default SseHandlerManager sse(String ssePath, Consumer sseClientHandler) { throw new UnsupportedOperationException("Server-sent events are not supported"); } } diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClient.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClient.java deleted file mode 100644 index fd7aefccf01d..000000000000 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClient.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2023 Salesforce, Inc. All rights reserved. - * The software in this package is published under the terms of the CPAL v1.0 - * license, a copy of which has been included with this distribution in the - * LICENSE.txt file. - */ -package org.mule.runtime.http.api.server.sse; - -import java.io.IOException; - -/** - * Server-side abstraction of a connected client. - */ -public interface SseClient extends AutoCloseable { - - /** - * Sends an event to the client represented by this interface. - * - * @param name the event name (topic). - * @param data the data as string. - * @param id event id (used to resume an event stream on reconnection). - * @param retryDelay new retry delay, in milliseconds. - */ - void sendEvent(String name, String data, String id, Long retryDelay) throws IOException; - - /** - * Equivalent to call {@code sendEvent(name, data, id, null);} - * - * @param name the event name (topic). - * @param data the data as string. - * @param id event id (used to resume an event stream on reconnection). - */ - default void sendEvent(String name, String data, String id) throws IOException { - sendEvent(name, data, id, null); - } - - /** - * Equivalent to call {@code sendEvent(name, data, null);} - * - * @param name the event name (topic). - * @param data the data as string. - */ - default void sendEvent(String name, String data) throws IOException { - sendEvent(name, data, null); - } - - /** - * Equivalent to call {@code sendEvent("message", data, null);} - *

- * Note: If you want to send a message without topic, you can call {@code sendEvent(null, data);} - * - * @param data the data as string. - */ - default void sendEvent(String data) throws IOException { - sendEvent("message", data, null); - } - - /** - * Sends a comment. - * - * @param comment the comment. TODO: What's the format of a "comment"?. - */ - void sendComment(String comment); - - /** - * The callback will be called when the client closes its connection. - * - * @param callback to be called when the client closes its connection. - */ - void onClose(Runnable callback); - - /** - * Closes the connection. - */ - @Override - void close() throws IOException; -} diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClientHandler.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClientHandler.java deleted file mode 100644 index 164d1f2b20ab..000000000000 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseClientHandler.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2023 Salesforce, Inc. All rights reserved. - * The software in this package is published under the terms of the CPAL v1.0 - * license, a copy of which has been included with this distribution in the - * LICENSE.txt file. - */ -package org.mule.runtime.http.api.server.sse; - -/** - * Server-side of client connections. - */ -public interface SseClientHandler { - - /** - * Callback to be invoked when each client is connected. - * - * @param sseClient server-side abstraction of a connected client. - */ - void handle(SseClient sseClient); -} diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseHandlerManager.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseHandlerManager.java deleted file mode 100644 index 2d624d0845f7..000000000000 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/sse/SseHandlerManager.java +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright 2023 Salesforce, Inc. All rights reserved. - * The software in this package is published under the terms of the CPAL v1.0 - * license, a copy of which has been included with this distribution in the - * LICENSE.txt file. - */ -package org.mule.runtime.http.api.server.sse; - -public interface SseHandlerManager { - - // start stop blah -} From a8bf68dc7d06c2add0b5d9f45ff91f7516b70239 Mon Sep 17 00:00:00 2001 From: Ezequiel Werner Date: Tue, 11 Mar 2025 12:50:26 -0300 Subject: [PATCH 12/12] sse only --- .../builders/MinimalConfigurationBuilder.java | 1 + .../api/http/HttpClientFactoryWrapper.java | 29 --------- .../extension/api/http/HttpClientWrapper.java | 45 ------------- .../api/http/HttpServerFactoryWrapper.java | 26 -------- .../extension/api/http/HttpServerWrapper.java | 65 ------------------- .../api/http/HttpServiceApiDelegate.java | 38 ++++------- .../runtime/http/api/client/HttpClient.java | 6 +- .../http/api/client/HttpClientFactory.java | 5 +- .../http/api/client/HttpRequestOptions.java | 2 +- .../api/client/HttpRequestOptionsBuilder.java | 3 +- .../api/domain/sse/ServerSentEventImpl.java | 2 + .../runtime/http/api/server/HttpServer.java | 15 ++++- .../SpringMuleContextServiceConfigurator.java | 60 +++++++++++++++-- 13 files changed, 90 insertions(+), 207 deletions(-) delete mode 100644 modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpClientFactoryWrapper.java delete mode 100644 modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpClientWrapper.java delete mode 100644 modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServerFactoryWrapper.java delete mode 100644 modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServerWrapper.java diff --git a/core/src/main/java/org/mule/runtime/core/internal/config/builders/MinimalConfigurationBuilder.java b/core/src/main/java/org/mule/runtime/core/internal/config/builders/MinimalConfigurationBuilder.java index 6d595cc40ef3..d80c60274f84 100644 --- a/core/src/main/java/org/mule/runtime/core/internal/config/builders/MinimalConfigurationBuilder.java +++ b/core/src/main/java/org/mule/runtime/core/internal/config/builders/MinimalConfigurationBuilder.java @@ -373,4 +373,5 @@ protected void configureSpanExporterFactory(MuleContext muleContext) throws Regi protected void configureSpanExporterConfiguration(MuleContext muleContext) throws RegistrationException { registerObject(MULE_SPAN_EXPORTER_CONFIGURATION_KEY, new EmptySpanExporterConfiguration(), muleContext); } + } diff --git a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpClientFactoryWrapper.java b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpClientFactoryWrapper.java deleted file mode 100644 index ef28059c2ab5..000000000000 --- a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpClientFactoryWrapper.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2023 Salesforce, Inc. All rights reserved. - * The software in this package is published under the terms of the CPAL v1.0 - * license, a copy of which has been included with this distribution in the - * LICENSE.txt file. - */ -package org.mule.runtime.module.extension.api.http; - -import org.mule.runtime.http.api.client.HttpClientConfiguration; -import org.mule.runtime.http.api.client.HttpRequestOptions; -import org.mule.runtime.http.api.domain.message.request.HttpRequest; -import org.mule.runtime.http.api.domain.message.response.HttpResponse; -import org.mule.sdk.api.http.HttpClient; -import org.mule.sdk.api.http.HttpClientFactory; - -public class HttpClientFactoryWrapper - implements HttpClientFactory { - - private final org.mule.runtime.http.api.client.HttpClientFactory delegate; - - public HttpClientFactoryWrapper(org.mule.runtime.http.api.client.HttpClientFactory delegate) { - this.delegate = delegate; - } - - @Override - public HttpClient create(HttpClientConfiguration configuration) { - return new HttpClientWrapper(delegate.create(configuration)); - } -} diff --git a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpClientWrapper.java b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpClientWrapper.java deleted file mode 100644 index a91c1c9f19bd..000000000000 --- a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpClientWrapper.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2023 Salesforce, Inc. All rights reserved. - * The software in this package is published under the terms of the CPAL v1.0 - * license, a copy of which has been included with this distribution in the - * LICENSE.txt file. - */ -package org.mule.runtime.module.extension.api.http; - -import org.mule.runtime.http.api.client.HttpRequestOptions; -import org.mule.runtime.http.api.domain.message.request.HttpRequest; -import org.mule.runtime.http.api.domain.message.response.HttpResponse; -import org.mule.sdk.api.http.HttpClient; -import org.mule.sdk.api.http.sse.ServerSentEventSource; -import org.mule.sdk.api.http.sse.SseRetryConfig; - -import java.util.concurrent.CompletableFuture; - -public class HttpClientWrapper implements HttpClient { - - private final org.mule.runtime.http.api.client.HttpClient delegate; - - public HttpClientWrapper(org.mule.runtime.http.api.client.HttpClient delegate) { - this.delegate = delegate; - } - - @Override - public CompletableFuture sendAsync(HttpRequest request, HttpRequestOptions httpRequestOptions) { - return delegate.sendAsync(request, httpRequestOptions); - } - - @Override - public ServerSentEventSource sseSource(String url, SseRetryConfig retryConfig) { - return delegate.sseSource(url, retryConfig); - } - - @Override - public void start() { - delegate.start(); - } - - @Override - public void stop() { - delegate.stop(); - } -} diff --git a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServerFactoryWrapper.java b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServerFactoryWrapper.java deleted file mode 100644 index 581fba855759..000000000000 --- a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServerFactoryWrapper.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2023 Salesforce, Inc. All rights reserved. - * The software in this package is published under the terms of the CPAL v1.0 - * license, a copy of which has been included with this distribution in the - * LICENSE.txt file. - */ -package org.mule.runtime.module.extension.api.http; - -import org.mule.runtime.http.api.server.HttpServerConfiguration; -import org.mule.runtime.http.api.server.ServerCreationException; -import org.mule.sdk.api.http.HttpServer; -import org.mule.sdk.api.http.HttpServerFactory; - -public class HttpServerFactoryWrapper implements HttpServerFactory { - - private final org.mule.runtime.http.api.server.HttpServerFactory delegate; - - public HttpServerFactoryWrapper(org.mule.runtime.http.api.server.HttpServerFactory delegate) { - this.delegate = delegate; - } - - @Override - public HttpServer create(HttpServerConfiguration configuration) throws ServerCreationException { - return new HttpServerWrapper(delegate.create(configuration)); - } -} diff --git a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServerWrapper.java b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServerWrapper.java deleted file mode 100644 index 133cd0b316d7..000000000000 --- a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServerWrapper.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2023 Salesforce, Inc. All rights reserved. - * The software in this package is published under the terms of the CPAL v1.0 - * license, a copy of which has been included with this distribution in the - * LICENSE.txt file. - */ -package org.mule.runtime.module.extension.api.http; - -import org.mule.sdk.api.http.HttpServer; -import org.mule.sdk.api.http.sse.SseClient; -import org.mule.sdk.api.http.sse.SseHandlerManager; - -import java.io.IOException; -import java.util.function.Consumer; - -public class HttpServerWrapper implements HttpServer { - - org.mule.runtime.http.api.server.HttpServer delegate; - - public HttpServerWrapper(org.mule.runtime.http.api.server.HttpServer delegate) { - this.delegate = delegate; - } - - @Override - public HttpServer start() throws IOException { - delegate.start(); - return this; - } - - @Override - public boolean isStopped() { - return delegate.isStopped(); - } - - @Override - public HttpServer stop() { - delegate.stop(); - return this; - } - - @Override - public void dispose() { - delegate.dispose(); - } - - @Override - public boolean isStopping() { - return delegate.isStopping(); - } - - @Override - public String getHost() { - return delegate.getServerAddress().getIp(); - } - - @Override - public int getPort() { - return delegate.getServerAddress().getPort(); - } - - @Override - public SseHandlerManager sse(String path, Consumer clientHandler) { - return delegate.sse(path, clientHandler); - } -} diff --git a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServiceApiDelegate.java b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServiceApiDelegate.java index 919f17f8b240..ca56bacc7402 100644 --- a/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServiceApiDelegate.java +++ b/modules/extensions-support/src/main/java/org/mule/runtime/module/extension/api/http/HttpServiceApiDelegate.java @@ -7,42 +7,28 @@ package org.mule.runtime.module.extension.api.http; import org.mule.runtime.http.api.HttpService; -import org.mule.runtime.http.api.client.HttpClientConfiguration; -import org.mule.runtime.http.api.client.HttpRequestOptions; -import org.mule.runtime.http.api.client.auth.HttpAuthentication; -import org.mule.runtime.http.api.client.proxy.ProxyConfig; -import org.mule.runtime.http.api.domain.message.request.HttpRequest; -import org.mule.runtime.http.api.domain.message.response.HttpResponse; -import org.mule.runtime.http.api.server.HttpServerConfiguration; -import org.mule.runtime.http.api.server.ServerCreationException; -import org.mule.sdk.api.http.HttpClientFactory; -import org.mule.sdk.api.http.HttpRequestOptionsBuilder; -import org.mule.sdk.api.http.HttpServerFactory; import org.mule.sdk.api.http.HttpServiceApi; +import org.mule.sdk.api.http.sse.ClientWithSse; +import org.mule.sdk.api.http.sse.ServerSentEventSource; +import org.mule.sdk.api.http.sse.ServerWithSse; +import org.mule.sdk.api.http.sse.SseClient; +import org.mule.sdk.api.http.sse.SseEndpointManager; +import org.mule.sdk.api.http.sse.SseRetryConfig; -import javax.inject.Inject; +import java.util.function.Consumer; /** * Definition of {@link HttpServiceApi} that just delegates all to the {@link HttpService}. */ -public class HttpServiceApiDelegate implements - HttpServiceApi, HttpServerFactory, HttpAuthentication, ProxyConfig> { - - @Inject - private HttpService delegate; - - @Override - public HttpClientFactory getClientFactory() { - return new HttpClientFactoryWrapper(delegate.getClientFactory()); - } +public class HttpServiceApiDelegate implements HttpServiceApi { @Override - public HttpServerFactory getServerFactory() { - return new HttpServerFactoryWrapper(delegate.getServerFactory()); + public SseEndpointManager sseEndpoint(ServerWithSse httpServer, String ssePath, Consumer sseClientHandler) { + return httpServer.sse(ssePath, sseClientHandler); } @Override - public HttpRequestOptionsBuilder requestOptionsBuilder() { - return HttpRequestOptions.builder(); + public ServerSentEventSource sseSource(ClientWithSse httpClient, String url, SseRetryConfig retryConfig) { + return httpClient.sseSource(url, retryConfig); } } diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java index 231db1d72ab5..2efc5fc748b5 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClient.java @@ -12,6 +12,7 @@ import org.mule.runtime.http.api.domain.message.request.HttpRequest; import org.mule.runtime.http.api.domain.message.response.HttpResponse; import org.mule.runtime.http.api.ws.WebSocket; +import org.mule.sdk.api.http.sse.ClientWithSse; import org.mule.sdk.api.http.sse.ServerSentEventSource; import org.mule.sdk.api.http.sse.SseRetryConfig; @@ -29,7 +30,7 @@ * @since 4.0 */ @NoImplement -public interface HttpClient extends org.mule.sdk.api.http.HttpClient { +public interface HttpClient extends ClientWithSse { /** * Fully configures the client, leaving it ready to use. Must be executed before any requests are attempted. @@ -175,7 +176,10 @@ default CompletableFuture openWebSocket(HttpRequest request, * @param url the URL of the server. * @param retryConfig configuration for the retry mechanism. * @return a non-connected instance of {@link ServerSentEventSource}. + * + * @since 4.10.0 */ + @Override default ServerSentEventSource sseSource(String url, SseRetryConfig retryConfig) { throw new UnsupportedOperationException("Server-sent Events are not supported"); } diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClientFactory.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClientFactory.java index 9744ed721224..abda59ab3857 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClientFactory.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpClientFactory.java @@ -7,8 +7,6 @@ package org.mule.runtime.http.api.client; import org.mule.api.annotation.NoImplement; -import org.mule.runtime.http.api.domain.message.request.HttpRequest; -import org.mule.runtime.http.api.domain.message.response.HttpResponse; /** * Factory object for {@link HttpClient}. @@ -16,8 +14,7 @@ * @since 4.0 */ @NoImplement -public interface HttpClientFactory - extends org.mule.sdk.api.http.HttpClientFactory { +public interface HttpClientFactory { /** * @param configuration the {@link HttpClientConfiguration} specifying the desired client. diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpRequestOptions.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpRequestOptions.java index 8f69a14d92a4..ee17db39ba45 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpRequestOptions.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpRequestOptions.java @@ -19,7 +19,7 @@ * @since 4.2 */ @NoImplement -public interface HttpRequestOptions extends org.mule.sdk.api.http.HttpRequestOptions { +public interface HttpRequestOptions { /** * @return a fresh {@link HttpRequestOptionsBuilder} to create instances. diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpRequestOptionsBuilder.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpRequestOptionsBuilder.java index 18136ecd97a1..01cf8c6bdd56 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpRequestOptionsBuilder.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/client/HttpRequestOptionsBuilder.java @@ -16,8 +16,7 @@ * * @since 4.2 */ -public final class HttpRequestOptionsBuilder - implements org.mule.sdk.api.http.HttpRequestOptionsBuilder { +public final class HttpRequestOptionsBuilder { private int responseTimeout = 30000; private boolean followsRedirect = true; diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEventImpl.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEventImpl.java index 698b56bdbff6..e7dbe3a2d956 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEventImpl.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/domain/sse/ServerSentEventImpl.java @@ -19,6 +19,8 @@ /** * Server-sent event. + * + * TODO: Move to service... */ public class ServerSentEventImpl implements Serializable, org.mule.sdk.api.http.sse.ServerSentEvent { diff --git a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/HttpServer.java b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/HttpServer.java index 84ab2192d2ec..59e65b0929a6 100644 --- a/modules/http-api/src/main/java/org/mule/runtime/http/api/server/HttpServer.java +++ b/modules/http-api/src/main/java/org/mule/runtime/http/api/server/HttpServer.java @@ -11,8 +11,9 @@ import org.mule.runtime.http.api.HttpConstants.Protocol; import org.mule.runtime.http.api.server.ws.WebSocketHandler; import org.mule.runtime.http.api.server.ws.WebSocketHandlerManager; +import org.mule.sdk.api.http.sse.ServerWithSse; import org.mule.sdk.api.http.sse.SseClient; -import org.mule.sdk.api.http.sse.SseHandlerManager; +import org.mule.sdk.api.http.sse.SseEndpointManager; import java.io.IOException; import java.util.Collection; @@ -26,7 +27,7 @@ * @since 4.0 */ @NoImplement -public interface HttpServer { +public interface HttpServer extends ServerWithSse { /** * Binds the ServerSocket to the network interface and starts listening for requests. @@ -121,7 +122,15 @@ default WebSocketHandlerManager addWebSocketHandler(WebSocketHandler handler) { throw new UnsupportedOperationException("WebSockets are only supported in Enterprise Edition"); } - default SseHandlerManager sse(String ssePath, Consumer sseClientHandler) { + /** + * Adds an endpoint to produce server-sent events. + * + * @param ssePath path to match. + * @param sseClientHandler callback to be executed for each received {@link SseClient}. + * @return an object that can be used to enable/disable/remove the endpoint from the server. + */ + @Override + default SseEndpointManager sse(String ssePath, Consumer sseClientHandler) { throw new UnsupportedOperationException("Server-sent events are not supported"); } } diff --git a/modules/spring-config/src/main/java/org/mule/runtime/config/internal/context/SpringMuleContextServiceConfigurator.java b/modules/spring-config/src/main/java/org/mule/runtime/config/internal/context/SpringMuleContextServiceConfigurator.java index 609169ac4043..8be068ac0f56 100644 --- a/modules/spring-config/src/main/java/org/mule/runtime/config/internal/context/SpringMuleContextServiceConfigurator.java +++ b/modules/spring-config/src/main/java/org/mule/runtime/config/internal/context/SpringMuleContextServiceConfigurator.java @@ -15,7 +15,61 @@ import static org.mule.runtime.api.value.ValueProviderService.VALUE_PROVIDER_SERVICE_KEY; import static org.mule.runtime.config.api.LazyComponentInitializer.LAZY_COMPONENT_INITIALIZER_SERVICE_KEY; import static org.mule.runtime.core.api.config.MuleDeploymentProperties.MULE_ADD_ARTIFACT_AST_TO_REGISTRY_DEPLOYMENT_PROPERTY; -import static org.mule.runtime.core.api.config.MuleProperties.*; +import static org.mule.runtime.core.api.config.MuleProperties.FORWARD_COMPATIBILITY_HELPER_KEY; +import static org.mule.runtime.core.api.config.MuleProperties.INTERCEPTOR_MANAGER_REGISTRY_KEY; +import static org.mule.runtime.core.api.config.MuleProperties.LOCAL_OBJECT_LOCK_FACTORY; +import static org.mule.runtime.core.api.config.MuleProperties.LOCAL_OBJECT_STORE_MANAGER; +import static org.mule.runtime.core.api.config.MuleProperties.MULE_ARTIFACT_METER_PROVIDER_KEY; +import static org.mule.runtime.core.api.config.MuleProperties.MULE_CORE_COMPONENT_TRACER_FACTORY_KEY; +import static org.mule.runtime.core.api.config.MuleProperties.MULE_CORE_EVENT_TRACER_KEY; +import static org.mule.runtime.core.api.config.MuleProperties.MULE_CORE_EXPORTER_FACTORY_KEY; +import static org.mule.runtime.core.api.config.MuleProperties.MULE_CORE_SPAN_FACTORY_KEY; +import static org.mule.runtime.core.api.config.MuleProperties.MULE_ERROR_METRICS_FACTORY_KEY; +import static org.mule.runtime.core.api.config.MuleProperties.MULE_HTTP_SERVICE_API_REGISTRY_KEY; +import static org.mule.runtime.core.api.config.MuleProperties.MULE_MEMORY_MANAGEMENT_SERVICE; +import static org.mule.runtime.core.api.config.MuleProperties.MULE_METER_EXPORTER_CONFIGURATION_KEY; +import static org.mule.runtime.core.api.config.MuleProperties.MULE_METER_EXPORTER_FACTORY_KEY; +import static org.mule.runtime.core.api.config.MuleProperties.MULE_METER_PROVIDER_KEY; +import static org.mule.runtime.core.api.config.MuleProperties.MULE_PROFILING_SERVICE_KEY; +import static org.mule.runtime.core.api.config.MuleProperties.MULE_SPAN_EXPORTER_CONFIGURATION_KEY; +import static org.mule.runtime.core.api.config.MuleProperties.MULE_TRACER_INITIAL_SPAN_INFO_PROVIDER_KEY; +import static org.mule.runtime.core.api.config.MuleProperties.MULE_TRACING_LEVEL_CONFIGURATION_KEY; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_ARTIFACT_AST; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_CLUSTER_SERVICE; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_COMPONENT_INITIAL_STATE_MANAGER; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_CONFIGURATION_PROPERTIES; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_CONNECTION_MANAGER; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_CONNECTIVITY_TESTER_FACTORY; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_CONVERTER_RESOLVER; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_DEFAULT_MESSAGE_PROCESSING_MANAGER; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_EXCEPTION_LOCATION_PROVIDER; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_EXTENSION_MANAGER; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_LOCAL_QUEUE_MANAGER; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_LOCAL_STORE_IN_MEMORY; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_LOCAL_STORE_PERSISTENT; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_LOCK_FACTORY; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_LOCK_PROVIDER; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_MESSAGE_PROCESSING_FLOW_TRACE_MANAGER; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_MULE_CONFIGURATION; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_MULE_CONTEXT; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_MULE_STREAM_CLOSER_SERVICE; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_NOTIFICATION_DISPATCHER; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_NOTIFICATION_HANDLER; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_OBJECT_NAME_PROCESSOR; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_POLICY_MANAGER; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_PROCESSING_TIME_WATCHER; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_QUEUE_MANAGER; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_RESOURCE_LOCATOR; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_SECURITY_MANAGER; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_STATISTICS; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_STORE_MANAGER; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_STREAMING_GHOST_BUSTER; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_STREAMING_MANAGER; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_TIME_SUPPLIER; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_TRANSACTION_FACTORY_LOCATOR; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_TRANSACTION_MANAGER; +import static org.mule.runtime.core.api.config.MuleProperties.OBJECT_TRANSFORMATION_SERVICE; +import static org.mule.runtime.core.api.config.MuleProperties.SDK_OBJECT_STORE_MANAGER; import static org.mule.runtime.core.api.config.bootstrap.ArtifactType.APP; import static org.mule.runtime.core.api.config.bootstrap.ArtifactType.POLICY; import static org.mule.runtime.core.api.data.sample.SampleDataService.SAMPLE_DATA_SERVICE_KEY; @@ -47,7 +101,6 @@ import org.mule.runtime.config.internal.model.dsl.config.DefaultComponentInitialStateManager; import org.mule.runtime.config.internal.processor.MuleObjectNameProcessor; import org.mule.runtime.config.internal.registry.SpringRegistryBootstrap; -import org.mule.runtime.core.api.MuleContext; import org.mule.runtime.core.api.config.bootstrap.ArtifactType; import org.mule.runtime.core.api.event.EventContextService; import org.mule.runtime.core.api.management.stats.ArtifactMeterProvider; @@ -84,7 +137,6 @@ import org.mule.runtime.core.internal.util.store.DefaultObjectStoreFactoryBean; import org.mule.runtime.core.internal.util.store.MuleObjectStoreManager; import org.mule.runtime.core.internal.value.MuleValueProviderService; -import org.mule.runtime.core.privileged.registry.RegistrationException; import org.mule.runtime.metadata.internal.MuleMetadataService; import org.mule.runtime.metadata.internal.cache.DefaultPersistentMetadataCacheManager; import org.mule.runtime.metrics.api.MeterProvider; @@ -104,7 +156,6 @@ import org.mule.runtime.tracer.impl.SelectableCoreEventTracer; import org.mule.runtime.tracer.impl.span.factory.ExecutionSpanFactory; import org.mule.runtime.tracing.level.impl.config.AutoConfigurableTracingLevelConfiguration; -import org.mule.sdk.api.http.HttpServiceApi; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; @@ -113,7 +164,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; - import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionRegistry;