This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit 4f2a467a584d6547ccbabdca8ed13df025aa4b48 Author: Andrea Cosentino <[email protected]> AuthorDate: Wed Jan 28 12:35:25 2026 +0100 Camel-AWS components: Use ObjectHelper for null checks - Polly Signed-off-by: Andrea Cosentino <[email protected]> --- .../component/aws2/polly/Polly2Component.java | 3 +- .../camel/component/aws2/polly/Polly2Endpoint.java | 4 +- .../camel/component/aws2/polly/Polly2Producer.java | 74 +++++++++++----------- 3 files changed, 41 insertions(+), 40 deletions(-) diff --git a/components/camel-aws/camel-aws2-polly/src/main/java/org/apache/camel/component/aws2/polly/Polly2Component.java b/components/camel-aws/camel-aws2-polly/src/main/java/org/apache/camel/component/aws2/polly/Polly2Component.java index d9ede2be6ea9..725ce9b3936f 100644 --- a/components/camel-aws/camel-aws2-polly/src/main/java/org/apache/camel/component/aws2/polly/Polly2Component.java +++ b/components/camel-aws/camel-aws2-polly/src/main/java/org/apache/camel/component/aws2/polly/Polly2Component.java @@ -23,6 +23,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.spi.Metadata; import org.apache.camel.spi.annotations.Component; import org.apache.camel.support.HealthCheckComponent; +import org.apache.camel.util.ObjectHelper; /** * For working with Amazon Polly SDK v2. @@ -44,7 +45,7 @@ public class Polly2Component extends HealthCheckComponent { @Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { Polly2Configuration configuration - = this.configuration != null ? this.configuration.copy() : new Polly2Configuration(); + = ObjectHelper.isNotEmpty(this.configuration) ? this.configuration.copy() : new Polly2Configuration(); Polly2Endpoint endpoint = new Polly2Endpoint(uri, this, configuration); setProperties(endpoint, parameters); diff --git a/components/camel-aws/camel-aws2-polly/src/main/java/org/apache/camel/component/aws2/polly/Polly2Endpoint.java b/components/camel-aws/camel-aws2-polly/src/main/java/org/apache/camel/component/aws2/polly/Polly2Endpoint.java index d9507dd51de9..2b4f80a3c308 100644 --- a/components/camel-aws/camel-aws2-polly/src/main/java/org/apache/camel/component/aws2/polly/Polly2Endpoint.java +++ b/components/camel-aws/camel-aws2-polly/src/main/java/org/apache/camel/component/aws2/polly/Polly2Endpoint.java @@ -66,7 +66,7 @@ public class Polly2Endpoint extends ScheduledPollEndpoint implements EndpointSer super.doStart(); pollyClient - = configuration.getPollyClient() != null + = ObjectHelper.isNotEmpty(configuration.getPollyClient()) ? configuration.getPollyClient() : Polly2ClientFactory.getPollyClient(configuration); } @@ -74,7 +74,7 @@ public class Polly2Endpoint extends ScheduledPollEndpoint implements EndpointSer @Override public void doStop() throws Exception { if (ObjectHelper.isEmpty(configuration.getPollyClient())) { - if (pollyClient != null) { + if (ObjectHelper.isNotEmpty(pollyClient)) { pollyClient.close(); } } diff --git a/components/camel-aws/camel-aws2-polly/src/main/java/org/apache/camel/component/aws2/polly/Polly2Producer.java b/components/camel-aws/camel-aws2-polly/src/main/java/org/apache/camel/component/aws2/polly/Polly2Producer.java index 86261b8794e8..fc7daaa21ba1 100644 --- a/components/camel-aws/camel-aws2-polly/src/main/java/org/apache/camel/component/aws2/polly/Polly2Producer.java +++ b/components/camel-aws/camel-aws2-polly/src/main/java/org/apache/camel/component/aws2/polly/Polly2Producer.java @@ -108,7 +108,7 @@ public class Polly2Producer extends DefaultProducer { private Polly2Operations determineOperation(Exchange exchange) { Polly2Operations operation = exchange.getIn().getHeader(Polly2Constants.OPERATION, Polly2Operations.class); - if (operation == null) { + if (ObjectHelper.isEmpty(operation)) { operation = getConfiguration().getOperation(); } return operation; @@ -120,7 +120,7 @@ public class Polly2Producer extends DefaultProducer { @Override public String toString() { - if (pollyProducerToString == null) { + if (ObjectHelper.isEmpty(pollyProducerToString)) { pollyProducerToString = "PollyProducer[" + URISupport.sanitizeUri(getEndpoint().getEndpointUri()) + "]"; } return pollyProducerToString; @@ -144,7 +144,7 @@ public class Polly2Producer extends DefaultProducer { } Message message = getMessageForResponse(exchange); message.setBody(result); - if (result.response().contentType() != null) { + if (ObjectHelper.isNotEmpty(result.response().contentType())) { message.setHeader(Polly2Constants.CONTENT_TYPE, result.response().contentType()); } message.setHeader(Polly2Constants.REQUEST_CHARACTERS, result.response().requestCharacters()); @@ -154,65 +154,65 @@ public class Polly2Producer extends DefaultProducer { // Set voice ID - endpoint option first, then header VoiceId voiceId = getConfiguration().getVoiceId(); - if (voiceId == null) { + if (ObjectHelper.isEmpty(voiceId)) { voiceId = exchange.getIn().getHeader(Polly2Constants.VOICE_ID, VoiceId.class); } - if (voiceId == null) { + if (ObjectHelper.isEmpty(voiceId)) { throw new IllegalArgumentException("Voice ID must be specified as endpoint option or header"); } request.voiceId(voiceId); // Set output format - endpoint option first, then header OutputFormat outputFormat = getConfiguration().getOutputFormat(); - if (outputFormat == null) { + if (ObjectHelper.isEmpty(outputFormat)) { outputFormat = exchange.getIn().getHeader(Polly2Constants.OUTPUT_FORMAT, OutputFormat.class); } - if (outputFormat != null) { + if (ObjectHelper.isNotEmpty(outputFormat)) { request.outputFormat(outputFormat); } // Set text type - endpoint option first, then header TextType textType = getConfiguration().getTextType(); - if (textType == null) { + if (ObjectHelper.isEmpty(textType)) { textType = exchange.getIn().getHeader(Polly2Constants.TEXT_TYPE, TextType.class); } - if (textType != null) { + if (ObjectHelper.isNotEmpty(textType)) { request.textType(textType); } // Set engine - endpoint option first, then header Engine engine = getConfiguration().getEngine(); - if (engine == null) { + if (ObjectHelper.isEmpty(engine)) { engine = exchange.getIn().getHeader(Polly2Constants.ENGINE, Engine.class); } - if (engine != null) { + if (ObjectHelper.isNotEmpty(engine)) { request.engine(engine); } // Set sample rate - endpoint option first, then header String sampleRate = getConfiguration().getSampleRate(); - if (sampleRate == null) { + if (ObjectHelper.isEmpty(sampleRate)) { sampleRate = exchange.getIn().getHeader(Polly2Constants.SAMPLE_RATE, String.class); } - if (sampleRate != null) { + if (ObjectHelper.isNotEmpty(sampleRate)) { request.sampleRate(sampleRate); } // Set language code - endpoint option first, then header String languageCode = getConfiguration().getLanguageCode(); - if (languageCode == null) { + if (ObjectHelper.isEmpty(languageCode)) { languageCode = exchange.getIn().getHeader(Polly2Constants.LANGUAGE_CODE, String.class); } - if (languageCode != null) { + if (ObjectHelper.isNotEmpty(languageCode)) { request.languageCode(languageCode); } // Set lexicon names - endpoint option first, then header String lexiconNames = getConfiguration().getLexiconNames(); - if (lexiconNames == null) { + if (ObjectHelper.isEmpty(lexiconNames)) { lexiconNames = exchange.getIn().getHeader(Polly2Constants.LEXICON_NAMES, String.class); } - if (lexiconNames != null) { + if (ObjectHelper.isNotEmpty(lexiconNames)) { request.lexiconNames(Arrays.asList(lexiconNames.split(","))); } @@ -254,19 +254,19 @@ public class Polly2Producer extends DefaultProducer { // Set engine filter - endpoint option first, then header Engine engine = getConfiguration().getEngine(); - if (engine == null) { + if (ObjectHelper.isEmpty(engine)) { engine = exchange.getIn().getHeader(Polly2Constants.ENGINE, Engine.class); } - if (engine != null) { + if (ObjectHelper.isNotEmpty(engine)) { request.engine(engine); } // Set language code filter - endpoint option first, then header String languageCode = getConfiguration().getLanguageCode(); - if (languageCode == null) { + if (ObjectHelper.isEmpty(languageCode)) { languageCode = exchange.getIn().getHeader(Polly2Constants.LANGUAGE_CODE, String.class); } - if (languageCode != null) { + if (ObjectHelper.isNotEmpty(languageCode)) { request.languageCode(languageCode); } @@ -449,20 +449,20 @@ public class Polly2Producer extends DefaultProducer { // Set voice ID - endpoint option first, then header VoiceId voiceId = getConfiguration().getVoiceId(); - if (voiceId == null) { + if (ObjectHelper.isEmpty(voiceId)) { voiceId = exchange.getIn().getHeader(Polly2Constants.VOICE_ID, VoiceId.class); } - if (voiceId == null) { + if (ObjectHelper.isEmpty(voiceId)) { throw new IllegalArgumentException("Voice ID must be specified as endpoint option or header"); } request.voiceId(voiceId); // Set output format - endpoint option first, then header OutputFormat outputFormat = getConfiguration().getOutputFormat(); - if (outputFormat == null) { + if (ObjectHelper.isEmpty(outputFormat)) { outputFormat = exchange.getIn().getHeader(Polly2Constants.OUTPUT_FORMAT, OutputFormat.class); } - if (outputFormat != null) { + if (ObjectHelper.isNotEmpty(outputFormat)) { request.outputFormat(outputFormat); } @@ -496,46 +496,46 @@ public class Polly2Producer extends DefaultProducer { // Set text type - endpoint option first, then header TextType textType = getConfiguration().getTextType(); - if (textType == null) { + if (ObjectHelper.isEmpty(textType)) { textType = exchange.getIn().getHeader(Polly2Constants.TEXT_TYPE, TextType.class); } - if (textType != null) { + if (ObjectHelper.isNotEmpty(textType)) { request.textType(textType); } // Set engine - endpoint option first, then header Engine engine = getConfiguration().getEngine(); - if (engine == null) { + if (ObjectHelper.isEmpty(engine)) { engine = exchange.getIn().getHeader(Polly2Constants.ENGINE, Engine.class); } - if (engine != null) { + if (ObjectHelper.isNotEmpty(engine)) { request.engine(engine); } // Set sample rate - endpoint option first, then header String sampleRate = getConfiguration().getSampleRate(); - if (sampleRate == null) { + if (ObjectHelper.isEmpty(sampleRate)) { sampleRate = exchange.getIn().getHeader(Polly2Constants.SAMPLE_RATE, String.class); } - if (sampleRate != null) { + if (ObjectHelper.isNotEmpty(sampleRate)) { request.sampleRate(sampleRate); } // Set language code - endpoint option first, then header String languageCode = getConfiguration().getLanguageCode(); - if (languageCode == null) { + if (ObjectHelper.isEmpty(languageCode)) { languageCode = exchange.getIn().getHeader(Polly2Constants.LANGUAGE_CODE, String.class); } - if (languageCode != null) { + if (ObjectHelper.isNotEmpty(languageCode)) { request.languageCode(languageCode); } // Set lexicon names - endpoint option first, then header String lexiconNames = getConfiguration().getLexiconNames(); - if (lexiconNames == null) { + if (ObjectHelper.isEmpty(lexiconNames)) { lexiconNames = exchange.getIn().getHeader(Polly2Constants.LEXICON_NAMES, String.class); } - if (lexiconNames != null) { + if (ObjectHelper.isNotEmpty(lexiconNames)) { request.lexiconNames(Arrays.asList(lexiconNames.split(","))); } @@ -637,7 +637,7 @@ public class Polly2Producer extends DefaultProducer { "producers", WritableHealthCheckRepository.class); - if (healthCheckRepository != null) { + if (ObjectHelper.isNotEmpty(healthCheckRepository)) { String id = getEndpoint().getId(); producerHealthCheck = new Polly2ProducerHealthCheck(getEndpoint(), id); producerHealthCheck.setEnabled(getEndpoint().getComponent().isHealthCheckProducerEnabled()); @@ -647,7 +647,7 @@ public class Polly2Producer extends DefaultProducer { @Override protected void doStop() throws Exception { - if (healthCheckRepository != null && producerHealthCheck != null) { + if (ObjectHelper.isNotEmpty(healthCheckRepository) && ObjectHelper.isNotEmpty(producerHealthCheck)) { healthCheckRepository.removeHealthCheck(producerHealthCheck); producerHealthCheck = null; }
