This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 49920e637fa4 CAMEL-27491: camel-smpp - a bind the SMSC rejects while
the consumer or producer starts fails the start, instead of reconnecting inside
it (#30815)
49920e637fa4 is described below
commit 49920e637fa4ebf255edc2b4930519aabd976a12
Author: allthingssecurity <[email protected]>
AuthorDate: Thu Nov 26 13:29:22 2026 +0530
CAMEL-27491: camel-smpp - a bind the SMSC rejects while the consumer or
producer starts fails the start, instead of reconnecting inside it (#30815)
jsmpp closes a session whose bind fails (negative bind response, no
bind_resp in time, I/O error) on the thread that called connectAndBind,
and calls the session state listeners on that thread before
connectAndBind throws. The Camel listener is registered before the bind,
so a bind rejected during doStart() ran the listener on the starting
thread: it saw a lost session and ran the whole reconnect task there,
waiting for it with no time limit while holding the lifecycle lock. With
the default maxReconnect the start never returned while the SMSC kept
rejecting, a stop from another thread waited for the same lock (so the
cancellation of CAMEL-27090 could not run), and once the SMSC accepted,
the start failed anyway and its stop unbound the session the reconnect
had just made. A lazy producer held the route thread in process() the
same way, as its connectLock is reentrant.
The consumer and the producer now remember, per thread, the session whose
connectAndBind runs on it, and the listener ignores a close reported on
that thread for that session: the caller of connectAndBind handles the
failure. The start fails at once with the bind error, as it does when
the SMSC refuses the connection; a lazy producer fails the exchange and
tries again with the next one; a reconnect attempt fails and the
reconnect task tries again after reconnectDelay, up to maxReconnect, as
before. A session lost after it was bound is reconnected as before.
The unit tests of the listener pass the session as the source of the
state change, as jsmpp does, instead of null.
* CAMEL-27491: camel-smpp - review follow-up: a null source of a session
state change still reconnects
- SmppConsumer, SmppProducer: the listener only skips the reconnect when
the source
is not null and is the session being bound on this thread. With no bind
on the
thread the ThreadLocal holds null, so a state change with a null source
matched
it and the lost session was not reconnected.
- SmppConsumerTest, SmppProducerTest: the listener tests share one helper,
and a new
test passes a null source and checks that the session is closed and
reconnected.
The producer test now uses its UNBOUND/CLOSED parameter instead of always
CLOSED.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../apache/camel/component/smpp/SmppConsumer.java | 30 ++-
.../apache/camel/component/smpp/SmppProducer.java | 40 ++-
.../camel/component/smpp/SmppBindRejectedTest.java | 283 +++++++++++++++++++++
.../camel/component/smpp/SmppConsumerTest.java | 13 +-
.../camel/component/smpp/SmppProducerTest.java | 13 +-
5 files changed, 358 insertions(+), 21 deletions(-)
diff --git
a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConsumer.java
b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConsumer.java
index ccd2a950c03c..5c0df92167f4 100644
---
a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConsumer.java
+++
b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppConsumer.java
@@ -33,6 +33,7 @@ import org.jsmpp.extra.SessionState;
import org.jsmpp.session.BindParameter;
import org.jsmpp.session.MessageReceiverListener;
import org.jsmpp.session.SMPPSession;
+import org.jsmpp.session.Session;
import org.jsmpp.session.SessionStateListener;
import org.jsmpp.util.DefaultComposer;
import org.slf4j.Logger;
@@ -57,6 +58,9 @@ public class SmppConsumer extends DefaultConsumer {
private final SessionStateListener internalSessionStateListener;
private final ReentrantLock reconnectLock = new ReentrantLock();
+ // the session whose connectAndBind runs on this thread: jsmpp closes a
session whose bind fails on the thread that
+ // called connectAndBind, and calls the session state listeners there
before connectAndBind throws
+ private final ThreadLocal<Session> bindingSession = new ThreadLocal<>();
// created again by a start after a stop, as the stop shuts it down
private volatile ScheduledExecutorService reconnectService;
@@ -79,6 +83,13 @@ public class SmppConsumer extends DefaultConsumer {
}
if (newState.equals(SessionState.UNBOUND) ||
newState.equals(SessionState.CLOSED)) {
+ if (source != null && source == bindingSession.get()) {
+ // the bind of this session failed on this thread, and
connectAndBind throws to its caller (the
+ // start, a reconnect attempt or a lazy session creation),
which handles it. Reconnecting here
+ // would run the whole reconnect on that thread: inside
start(), under the lock stop() needs too
+ LOG.debug("The bind to {} failed",
getEndpoint().getConnectionString());
+ return;
+ }
LOG.warn(newState.equals(SessionState.UNBOUND)
? "Session to {} was unbound - trying to reconnect" :
"Lost connection to: {} - trying to reconnect...",
getEndpoint().getConnectionString());
@@ -109,13 +120,18 @@ public class SmppConsumer extends DefaultConsumer {
newSession.setQueueCapacity(this.configuration.getPduProcessorQueueCapacity());
newSession.addSessionStateListener(internalSessionStateListener);
newSession.setMessageReceiverListener(messageReceiverListener);
- newSession.connectAndBind(this.configuration.getHost(),
this.configuration.getPort(),
- new BindParameter(
- BindType.BIND_RX, this.configuration.getSystemId(),
- this.configuration.getPassword(),
this.configuration.getSystemType(),
- TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN,
- configuration.getAddressRange(),
- configuration.getInterfaceVersionByte()));
+ bindingSession.set(newSession);
+ try {
+ newSession.connectAndBind(this.configuration.getHost(),
this.configuration.getPort(),
+ new BindParameter(
+ BindType.BIND_RX, this.configuration.getSystemId(),
+ this.configuration.getPassword(),
this.configuration.getSystemType(),
+ TypeOfNumber.UNKNOWN,
NumberingPlanIndicator.UNKNOWN,
+ configuration.getAddressRange(),
+ configuration.getInterfaceVersionByte()));
+ } finally {
+ bindingSession.remove();
+ }
return newSession;
}
diff --git
a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java
b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java
index 1ec4c3554b99..30ed57de78e0 100644
---
a/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java
+++
b/components/camel-smpp/src/main/java/org/apache/camel/component/smpp/SmppProducer.java
@@ -34,6 +34,7 @@ import org.jsmpp.bean.TypeOfNumber;
import org.jsmpp.extra.SessionState;
import org.jsmpp.session.BindParameter;
import org.jsmpp.session.SMPPSession;
+import org.jsmpp.session.Session;
import org.jsmpp.session.SessionStateListener;
import org.jsmpp.util.DefaultComposer;
import org.slf4j.Logger;
@@ -56,6 +57,9 @@ public class SmppProducer extends DefaultProducer {
private final SmppConfiguration configuration;
private final SessionStateListener internalSessionStateListener;
private final ReentrantLock connectLock = new ReentrantLock();
+ // the session whose connectAndBind runs on this thread: jsmpp closes a
session whose bind fails on the thread that
+ // called connectAndBind, and calls the session state listeners there
before connectAndBind throws
+ private final ThreadLocal<Session> bindingSession = new ThreadLocal<>();
// created again by a start after a stop, as the stop shuts it down
private volatile ScheduledExecutorService reconnectService;
@@ -75,6 +79,13 @@ public class SmppProducer extends DefaultProducer {
}
if (newState.equals(SessionState.UNBOUND) ||
newState.equals(SessionState.CLOSED)) {
+ if (source != null && source == bindingSession.get()) {
+ // the bind of this session failed on this thread, and
connectAndBind throws to its caller (the
+ // start, a reconnect attempt or a lazy session creation),
which handles it. Reconnecting here
+ // would run the whole reconnect on that thread: inside
start(), under the lock stop() needs too
+ LOG.debug("The bind to {} failed",
getEndpoint().getConnectionString());
+ return;
+ }
LOG.warn(newState.equals(SessionState.UNBOUND)
? "Session to {} was unbound - trying to reconnect" :
"Lost connection to: {} - trying to reconnect...",
getEndpoint().getConnectionString());
@@ -119,18 +130,23 @@ public class SmppProducer extends DefaultProducer {
this.configuration.getMessageReceiverRouteId()));
bindType = BindType.BIND_TRX;
}
- session.connectAndBind(
- this.configuration.getHost(),
- this.configuration.getPort(),
- new BindParameter(
- bindType,
- this.configuration.getSystemId(),
- this.configuration.getPassword(),
- this.configuration.getSystemType(),
- TypeOfNumber.valueOf(configuration.getTypeOfNumber()),
-
NumberingPlanIndicator.valueOf(configuration.getNumberingPlanIndicator()),
- "",
- configuration.getInterfaceVersionByte()));
+ bindingSession.set(session);
+ try {
+ session.connectAndBind(
+ this.configuration.getHost(),
+ this.configuration.getPort(),
+ new BindParameter(
+ bindType,
+ this.configuration.getSystemId(),
+ this.configuration.getPassword(),
+ this.configuration.getSystemType(),
+
TypeOfNumber.valueOf(configuration.getTypeOfNumber()),
+
NumberingPlanIndicator.valueOf(configuration.getNumberingPlanIndicator()),
+ "",
+ configuration.getInterfaceVersionByte()));
+ } finally {
+ bindingSession.remove();
+ }
LOG.info("Connected to: {}", getEndpoint().getConnectionString());
diff --git
a/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppBindRejectedTest.java
b/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppBindRejectedTest.java
new file mode 100644
index 000000000000..628407da966d
--- /dev/null
+++
b/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppBindRejectedTest.java
@@ -0,0 +1,283 @@
+/*
+ * 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.camel.component.smpp;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionException;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Exchange;
+import org.apache.camel.Producer;
+import org.apache.camel.Service;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.jsmpp.PDUStringException;
+import org.jsmpp.SMPPConstant;
+import org.jsmpp.bean.BroadcastSm;
+import org.jsmpp.bean.CancelBroadcastSm;
+import org.jsmpp.bean.CancelSm;
+import org.jsmpp.bean.DataCodings;
+import org.jsmpp.bean.DataSm;
+import org.jsmpp.bean.ESMClass;
+import org.jsmpp.bean.NumberingPlanIndicator;
+import org.jsmpp.bean.OptionalParameter;
+import org.jsmpp.bean.QueryBroadcastSm;
+import org.jsmpp.bean.QuerySm;
+import org.jsmpp.bean.RegisteredDelivery;
+import org.jsmpp.bean.ReplaceSm;
+import org.jsmpp.bean.SubmitMulti;
+import org.jsmpp.bean.SubmitSm;
+import org.jsmpp.bean.TypeOfNumber;
+import org.jsmpp.extra.ProcessRequestException;
+import org.jsmpp.session.BindRequest;
+import org.jsmpp.session.BroadcastSmResult;
+import org.jsmpp.session.DataSmResult;
+import org.jsmpp.session.QueryBroadcastSmResult;
+import org.jsmpp.session.QuerySmResult;
+import org.jsmpp.session.SMPPServerSession;
+import org.jsmpp.session.SMPPServerSessionListener;
+import org.jsmpp.session.ServerMessageReceiverListener;
+import org.jsmpp.session.Session;
+import org.jsmpp.session.SubmitMultiResult;
+import org.jsmpp.session.SubmitSmResult;
+import org.jsmpp.util.MessageId;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * A bind that the SMSC rejects while the consumer or producer starts (or
while a lazy producer creates its session)
+ * fails that start (or that exchange) at once, as a refused connection does.
It must not run the reconnect loop on the
+ * starting thread, where the start never returned while the SMSC kept
rejecting and a stop from another thread waited
+ * for it.
+ */
+class SmppBindRejectedTest extends CamelTestSupport {
+
+ @RegisterExtension
+ static AvailablePortFinder.Port port = AvailablePortFinder.find();
+
+ private final List<SMPPServerSession> serverSessions = new
CopyOnWriteArrayList<>();
+ private final AtomicInteger binds = new AtomicInteger();
+ private final AtomicInteger submitted = new AtomicInteger();
+ private volatile boolean reject = true;
+ private SMPPServerSessionListener smsc;
+
+ @BeforeEach
+ void startSmsc() throws IOException {
+ smsc = new SMPPServerSessionListener(port.getPort());
+ Thread acceptor = new Thread(this::acceptBinds, "smsc-acceptor");
+ acceptor.setDaemon(true);
+ acceptor.start();
+ }
+
+ @AfterEach
+ void stopSmsc() throws IOException {
+ smsc.close();
+ serverSessions.forEach(SMPPServerSession::close);
+ }
+
+ private void acceptBinds() {
+ try {
+ while (true) {
+ SMPPServerSession session = smsc.accept();
+ session.setMessageReceiverListener(new AcceptSubmitSm());
+ BindRequest bind = session.waitForBind(5000);
+ binds.incrementAndGet();
+ if (reject) {
+ // negative bind_resp, as for wrong credentials or a
throttled ESME; the ESME closes the connection
+ bind.reject(SMPPConstant.STAT_ESME_RBINDFAIL);
+ } else {
+ bind.accept("smsc");
+ serverSessions.add(session);
+ }
+ }
+ } catch (Exception e) {
+ // the SMSC is closed
+ }
+ }
+
+ private static String uri() {
+ // a reconnect loop would bind again every 100 ms
+ return "smpp://smppclient@localhost:" + port.getPort()
+ +
"?password=password&initialReconnectDelay=100&reconnectDelay=100";
+ }
+
+ @Test
+ void consumerStartFailsAtOnceWhenTheSmscRejectsTheBind() throws Exception {
+ List<String> received = new CopyOnWriteArrayList<>();
+ Consumer consumer = context.getEndpoint(uri())
+ .createConsumer(exchange ->
received.add(exchange.getIn().getBody(String.class)));
+ try {
+ startFailsAtOnce(consumer);
+
+ // the SMSC accepts binds again: a new start binds, and the
consumer receives
+ reject = false;
+ consumer.start();
+ await().atMost(10, TimeUnit.SECONDS).until(() ->
serverSessions.size() == 1);
+ // returns once the consumer answered the deliver_sm, which it
does after it processed the message
+ serverSessions.get(0).deliverShortMessage("CMT",
TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, "1616",
+ TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN,
"1717", new ESMClass(), (byte) 0, (byte) 1,
+ new RegisteredDelivery(0), DataCodings.ZERO,
"hello".getBytes(StandardCharsets.US_ASCII));
+ assertEquals(List.of("hello"), received);
+ } finally {
+ // without the fix the start still waits in the reconnect: let it
bind so that it ends
+ reject = false;
+ consumer.stop();
+ }
+ }
+
+ @Test
+ void producerStartFailsAtOnceWhenTheSmscRejectsTheBind() throws Exception {
+ Producer producer = context.getEndpoint(uri()).createProducer();
+ try {
+ startFailsAtOnce(producer);
+
+ // the SMSC accepts binds again: a new start binds, and the
producer sends
+ reject = false;
+ producer.start();
+ producer.process(newExchange());
+ assertEquals(1, submitted.get());
+ } finally {
+ reject = false;
+ producer.stop();
+ }
+ }
+
+ @Test
+ void lazyProducerFailsTheExchangeAtOnceWhenTheSmscRejectsTheBind() throws
Exception {
+ Producer producer = context.getEndpoint(uri() +
"&lazySessionCreation=true").createProducer();
+ producer.start();
+ try {
+ Exchange exchange = newExchange();
+ CompletableFuture<Void> send = CompletableFuture.runAsync(() -> {
+ try {
+ producer.process(exchange);
+ } catch (Exception e) {
+ throw new CompletionException(e);
+ }
+ });
+
+ // the route thread gets the bind failure; it does not wait for a
reconnect
+ ExecutionException failure =
assertThrows(ExecutionException.class, () -> send.get(5, TimeUnit.SECONDS));
+ assertNotNull(ObjectHelper.getException(IOException.class,
failure));
+ await().during(1, TimeUnit.SECONDS).atMost(2,
TimeUnit.SECONDS).until(() -> binds.get() == 1);
+
+ // the SMSC accepts binds again: the next exchange creates the
session and is sent
+ reject = false;
+ producer.process(newExchange());
+ assertEquals(1, submitted.get());
+ } finally {
+ reject = false;
+ producer.stop();
+ }
+ }
+
+ private void startFailsAtOnce(Service service) throws Exception {
+ CompletableFuture<Void> start =
CompletableFuture.runAsync(service::start);
+
+ // the start fails with the bind error, and the bind is not tried again
+ ExecutionException failure = assertThrows(ExecutionException.class, ()
-> start.get(5, TimeUnit.SECONDS));
+ assertNotNull(ObjectHelper.getException(IOException.class, failure));
+ await().during(1, TimeUnit.SECONDS).atMost(2,
TimeUnit.SECONDS).until(() -> binds.get() == 1);
+
+ // a stop from another thread does not wait for anything
+ CompletableFuture.runAsync(service::stop).get(5, TimeUnit.SECONDS);
+ }
+
+ private Exchange newExchange() {
+ Exchange exchange = context.getEndpoint(uri()).createExchange();
+ exchange.getIn().setBody("hello");
+ return exchange;
+ }
+
+ /** Accepts every submit_sm; the tests send nothing else. */
+ private final class AcceptSubmitSm implements
ServerMessageReceiverListener {
+
+ @Override
+ public SubmitSmResult onAcceptSubmitSm(SubmitSm submitSm,
SMPPServerSession source)
+ throws ProcessRequestException {
+ submitted.incrementAndGet();
+ try {
+ return new SubmitSmResult(new MessageId("1"), new
OptionalParameter[0]);
+ } catch (PDUStringException e) {
+ throw new ProcessRequestException(e.getMessage(),
SMPPConstant.STAT_ESME_RSYSERR, e);
+ }
+ }
+
+ @Override
+ public SubmitMultiResult onAcceptSubmitMulti(SubmitMulti submitMulti,
SMPPServerSession source)
+ throws ProcessRequestException {
+ throw notSupported();
+ }
+
+ @Override
+ public QuerySmResult onAcceptQuerySm(QuerySm querySm,
SMPPServerSession source) throws ProcessRequestException {
+ throw notSupported();
+ }
+
+ @Override
+ public void onAcceptReplaceSm(ReplaceSm replaceSm, SMPPServerSession
source) throws ProcessRequestException {
+ throw notSupported();
+ }
+
+ @Override
+ public void onAcceptCancelSm(CancelSm cancelSm, SMPPServerSession
source) throws ProcessRequestException {
+ throw notSupported();
+ }
+
+ @Override
+ public BroadcastSmResult onAcceptBroadcastSm(BroadcastSm broadcastSm,
SMPPServerSession source)
+ throws ProcessRequestException {
+ throw notSupported();
+ }
+
+ @Override
+ public void onAcceptCancelBroadcastSm(CancelBroadcastSm
cancelBroadcastSm, SMPPServerSession source)
+ throws ProcessRequestException {
+ throw notSupported();
+ }
+
+ @Override
+ public QueryBroadcastSmResult
onAcceptQueryBroadcastSm(QueryBroadcastSm queryBroadcastSm, SMPPServerSession
source)
+ throws ProcessRequestException {
+ throw notSupported();
+ }
+
+ @Override
+ public DataSmResult onAcceptDataSm(DataSm dataSm, Session source)
throws ProcessRequestException {
+ throw notSupported();
+ }
+
+ private ProcessRequestException notSupported() {
+ return new ProcessRequestException("not supported by the test
SMSC", SMPPConstant.STAT_ESME_RINVCMDID);
+ }
+ }
+}
diff --git
a/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConsumerTest.java
b/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConsumerTest.java
index bb1b04e7a4ed..97a76b0a9ada 100644
---
a/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConsumerTest.java
+++
b/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppConsumerTest.java
@@ -32,6 +32,7 @@ import org.jsmpp.extra.SessionState;
import org.jsmpp.session.BindParameter;
import org.jsmpp.session.MessageReceiverListener;
import org.jsmpp.session.SMPPSession;
+import org.jsmpp.session.Session;
import org.jsmpp.session.SessionStateListener;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -176,6 +177,16 @@ class SmppConsumerTest {
@ParameterizedTest
@EnumSource(value = SessionState.class, names = { "UNBOUND", "CLOSED" })
public void
internalSessionStateListenerShouldCloseSessionAndReconnect(SessionState
sessionState) throws Exception {
+ assertListenerClosesSessionAndReconnects(sessionState, session);
+ }
+
+ @Test
+ public void
internalSessionStateListenerShouldReconnectWhenTheSourceIsNull() throws
Exception {
+ // no bind runs on this thread, so the session being bound here is
null as well: a null source still reconnects
+ assertListenerClosesSessionAndReconnects(SessionState.CLOSED, null);
+ }
+
+ private void assertListenerClosesSessionAndReconnects(SessionState
sessionState, Session source) throws Exception {
try (MockedStatic<SmppUtils> smppUtilsMock =
mockStatic(SmppUtils.class)) {
SessionStateListener sessionStateListener = (SessionStateListener)
ReflectionHelper
.getField(SmppConsumer.class.getDeclaredField("internalSessionStateListener"),
consumer);
@@ -200,7 +211,7 @@ class SmppConsumerTest {
consumer.doStart();
- sessionStateListener.onStateChange(sessionState,
SessionState.BOUND_RX, null);
+ sessionStateListener.onStateChange(sessionState,
SessionState.BOUND_RX, source);
verify(session).unbindAndClose();
}
}
diff --git
a/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppProducerTest.java
b/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppProducerTest.java
index 26e40877f924..dfe3376035f4 100644
---
a/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppProducerTest.java
+++
b/components/camel-smpp/src/test/java/org/apache/camel/component/smpp/SmppProducerTest.java
@@ -29,6 +29,7 @@ import org.jsmpp.bean.TypeOfNumber;
import org.jsmpp.extra.SessionState;
import org.jsmpp.session.BindParameter;
import org.jsmpp.session.SMPPSession;
+import org.jsmpp.session.Session;
import org.jsmpp.session.SessionStateListener;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -147,6 +148,16 @@ class SmppProducerTest {
@ParameterizedTest
@EnumSource(value = SessionState.class, names = { "UNBOUND", "CLOSED" })
public void
internalSessionStateListenerShouldCloseSessionAndReconnect(SessionState
sessionState) throws Exception {
+ assertListenerClosesSessionAndReconnects(sessionState, session);
+ }
+
+ @Test
+ public void
internalSessionStateListenerShouldReconnectWhenTheSourceIsNull() throws
Exception {
+ // no bind runs on this thread, so the session being bound here is
null as well: a null source still reconnects
+ assertListenerClosesSessionAndReconnects(SessionState.CLOSED, null);
+ }
+
+ private void assertListenerClosesSessionAndReconnects(SessionState
sessionState, Session source) throws Exception {
try (MockedStatic<SmppUtils> smppUtilsMock =
mockStatic(SmppUtils.class)) {
ScheduledExecutorService reconnectService =
(ScheduledExecutorService) ReflectionHelper
.getField(SmppProducer.class.getDeclaredField("reconnectService"), producer);
@@ -173,7 +184,7 @@ class SmppProducerTest {
producer.doStart();
- sessionStateListener.onStateChange(SessionState.CLOSED,
SessionState.BOUND_TX, null);
+ sessionStateListener.onStateChange(sessionState,
SessionState.BOUND_TX, source);
verify(session).unbindAndClose();
}
}