Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poc/sse #1009

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft

Poc/sse #1009

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mule-http-connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
<muleHttpPolicyApiVersion>1.1.3</muleHttpPolicyApiVersion>
<mulePolicyApiVersion>1.1.3</mulePolicyApiVersion>
<muleProfilingApiVersion>1.0.0</muleProfilingApiVersion>
<muleSdkCompatibilityApiVersion>0.7.4</muleSdkCompatibilityApiVersion>
<muleSdkApiVersion>0.7.0</muleSdkApiVersion>
<muleSdkCompatibilityApiVersion>0.12.0-SNAPSHOT</muleSdkCompatibilityApiVersion>
<muleSdkApiVersion>0.12.0-SNAPSHOT</muleSdkApiVersion>

<!-- Remove when a new parent version with MTF is available -->
<munit.input.directory>src/test/munit</munit.input.directory>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.extension.http.api;

public class SseClientAttributes {

private final Long clientId;

public SseClientAttributes(Long clientId) {
this.clientId = clientId;
}

public Long getClientId() {
return clientId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.extension.http.api;

import org.mule.sdk.api.http.sse.ServerSentEvent;

public class SseEventAttributes {

private final String eventName;
private final String eventId;
private final Long retryDelay;

public SseEventAttributes(ServerSentEvent event) {
eventName = event.getEventName();
eventId = event.getId().orElse(null);
retryDelay = event.getRetryDelay().isPresent() ? event.getRetryDelay().getAsLong() : null;
}

public String getEventName() {
return eventName;
}

public String getId() {
return eventId;
}

public Long getRetryDelay() {
return retryDelay;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.mule.extension.http.internal.listener.ListenerPath;
import org.mule.extension.http.internal.listener.intercepting.HttpListenerInterceptor;
import org.mule.extension.http.api.listener.intercepting.cors.CorsInterceptorWrapper;
import org.mule.extension.http.internal.sse.SseEndpoint;
import org.mule.runtime.api.lifecycle.Initialisable;
import org.mule.runtime.api.lifecycle.InitialisationException;
import org.mule.runtime.api.util.MultiMap;
Expand All @@ -36,7 +37,7 @@
*/
@Configuration(name = "listenerConfig")
@ConnectionProviders(HttpListenerProvider.class)
@Sources(HttpListener.class)
@Sources({HttpListener.class, SseEndpoint.class})
public class HttpListenerConfig implements Initialisable {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.extension.http.internal.delegate;

import org.mule.extension.http.api.request.proxy.HttpProxyConfig;
import org.mule.runtime.http.api.client.HttpClientConfiguration;
import org.mule.runtime.http.api.client.auth.HttpAuthentication;
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;
import org.mule.sdk.api.http.HttpRequestOptions;

public class HttpClientFactoryWrapper implements
HttpClientFactory<HttpClientConfiguration, HttpRequest, HttpRequestOptions<HttpAuthentication, HttpProxyConfig>, HttpResponse> {

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<HttpRequest, HttpRequestOptions<HttpAuthentication, HttpProxyConfig>, HttpResponse> create(HttpClientConfiguration configuration) {
return new HttpClientWrapper(delegate.create(configuration));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.extension.http.internal.delegate;

import org.mule.extension.http.api.request.proxy.HttpProxyConfig;
import org.mule.runtime.http.api.client.auth.HttpAuthentication;
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.HttpRequestOptions;
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<HttpRequest, HttpRequestOptions<HttpAuthentication, HttpProxyConfig>, HttpResponse> {

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<HttpResponse> sendAsync(HttpRequest request,
HttpRequestOptions<HttpAuthentication, HttpProxyConfig> o) {
// TODO: use reflection client instead
return delegate.sendAsync(request, o.getResponseTimeout(), o.isFollowsRedirect(), o.getAuthentication().orElse(null));
}

@Override
public ServerSentEventSource sseSource(String url, SseRetryConfig retryConfig) {
throw new UnsupportedOperationException("Server-sent events are not supported");
}

@Override
public void start() {
delegate.start();
}

@Override
public void stop() {
delegate.stop();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.extension.http.internal.delegate;

import org.mule.extension.http.api.request.proxy.HttpProxyConfig;
import org.mule.runtime.http.api.client.auth.HttpAuthentication;
import org.mule.sdk.api.http.HttpRequestOptions;
import org.mule.sdk.api.http.HttpRequestOptionsBuilder;

public class HttpRequestOptionsBuilderWrapper implements HttpRequestOptionsBuilder<HttpAuthentication, HttpProxyConfig> {

private int responseTimeout;
private boolean followsRedirect;
private HttpAuthentication authentication;
private HttpProxyConfig proxyConfig;
private boolean sendBodyAlways;

@Override
public HttpRequestOptionsBuilder<HttpAuthentication, HttpProxyConfig> responseTimeout(int responseTimeout) {
this.responseTimeout = responseTimeout;
return this;
}

@Override
public HttpRequestOptionsBuilder<HttpAuthentication, HttpProxyConfig> followsRedirect(boolean followsRedirect) {
this.followsRedirect = followsRedirect;
return this;
}

@Override
public HttpRequestOptionsBuilder<HttpAuthentication, HttpProxyConfig> authentication(HttpAuthentication authentication) {
this.authentication = authentication;
return this;
}

@Override
public HttpRequestOptionsBuilder<HttpAuthentication, HttpProxyConfig> proxyConfig(HttpProxyConfig proxyConfig) {
this.proxyConfig = proxyConfig;
return this;
}

@Override
public HttpRequestOptionsBuilder<HttpAuthentication, HttpProxyConfig> sendBodyAlways(boolean sendBodyAlways) {
this.sendBodyAlways = sendBodyAlways;
return this;
}

@Override
public HttpRequestOptions<HttpAuthentication, HttpProxyConfig> build() {
return new HttpRequestOptionsWrapper(responseTimeout, followsRedirect, authentication, proxyConfig, sendBodyAlways);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.extension.http.internal.delegate;

import org.mule.extension.http.api.request.proxy.HttpProxyConfig;
import org.mule.runtime.http.api.client.auth.HttpAuthentication;
import org.mule.sdk.api.http.HttpRequestOptions;

import java.util.Optional;

public class HttpRequestOptionsWrapper implements HttpRequestOptions<HttpAuthentication, HttpProxyConfig> {

private final int responseTimeout;
private final boolean followsRedirect;
private final HttpAuthentication authentication;
private final HttpProxyConfig proxyConfig;
private final boolean sendBodyAlways;

public HttpRequestOptionsWrapper(int responseTimeout, boolean followsRedirect, HttpAuthentication authentication,
HttpProxyConfig proxyConfig, boolean sendBodyAlways) {
this.responseTimeout = responseTimeout;
this.followsRedirect = followsRedirect;
this.authentication = authentication;
this.proxyConfig = proxyConfig;
this.sendBodyAlways = sendBodyAlways;
}

@Override
public int getResponseTimeout() {
return responseTimeout;
}

@Override
public boolean isFollowsRedirect() {
return followsRedirect;
}

@Override
public Optional<HttpAuthentication> getAuthentication() {
return Optional.ofNullable(authentication);
}

@Override
public boolean shouldSendBodyAlways() {
return sendBodyAlways;
}

@Override
public Optional<HttpProxyConfig> getProxyConfig() {
return Optional.ofNullable(proxyConfig);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.extension.http.internal.delegate;

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<HttpServerConfiguration, ServerCreationException> {

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));
}
}
Original file line number Diff line number Diff line change
@@ -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.extension.http.internal.delegate;

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 {

private final 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<SseClient> clientHandler) {
throw new UnsupportedOperationException("Not implemented yet");
}
}
Loading