[ 
https://issues.apache.org/jira/browse/KNOX-3065?focusedWorklogId=942745&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-942745
 ]

ASF GitHub Bot logged work on KNOX-3065:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 08/Nov/24 09:55
            Start Date: 08/Nov/24 09:55
    Worklog Time Spent: 10m 
      Work Description: hanicz commented on code in PR #947:
URL: https://github.com/apache/knox/pull/947#discussion_r1834047083


##########
gateway-spi/src/main/java/org/apache/knox/gateway/sse/SSEEntity.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.knox.gateway.sse;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.entity.AbstractHttpEntity;
+
+import javax.servlet.AsyncContext;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.CharBuffer;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+public class SSEEntity extends AbstractHttpEntity {
+
+    private static final String SSE_DELIMITER = ":";
+
+    private final BlockingQueue<SSEvent> eventQueue;
+    private final StringBuilder eventBuilder = new StringBuilder();
+    private final HttpEntity httpEntity;
+    private char previousChar = '0';
+
+    public SSEEntity(HttpEntity httpEntity) {
+        this.httpEntity = httpEntity;
+        this.eventQueue = new LinkedBlockingQueue<>();
+    }
+
+    public boolean readCharBuffer(CharBuffer charBuffer) {
+        while (charBuffer.hasRemaining()) {
+            processChar(charBuffer.get());
+        }
+        return !this.eventQueue.isEmpty();

Review Comment:
   Removed



##########
gateway-spi/src/main/java/org/apache/knox/gateway/sse/SSEEntity.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.knox.gateway.sse;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.entity.AbstractHttpEntity;
+
+import javax.servlet.AsyncContext;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.CharBuffer;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+public class SSEEntity extends AbstractHttpEntity {
+
+    private static final String SSE_DELIMITER = ":";
+
+    private final BlockingQueue<SSEvent> eventQueue;
+    private final StringBuilder eventBuilder = new StringBuilder();
+    private final HttpEntity httpEntity;
+    private char previousChar = '0';
+
+    public SSEEntity(HttpEntity httpEntity) {
+        this.httpEntity = httpEntity;
+        this.eventQueue = new LinkedBlockingQueue<>();
+    }
+
+    public boolean readCharBuffer(CharBuffer charBuffer) {
+        while (charBuffer.hasRemaining()) {
+            processChar(charBuffer.get());
+        }
+        return !this.eventQueue.isEmpty();
+    }
+
+    //Two new line chars (\n\n) after each other means the event is finished 
streaming
+    //We can process it and add it to the event queue
+    private void processChar(char nextChar) {
+        if (isNewLineChar(nextChar) && isNewLineChar(this.previousChar)) {
+            this.processEvent();

Review Comment:
   Removed them





Issue Time Tracking
-------------------

    Worklog Id:     (was: 942745)
    Time Spent: 1h 50m  (was: 1h 40m)

> Support Server Sent Events (SSE) in Knox
> ----------------------------------------
>
>                 Key: KNOX-3065
>                 URL: https://issues.apache.org/jira/browse/KNOX-3065
>             Project: Apache Knox
>          Issue Type: New Feature
>          Components: Server
>    Affects Versions: 2.1.0
>            Reporter: Tamás Hanicz
>            Priority: Major
>          Time Spent: 1h 50m
>  Remaining Estimate: 0h
>
> Currently Knox is not working with SSE. In case of SSE the response header 
> contains Content-Type = text/event-stream, in which case the server will send 
> messages terminated by \n\n. Knox should send these messages to the client as 
> they arrive. Currently Knox collects them all, and once the server closes the 
> connection sends all of them concatenated to each other to the client.
> Requirement:
>  * Full support in Knox for Server Sent Events.
> Definition of done:
>  * Clients can connect to SSE endpoints in the backend via Knox.
>  * Server Sent Events 
> ([https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events])
>  are forwarded by Knox from the server to the client as soon as they are 
> received.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to