exceptionfactory commented on a change in pull request #5541:
URL: https://github.com/apache/nifi/pull/5541#discussion_r760269901
##########
File path:
nifi-nar-bundles/nifi-websocket-bundle/nifi-websocket-services-jetty/src/main/java/org/apache/nifi/websocket/jetty/JettyWebSocketClient.java
##########
@@ -248,6 +268,44 @@ public void startClient(final ConfigurationContext
context) throws Exception {
}, sessionMaintenanceInterval, sessionMaintenanceInterval,
TimeUnit.MILLISECONDS);
}
+ private URI getEndpoint(final ConfigurationContext context) throws
URISyntaxException {
+ final StringBuilder result = new
StringBuilder(context.getProperty(WS_URI).evaluateAttributeExpressions(new
HashMap<>()).getValue());
+ final List<PropertyDescriptor> dynamicProperties =
context.getProperties()
+ .keySet()
+ .stream()
+ .filter(PropertyDescriptor::isDynamic)
+ .collect(Collectors.toList());
+
+ final Map<String, String> queryParameters = new HashMap<>();
+ dynamicProperties.forEach((descriptor) -> {
+ final PropertyValue propertyValue =
context.getProperty(descriptor);
+ if (descriptor.isSensitive()) {
+ final String propertyName =
org.apache.commons.lang3.StringUtils.substringAfter(descriptor.getName(),
SENSITIVE_PROPERTY_PREFIX);
+ queryParameters.put(propertyName, propertyValue.getValue());
+ } else {
+ queryParameters.put(descriptor.getName(),
propertyValue.evaluateAttributeExpressions().getValue());
+ }
+ });
+
+ if (!queryParameters.isEmpty()) {
+ final List<String> parameters = new LinkedList<>();
+
+ try {
+ for (final Map.Entry<String, String> parameter :
queryParameters.entrySet()) {
+ parameters.add(URLEncoder.encode(parameter.getKey(),
"UTF-8") + '=' + URLEncoder.encode(parameter.getValue(), "UTF-8"));
Review comment:
For clarity, it would be helpful to declare the key and value elements
separately. The `UTF-8` string can be replaced with `StandardCharsets.UTF_8`.
##########
File path:
nifi-nar-bundles/nifi-websocket-bundle/nifi-websocket-services-jetty/src/main/java/org/apache/nifi/websocket/jetty/JettyWebSocketClient.java
##########
@@ -248,6 +268,44 @@ public void startClient(final ConfigurationContext
context) throws Exception {
}, sessionMaintenanceInterval, sessionMaintenanceInterval,
TimeUnit.MILLISECONDS);
}
+ private URI getEndpoint(final ConfigurationContext context) throws
URISyntaxException {
+ final StringBuilder result = new
StringBuilder(context.getProperty(WS_URI).evaluateAttributeExpressions(new
HashMap<>()).getValue());
Review comment:
The `evaluateAttributeExpressions()` method can be called without an
argument, so it looks like the empty `HashMap` can be removed:
```suggestion
final StringBuilder result = new
StringBuilder(context.getProperty(WS_URI).evaluateAttributeExpressions().getValue());
```
##########
File path:
nifi-nar-bundles/nifi-websocket-bundle/nifi-websocket-services-jetty/src/main/java/org/apache/nifi/websocket/jetty/JettyWebSocketClient.java
##########
@@ -248,6 +268,44 @@ public void startClient(final ConfigurationContext
context) throws Exception {
}, sessionMaintenanceInterval, sessionMaintenanceInterval,
TimeUnit.MILLISECONDS);
}
+ private URI getEndpoint(final ConfigurationContext context) throws
URISyntaxException {
+ final StringBuilder result = new
StringBuilder(context.getProperty(WS_URI).evaluateAttributeExpressions(new
HashMap<>()).getValue());
+ final List<PropertyDescriptor> dynamicProperties =
context.getProperties()
+ .keySet()
+ .stream()
+ .filter(PropertyDescriptor::isDynamic)
+ .collect(Collectors.toList());
+
+ final Map<String, String> queryParameters = new HashMap<>();
+ dynamicProperties.forEach((descriptor) -> {
+ final PropertyValue propertyValue =
context.getProperty(descriptor);
+ if (descriptor.isSensitive()) {
+ final String propertyName =
org.apache.commons.lang3.StringUtils.substringAfter(descriptor.getName(),
SENSITIVE_PROPERTY_PREFIX);
+ queryParameters.put(propertyName, propertyValue.getValue());
+ } else {
+ queryParameters.put(descriptor.getName(),
propertyValue.evaluateAttributeExpressions().getValue());
+ }
+ });
+
+ if (!queryParameters.isEmpty()) {
+ final List<String> parameters = new LinkedList<>();
+
+ try {
+ for (final Map.Entry<String, String> parameter :
queryParameters.entrySet()) {
+ parameters.add(URLEncoder.encode(parameter.getKey(),
"UTF-8") + '=' + URLEncoder.encode(parameter.getValue(), "UTF-8"));
+ }
+ } catch (final UnsupportedEncodingException e) {
+ getLogger().error("Could not be initialized because of: {}",
new Object[]{e.getMessage()}, e);
Review comment:
The wrapping `Object[]` is not necessary for logging placeholder values,
it would also be helpful to adjust the message:
```suggestion
getLogger().error("WebSocket URI parameter encoding failed",
e);
```
Is it possible that the `UnsupportedEncodingException` could include the
value of a sensitive parameter? That may make it necessary to avoid including
the exception stack trace to avoid leaking sensitive information.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]