gnodet-bot commented on code in PR #28353:
URL: https://github.com/apache/camel/pull/28353#discussion_r4364400099
##########
components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java:
##########
@@ -670,6 +677,63 @@ public static Message getMessageForResponse(final Exchange
exchange) {
return exchange.getMessage();
}
+ /**
+ * The instance type of the {@link AWS2EC2Constants#INSTANCE_TYPE} header:
an {@link InstanceType}, its AWS value
+ * (such as t2.micro), or the name of the constant (such as T2_MICRO).
+ */
+ private InstanceType getInstanceType(Exchange exchange) {
+ Object value =
exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_TYPE);
+ if (value instanceof InstanceType instanceType) {
+ return instanceType;
+ }
+ String text =
exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_TYPE, String.class);
+ if (text != null) {
+ text = text.trim();
+ InstanceType instanceType = InstanceType.fromValue(text);
+ if (instanceType != null && instanceType !=
InstanceType.UNKNOWN_TO_SDK_VERSION) {
+ return instanceType;
+ }
+ for (InstanceType candidate : InstanceType.knownValues()) {
+ if (candidate.name().equals(text)) {
+ return candidate;
+ }
+ }
+ }
+ throw new IllegalArgumentException(
+ "Unknown instance type " + value + " in the " +
AWS2EC2Constants.INSTANCE_TYPE
+ + " header: expected an
InstanceType, such as t2.micro or T2_MICRO");
+ }
+
+ /**
+ * The instance ids of the {@link AWS2EC2Constants#INSTANCES_IDS} header:
a Collection of ids, or a String of ids
+ * separated by commas. Returns null when the header is not set.
+ */
+ private Collection<String> getInstanceIds(Exchange exchange) {
+ Object value =
exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS);
+ if (value == null) {
+ return null;
+ }
+ if (value instanceof Collection<?> collection) {
+ List<String> ids = new ArrayList<>(collection.size());
+ for (Object id : collection) {
+ ids.add(id != null ? id.toString() : null);
Review Comment:
⚠️ **Bug (still open from previous review):** When the header is a
`Collection<?>`, null elements are silently passed through to the AWS SDK. The
ternary `id != null ? id.toString() : null` adds `null` strings to the list,
which will likely cause a `NullPointerException` inside the SDK. The
String-split path already skips blank/empty tokens — the Collection path should
filter nulls too:
```java
for (Object id : collection) {
if (id != null) {
ids.add(id.toString());
}
}
```
##########
components/camel-aws/camel-aws2-transcribe/src/main/java/org/apache/camel/component/aws2/transcribe/Transcribe2Producer.java:
##########
@@ -917,6 +910,32 @@ private void applyIfPresent(Exchange exchange, String
header, Consumer<String> s
}
}
+ /**
+ * Reads the phrases (or words of a vocabulary filter) header as a list of
strings. A single String is taken as a
+ * list of one phrase.
+ */
+ private List<String> getPhrases(Exchange exchange) {
+ Object value =
exchange.getIn().getHeader(Transcribe2Constants.VOCABULARY_PHRASES);
+ if (value == null) {
+ return null;
+ }
+ if (value instanceof String phrase) {
+ return phrase.isBlank() ? null : List.of(phrase);
+ }
+ if (value instanceof Collection<?> collection) {
+ List<String> phrases = new ArrayList<>(collection.size());
+ for (Object phrase : collection) {
+ if (phrase != null) {
+ phrases.add(phrase.toString());
+ }
+ }
+ return phrases;
+ }
+ throw new IllegalArgumentException(
+ "The " + Transcribe2Constants.VOCABULARY_PHRASES + " header
must be a List<String> or a String, was: "
+ + value.getClass().getName());
Review Comment:
💬 **Nit (cosmetic):** The trailing-space alignment in the exception message
concatenation doesn't render consistently across tools. Consider
straightforward indentation:
```suggestion
throw new IllegalArgumentException(
"The " + Transcribe2Constants.VOCABULARY_PHRASES
+ " header must be a List<String> or a String, was: "
+ value.getClass().getName());
```
--
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]