You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2021/06/06 21:31:13 UTC

[GitHub] [nifi] Lehel44 opened a new pull request #5130: NIFI-8639: Add custom headers and dynamic URLs to ConnectWebsocket

Lehel44 opened a new pull request #5130:
URL: https://github.com/apache/nifi/pull/5130


   <!--
     Licensed to the Apache Software Foundation (ASF) under one or more
     contributor license agreements.  See the NOTICE file distributed with
     this work for additional information regarding copyright ownership.
     The ASF licenses this file to You under the Apache License, Version 2.0
     (the "License"); you may not use this file except in compliance with
     the License.  You may obtain a copy of the License at
         http://www.apache.org/licenses/LICENSE-2.0
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
   -->
   Thank you for submitting a contribution to Apache NiFi.
   
   Please provide a short description of the PR here:
   
   #### Description of PR
   
   https://issues.apache.org/jira/browse/NIFI-8639
   
   - ConnectWebSocket can parse HTTP headers from an incoming flowfile
   - JettyWebSocketClientService's WS URL attribute supports expression language from flowfile attributes
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced 
        in the commit message?
   
   - [ ] Does your PR title start with **NIFI-XXXX** where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically `main`)?
   
   - [ ] Is your initial contribution a single, squashed commit? _Additional commits in response to PR reviewer feedback should be made on this branch and pushed to allow change tracking. Do not `squash` or use `--force` when pushing to allow for clean monitoring of changes._
   
   ### For code changes:
   - [ ] Have you ensured that the full suite of tests is executed via `mvn -Pcontrib-check clean install` at the root `nifi` folder?
   - [ ] Have you written or updated unit tests to verify your changes?
   - [ ] Have you verified that the full build is successful on JDK 8?
   - [ ] Have you verified that the full build is successful on JDK 11?
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? 
   - [ ] If applicable, have you updated the `LICENSE` file, including the main `LICENSE` file under `nifi-assembly`?
   - [ ] If applicable, have you updated the `NOTICE` file, including the main `NOTICE` file found under `nifi-assembly`?
   - [ ] If adding new Properties, have you added `.displayName` in addition to .name (programmatic access) for each of the new properties?
   
   ### For documentation related changes:
   - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
   
   ### Note:
   Please ensure that once the PR is submitted, you check GitHub Actions CI for build issues and submit an update to your PR as soon as possible.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] asfgit closed pull request #5130: NIFI-8639: Add custom headers and dynamic URLs to ConnectWebsocket

Posted by GitBox <gi...@apache.org>.
asfgit closed pull request #5130:
URL: https://github.com/apache/nifi/pull/5130


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] Lehel44 commented on a change in pull request #5130: NIFI-8639: Add custom headers and dynamic URLs to ConnectWebsocket

Posted by GitBox <gi...@apache.org>.
Lehel44 commented on a change in pull request #5130:
URL: https://github.com/apache/nifi/pull/5130#discussion_r647237052



##########
File path: nifi-nar-bundles/nifi-websocket-bundle/nifi-websocket-processors/src/main/java/org/apache/nifi/processors/websocket/AbstractWebSocketGatewayProcessor.java
##########
@@ -165,27 +177,36 @@ private void deregister() {
     }
 
     @Override
-    public final void onTrigger(final ProcessContext context, final ProcessSessionFactory sessionFactory) throws ProcessException {
+    public final void onTrigger(final ProcessContext context, final ProcessSessionFactory sessionFactory) {
         if (processSessionFactory == null) {
             processSessionFactory = sessionFactory;
         }
 
         if (!isProcessorRegisteredToService()) {
             try {
-                registerProcessorToService(context, webSocketService -> onWebSocketServiceReady(webSocketService));
-            } catch (IOException|WebSocketConfigurationException e) {
+                registerProcessorToService(context, webSocketService -> onWebSocketServiceReady(webSocketService, context));
+            } catch (IOException | WebSocketConfigurationException e) {
                 // Deregister processor if it failed so that it can retry next onTrigger.
                 deregister();
                 context.yield();
                 throw new ProcessException("Failed to register processor to WebSocket service due to: " + e, e);
             }
+
+        } else {
+            try {
+                onWebSocketServiceReady(webSocketService, context);
+            } catch (IOException e) {
+                deregister();
+                context.yield();
+                throw new ProcessException("Failed to renew session and connect to WebSocket service due to: " + e, e);

Review comment:
       I think toString here would be better, I'd prefer to see the exception type, too. Later on it will be enough to just pass the exception to be displayed in the bulletins as well.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] tpalfy commented on a change in pull request #5130: NIFI-8639: Add custom headers and dynamic URLs to ConnectWebsocket

Posted by GitBox <gi...@apache.org>.
tpalfy commented on a change in pull request #5130:
URL: https://github.com/apache/nifi/pull/5130#discussion_r656314776



##########
File path: nifi-nar-bundles/nifi-websocket-bundle/nifi-websocket-processors/src/main/java/org/apache/nifi/processors/websocket/AbstractWebSocketGatewayProcessor.java
##########
@@ -118,12 +121,20 @@ public void consume(WebSocketSessionInfo sessionInfo, byte[] payload, int offset
 
     // @OnScheduled can not report error messages well on bulletin since it's an async method.
     // So, let's do it in onTrigger().
-    public void onWebSocketServiceReady(final WebSocketService webSocketService) throws IOException {
-
+    public void onWebSocketServiceReady(final WebSocketService webSocketService, final ProcessContext context) throws IOException {
         if (webSocketService instanceof WebSocketClientService) {
             // If it's a ws client, then connect to the remote here.
             // Otherwise, ws server is already started at WebSocketServerService
-            ((WebSocketClientService) webSocketService).connect(endpointId);
+            WebSocketClientService webSocketClientService = (WebSocketClientService) webSocketService;
+            if (context.hasIncomingConnection()) {
+                final ProcessSession session = processSessionFactory.createSession();
+                final FlowFile flowFile = session.get();
+                final Map<String, String> attributes = flowFile.getAttributes();
+                session.remove(flowFile);
+                webSocketClientService.connect(endpointId, attributes);

Review comment:
       ```suggestion
                  try {
                       webSocketClientService.connect(endpointId, attributes);
                       session.remove(flowFile);
                       session.commitAsync();
                   } catch (IOException | RuntimeException e) {
                       session.rollback(true);
                       throw e;
                   }
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] Lehel44 commented on a change in pull request #5130: NIFI-8639: Add custom headers and dynamic URLs to ConnectWebsocket

Posted by GitBox <gi...@apache.org>.
Lehel44 commented on a change in pull request #5130:
URL: https://github.com/apache/nifi/pull/5130#discussion_r647237052



##########
File path: nifi-nar-bundles/nifi-websocket-bundle/nifi-websocket-processors/src/main/java/org/apache/nifi/processors/websocket/AbstractWebSocketGatewayProcessor.java
##########
@@ -165,27 +177,36 @@ private void deregister() {
     }
 
     @Override
-    public final void onTrigger(final ProcessContext context, final ProcessSessionFactory sessionFactory) throws ProcessException {
+    public final void onTrigger(final ProcessContext context, final ProcessSessionFactory sessionFactory) {
         if (processSessionFactory == null) {
             processSessionFactory = sessionFactory;
         }
 
         if (!isProcessorRegisteredToService()) {
             try {
-                registerProcessorToService(context, webSocketService -> onWebSocketServiceReady(webSocketService));
-            } catch (IOException|WebSocketConfigurationException e) {
+                registerProcessorToService(context, webSocketService -> onWebSocketServiceReady(webSocketService, context));
+            } catch (IOException | WebSocketConfigurationException e) {
                 // Deregister processor if it failed so that it can retry next onTrigger.
                 deregister();
                 context.yield();
                 throw new ProcessException("Failed to register processor to WebSocket service due to: " + e, e);
             }
+
+        } else {
+            try {
+                onWebSocketServiceReady(webSocketService, context);
+            } catch (IOException e) {
+                deregister();
+                context.yield();
+                throw new ProcessException("Failed to renew session and connect to WebSocket service due to: " + e, e);

Review comment:
       I think toString here would be better. Later on it will be enough to just pass the exception to be displayed in the bulletins as well.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] exceptionfactory commented on a change in pull request #5130: NIFI-8639: Add custom headers and dynamic URLs to ConnectWebsocket

Posted by GitBox <gi...@apache.org>.
exceptionfactory commented on a change in pull request #5130:
URL: https://github.com/apache/nifi/pull/5130#discussion_r646963775



##########
File path: nifi-nar-bundles/nifi-websocket-bundle/nifi-websocket-processors/pom.xml
##########
@@ -52,5 +52,17 @@
             <version>1.14.0-SNAPSHOT</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.nifi</groupId>
+            <artifactId>nifi-websocket-services-jetty</artifactId>
+            <version>1.14.0-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.nifi</groupId>
+            <artifactId>nifi-websocket-services-jetty</artifactId>
+            <version>1.14.0-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>

Review comment:
       This dependency declaration appears to be duplicated.

##########
File path: nifi-nar-bundles/nifi-websocket-bundle/nifi-websocket-processors/src/main/java/org/apache/nifi/processors/websocket/AbstractWebSocketGatewayProcessor.java
##########
@@ -165,27 +177,36 @@ private void deregister() {
     }
 
     @Override
-    public final void onTrigger(final ProcessContext context, final ProcessSessionFactory sessionFactory) throws ProcessException {
+    public final void onTrigger(final ProcessContext context, final ProcessSessionFactory sessionFactory) {
         if (processSessionFactory == null) {
             processSessionFactory = sessionFactory;
         }
 
         if (!isProcessorRegisteredToService()) {
             try {
-                registerProcessorToService(context, webSocketService -> onWebSocketServiceReady(webSocketService));
-            } catch (IOException|WebSocketConfigurationException e) {
+                registerProcessorToService(context, webSocketService -> onWebSocketServiceReady(webSocketService, context));
+            } catch (IOException | WebSocketConfigurationException e) {
                 // Deregister processor if it failed so that it can retry next onTrigger.
                 deregister();
                 context.yield();
                 throw new ProcessException("Failed to register processor to WebSocket service due to: " + e, e);
             }
+
+        } else {
+            try {
+                onWebSocketServiceReady(webSocketService, context);
+            } catch (IOException e) {
+                deregister();
+                context.yield();
+                throw new ProcessException("Failed to renew session and connect to WebSocket service due to: " + e, e);

Review comment:
       Should the message include `e.getMessage()` instead of implicitly calling `e.toString()`?
   ```suggestion
                   throw new ProcessException("Failed to renew session and connect to WebSocket service due to: " + e.getMessage(), e);
   ```

##########
File path: nifi-nar-bundles/nifi-websocket-bundle/nifi-websocket-services-jetty/src/main/java/org/apache/nifi/websocket/jetty/JettyWebSocketClient.java
##########
@@ -293,35 +303,37 @@ private void connect(final String clientId, String sessionId) throws IOException
             try {
                 router = routers.getRouterOrFail(clientId);
             } catch (WebSocketConfigurationException e) {
-                throw new IllegalStateException("Failed to get router due to: "  + e, e);
+                throw new IllegalStateException("Failed to get router due to: " + e, e);

Review comment:
       Should this message call `e.getMessage()`?
   ```suggestion
                   throw new IllegalStateException("Failed to get router due to: " + e.getMessage(), e);
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] tpalfy commented on a change in pull request #5130: NIFI-8639: Add custom headers and dynamic URLs to ConnectWebsocket

Posted by GitBox <gi...@apache.org>.
tpalfy commented on a change in pull request #5130:
URL: https://github.com/apache/nifi/pull/5130#discussion_r656148733



##########
File path: nifi-nar-bundles/nifi-websocket-bundle/nifi-websocket-services-api/src/main/java/org/apache/nifi/websocket/WebSocketClientService.java
##########
@@ -32,7 +33,7 @@
 
     void stopClient() throws Exception;
 
-    void connect(final String clientId) throws IOException;
+    void connect(final String clientId, final Map<String, String> flowFileAttributes) throws IOException;

Review comment:
       ```suggestion
       void connect(final String clientId) throws IOException;
       
       default void connect(final String clientId, final Map<String, String> flowFileAttributes) throws IOException {
           connect(clientId);
       };
   ```

##########
File path: nifi-nar-bundles/nifi-websocket-bundle/nifi-websocket-services-jetty/src/test/java/org/apache/nifi/websocket/jetty/ITJettyWebSocketCommunication.java
##########
@@ -234,7 +235,7 @@ public void testClientServerCommunicationRecovery() throws Exception {
 
         clientService.registerProcessor(clientId, clientProcessor);
 
-        clientService.connect(clientId);
+        clientService.connect(clientId, Collections.emptyMap());

Review comment:
       If the interface is made backward-compatible, this change can be reverted.

##########
File path: nifi-nar-bundles/nifi-websocket-bundle/nifi-websocket-processors/src/main/resources/docs/org.apache.nifi.processors.websocket.ConnectWebSocket/additionalDetails.html
##########
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html lang="en">
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+      http://www.apache.org/licenses/LICENSE-2.0
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<head>
+    <meta charset="utf-8"/>
+    <title>ConnectWebSocket</title>
+    <link rel="stylesheet" href="../../../../../css/component-usage.css" type="text/css"/>
+</head>
+
+<body>
+<h2>Summary</h2>
+<p>
+    This processor acts as a WebSocket client endpoint to interact with a remote WebSocket server.
+    It is capable of receiving messages from a websocket server and it transfers them to downstream relationships
+    according to the received message types. Dynamic properties and custom header attributes can be configured by
+    incoming
+    flowfile attributes.
+</p>
+<p>
+    Any flowfile attributes can be referenced in the processor and in its WebSocket Client Service. For dynamic
+    properties
+    use the NiFi Expression Language and reference a flowfile attribute. For instance to the "dynamic.url =
+    currentValue"
+    flowfile attribute can be referenced in the WebSocket Client Service with the ${dynamic.url} expression.

Review comment:
       ```suggestion
       The processor may have an incoming relationship, in which case flowfile attributes are passed down to its WebSocket Client Service. This can be used to fine-tune connection configuration (url and headers for example). For example the "dynamic.url =
       currentValue"
       flowfile attribute can be referenced in the WebSocket Client Service with the ${dynamic.url} expression.
   ```

##########
File path: nifi-nar-bundles/nifi-websocket-bundle/nifi-websocket-processors/src/main/resources/docs/org.apache.nifi.processors.websocket.ConnectWebSocket/additionalDetails.html
##########
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html lang="en">
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+      http://www.apache.org/licenses/LICENSE-2.0
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<head>
+    <meta charset="utf-8"/>
+    <title>ConnectWebSocket</title>
+    <link rel="stylesheet" href="../../../../../css/component-usage.css" type="text/css"/>
+</head>
+
+<body>
+<h2>Summary</h2>
+<p>
+    This processor acts as a WebSocket client endpoint to interact with a remote WebSocket server.
+    It is capable of receiving messages from a websocket server and it transfers them to downstream relationships
+    according to the received message types. Dynamic properties and custom header attributes can be configured by
+    incoming
+    flowfile attributes.
+</p>
+<p>
+    Any flowfile attributes can be referenced in the processor and in its WebSocket Client Service. For dynamic
+    properties
+    use the NiFi Expression Language and reference a flowfile attribute. For instance to the "dynamic.url =
+    currentValue"
+    flowfile attribute can be referenced in the WebSocket Client Service with the ${dynamic.url} expression.
+</p>
+<p>
+    You can define custom websocket headers in the incoming flowfile as additional attributes. The attribute key
+    shall start with "header." and continue with they header key. For example: "header.Authorization". The attribute
+    value will be the corresponding header value.
+<ol>
+    <li>header.Autorization | AuthorizationPassword</li>

Review comment:
       ```suggestion
       <li>header.Authorization | Basic base64UserNamePassWord</li>
   ```

##########
File path: nifi-nar-bundles/nifi-websocket-bundle/nifi-websocket-services-jetty/src/test/java/org/apache/nifi/websocket/jetty/ITJettyWebSocketCommunication.java
##########
@@ -165,7 +166,7 @@ public void testClientServerCommunication() throws Exception {
 
         clientService.registerProcessor(clientId, clientProcessor);
 
-        clientService.connect(clientId);
+        clientService.connect(clientId, Collections.emptyMap());

Review comment:
       If the interface is made backward-compatible, this change can be reverted.

##########
File path: nifi-nar-bundles/nifi-websocket-bundle/nifi-websocket-processors/src/test/java/org/apache/nifi/processors/websocket/TestConnectWebSocket.java
##########
@@ -86,7 +95,7 @@ public void testSuccess() throws Exception {
             processor.consume(webSocketSession, binaryMessage, 0, binaryMessage.length);
             processor.consume(webSocketSession, binaryMessage, 0, binaryMessage.length);
             return null;
-        }).when(service).connect(endpointId);
+        }).when(service).connect(endpointId, Collections.emptyMap());

Review comment:
       If the interface is made backward-compatible, this change can be reverted.

##########
File path: nifi-nar-bundles/nifi-websocket-bundle/nifi-websocket-services-jetty/src/test/java/org/apache/nifi/websocket/util/HeaderMapExtractorTest.java
##########
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.websocket.util;
+
+import org.junit.Test;
+import util.HeaderMapExtractor;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class HeaderMapExtractorTest {
+
+    private static final Map<String, String> FLOW_FILE_ATTRIBUTES;
+    private static final Map<String, List<String>> EXPECTED_HEADER_MAP;
+
+    static {
+        final Map<String, String> attributes = new HashMap<>();
+        attributes.put("header.AUTHORIZATION", "AUTH_VALUE");
+        attributes.put("header.MULTI_HEADER_KEY", "FIRST, SECOND   ,THIRD");
+        attributes.put("headers.dots.dots.dots.DOTS_KEY", "DOTS_VALUE");
+        attributes.put("something.else.SOMETHING_ELSE_KEY", "SOMETHING_ELSE_VALUE");
+        attributes.put("header.EMPTY_VALUE_KEY", "");
+        FLOW_FILE_ATTRIBUTES = Collections.unmodifiableMap(attributes);
+    }
+
+    static {
+        final Map<String, List<String>> headers = new HashMap<>();
+        headers.put("AUTHORIZATION", Collections.singletonList("AUTH_VALUE"));
+        headers.put("MULTI_HEADER_KEY", Arrays.asList("FIRST", "SECOND", "THIRD"));
+        headers.put("dots.dots.dots.DOTS_KEY", Collections.singletonList("DOTS_VALUE"));
+        EXPECTED_HEADER_MAP = Collections.unmodifiableMap(headers);
+    }
+
+    @Test
+    public void testMapExtractor() {
+        final Map<String, List<String>> headerMap = HeaderMapExtractor.getHeaderMap(FLOW_FILE_ATTRIBUTES);
+
+        assertEquals(EXPECTED_HEADER_MAP.size(), headerMap.size());
+        for (Map.Entry<String, List<String>> entry : headerMap.entrySet()) {
+            assertTrue(EXPECTED_HEADER_MAP.containsKey(entry.getKey()));
+            final List<String> actualHeaderValues = entry.getValue();
+            final List<String> expectedHeaderValues = EXPECTED_HEADER_MAP.get(entry.getKey());
+            for (int i = 0; i < actualHeaderValues.size(); i++) {
+                assertEquals(expectedHeaderValues.get(i), actualHeaderValues.get(i));
+            }
+        }
+    }

Review comment:
       Using static constants to define the input and expected values of a single test case is not recommended.
   If the scope of the data is a single test case, so should be the corresponding variables. Also makes it less complex overall.
   
   The assertion can be simplified and made more declarative. The usual Java Map implementations have "smart" equals() methods which we can leverage.
   
   Below is a suggestion. Note I added one more header example as well:
   `attributes.put("headerButNotReally.UNRECOGNIZED", "NOT_A_HEADER_VALUE");`
   
   
   
   ```suggestion
       @Test
       public void testMapExtractor() {
           // GIVEN
           final Map<String, String> attributes = new HashMap<>();
           attributes.put("header.AUTHORIZATION", "AUTH_VALUE");
           attributes.put("header.MULTI_HEADER_KEY", "FIRST, SECOND   ,THIRD");
           attributes.put("header.dots.dots.dots.DOTS_KEY", "DOTS_VALUE");
           attributes.put("something.else.SOMETHING_ELSE_KEY", "SOMETHING_ELSE_VALUE");
           attributes.put("header.EMPTY_VALUE_KEY", "");
           attributes.put("headerButNotReally.UNRECOGNIZED", "NOT_A_HEADER_VALUE");
   
           final Map<String, List<String>> expected = new HashMap<>();
           expected.put("AUTHORIZATION", Collections.singletonList("AUTH_VALUE"));
           expected.put("MULTI_HEADER_KEY", Arrays.asList("FIRST", "SECOND", "THIRD"));
           expected.put("dots.dots.dots.DOTS_KEY", Collections.singletonList("DOTS_VALUE"));
   
           // WHEN
           final Map<String, List<String>> actual = HeaderMapExtractor.getHeaderMap(attributes);
   
           // THEN
           assertEquals(expected, actual);
       }
   ```

##########
File path: nifi-nar-bundles/nifi-websocket-bundle/nifi-websocket-services-jetty/src/main/java/util/HeaderMapExtractor.java
##########
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package util;
+
+import org.apache.nifi.util.StringUtils;
+
+import java.util.AbstractMap;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class HeaderMapExtractor {
+
+    public static Map<String, List<String>> getHeaderMap(final Map<String, String> flowFileAttributes) {
+        return flowFileAttributes.entrySet().stream()
+                .filter(entry -> entry.getKey().startsWith("header"))
+                .filter(entry -> StringUtils.isNotBlank(entry.getValue()))
+                .map(entry -> new AbstractMap.SimpleImmutableEntry<>(StringUtils.substringAfter(entry.getKey(), "."), entry.getValue()))
+                .collect(Collectors.toMap(Map.Entry::getKey, HeaderMapExtractor::headerValueMapper));
+    }

Review comment:
       ```suggestion
       public static final String HEADER_PREFIX = "header.";
   
       public static Map<String, List<String>> getHeaderMap(final Map<String, String> flowFileAttributes) {
           return flowFileAttributes.entrySet().stream()
                   .filter(entry -> entry.getKey().startsWith(HEADER_PREFIX))
                   .filter(entry -> StringUtils.isNotBlank(entry.getValue()))
                   .map(entry -> new AbstractMap.SimpleImmutableEntry<>(entry.getKey().substring(HEADER_PREFIX.length()), entry.getValue()))
                   .collect(Collectors.toMap(Map.Entry::getKey, HeaderMapExtractor::headerValueMapper));
       }
   ```

##########
File path: nifi-nar-bundles/nifi-websocket-bundle/nifi-websocket-processors/src/main/resources/docs/org.apache.nifi.processors.websocket.ConnectWebSocket/additionalDetails.html
##########
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html lang="en">
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+      http://www.apache.org/licenses/LICENSE-2.0
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<head>
+    <meta charset="utf-8"/>
+    <title>ConnectWebSocket</title>
+    <link rel="stylesheet" href="../../../../../css/component-usage.css" type="text/css"/>
+</head>
+
+<body>
+<h2>Summary</h2>
+<p>
+    This processor acts as a WebSocket client endpoint to interact with a remote WebSocket server.
+    It is capable of receiving messages from a websocket server and it transfers them to downstream relationships
+    according to the received message types. Dynamic properties and custom header attributes can be configured by
+    incoming
+    flowfile attributes.

Review comment:
       ```suggestion
       according to the received message types.
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] tpalfy commented on a change in pull request #5130: NIFI-8639: Add custom headers and dynamic URLs to ConnectWebsocket

Posted by GitBox <gi...@apache.org>.
tpalfy commented on a change in pull request #5130:
URL: https://github.com/apache/nifi/pull/5130#discussion_r656314776



##########
File path: nifi-nar-bundles/nifi-websocket-bundle/nifi-websocket-processors/src/main/java/org/apache/nifi/processors/websocket/AbstractWebSocketGatewayProcessor.java
##########
@@ -118,12 +121,20 @@ public void consume(WebSocketSessionInfo sessionInfo, byte[] payload, int offset
 
     // @OnScheduled can not report error messages well on bulletin since it's an async method.
     // So, let's do it in onTrigger().
-    public void onWebSocketServiceReady(final WebSocketService webSocketService) throws IOException {
-
+    public void onWebSocketServiceReady(final WebSocketService webSocketService, final ProcessContext context) throws IOException {
         if (webSocketService instanceof WebSocketClientService) {
             // If it's a ws client, then connect to the remote here.
             // Otherwise, ws server is already started at WebSocketServerService
-            ((WebSocketClientService) webSocketService).connect(endpointId);
+            WebSocketClientService webSocketClientService = (WebSocketClientService) webSocketService;
+            if (context.hasIncomingConnection()) {
+                final ProcessSession session = processSessionFactory.createSession();
+                final FlowFile flowFile = session.get();
+                final Map<String, String> attributes = flowFile.getAttributes();
+                session.remove(flowFile);
+                webSocketClientService.connect(endpointId, attributes);

Review comment:
       ```suggestion
                  try {
                       webSocketClientService.connect(endpointId, attributes);
                   } finally {
                       session.remove(flowFile);
                       session.commitAsync();
                   }
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] tpalfy commented on pull request #5130: NIFI-8639: Add custom headers and dynamic URLs to ConnectWebsocket

Posted by GitBox <gi...@apache.org>.
tpalfy commented on pull request #5130:
URL: https://github.com/apache/nifi/pull/5130#issuecomment-881665610


   LGTM+1.
   
   Merged into main.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org