Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2023 BSI Business Systems Integration AG
* Copyright (c) 2010, 2026 BSI Business Systems Integration AG
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -131,7 +131,7 @@ public PublishInput withProperty(final String name, final String value) {
/**
* Sets multiple properties to be included as message property.
* <p>
* This is a convenience method calling {@link #withProperties(String, String)} multiple times.
* This is a convenience method calling {@link #withProperty(String, String)} multiple times.
*/
public PublishInput withProperties(final Map<String, String> props) {
if (props != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2023 BSI Business Systems Integration AG
* Copyright (c) 2010, 2026 BSI Business Systems Integration AG
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -29,6 +29,7 @@
import org.eclipse.scout.rt.platform.BEANS;
import org.eclipse.scout.rt.platform.Bean;
import org.eclipse.scout.rt.platform.exception.PlatformException;
import org.eclipse.scout.rt.platform.exception.ProcessingException;

/**
* Allows to write a JMS message.
Expand All @@ -43,6 +44,7 @@ public class JmsMessageWriter {
protected IMarshaller m_marshaller;
protected Map<String, String> m_marshallerContext;
protected IDataObjectMapper m_contextDataObjectMapper;
protected long m_maxMessageSize = 0;

/**
* Initializes this writer.
Expand All @@ -56,6 +58,11 @@ protected JmsMessageWriter init(final Session session, final IMarshaller marshal
return this;
}

public JmsMessageWriter withMaxMessageSize(final long maxMessageSize) {
this.m_maxMessageSize = maxMessageSize;
return this;
}

/**
* Creates the message of the given type.
*/
Expand Down Expand Up @@ -91,10 +98,18 @@ public JmsMessageWriter writeTransferObject(final Object transferObject) throws

switch (m_marshaller.getMessageType()) {
case MESSAGE_TYPE_TEXT:
writeTextMessage((TextMessage) m_message, (String) transportObject);
String text = (String) transportObject;
if (m_maxMessageSize > 0 && text != null && m_maxMessageSize < text.length()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can (reliably) derive the actual message size from the text.length() since some charactes of text might need more bytes when encoded than others.

throw new ProcessingException("Message too large: {} > {}.", text.length(), m_maxMessageSize);
}
writeTextMessage((TextMessage) m_message, text);
break;
case MESSAGE_TYPE_BYTES:
writeBytesMessage((BytesMessage) m_message, (byte[]) transportObject);
byte[] data = (byte[]) transportObject;
if (m_maxMessageSize > 0 && data != null && m_maxMessageSize < data.length) {
throw new ProcessingException("Message too large: {} > {}.", data.length, m_maxMessageSize);
}
writeBytesMessage((BytesMessage) m_message, data);
break;
case MESSAGE_TYPE_NO_PAYLOAD:
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2023 BSI Business Systems Integration AG
* Copyright (c) 2010, 2026 BSI Business Systems Integration AG
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -131,6 +131,11 @@ public class JmsMomImplementor implements IMomImplementor {
*/
public static final String JMS_REQUEST_CANCELLATION_MESSAGE_CONSUMER_JOB_RECEIVE_TIMEOUT = "scout.mom.jms.requestCancellationMessageConsumerJobReceiveTimeout";

/**
* Key to set {@link #m_requestMaxMessageSize}
*/
public static final String JMS_REQUEST_MAX_MESSAGE_SIZE = "scout.mom.jms.requestMaxMessageSize";

/**
* Key to set {@link #m_subscriptionAwaitStartedSeconds}, if value is not set {@link #WAIT_TIME_INFINITE} is used as a
* default to wait infinitely (the {@link #WAIT_TIME_INFINITE} value may also be used to configure an infinite wait
Expand Down Expand Up @@ -169,6 +174,7 @@ public class JmsMomImplementor implements IMomImplementor {
protected long m_messageConsumerJobReceiveTimeout = 0L;
protected long m_replyMessageConsumerJobReceiveTimeout = 0L;
protected long m_requestCancellationMessageConsumerJobReceiveTimeout = 0L;
protected long m_requestMaxMessageSize = 0L;

@Override
public void init(final Map<Object, Object> properties) throws Exception {
Expand All @@ -180,6 +186,7 @@ public void init(final Map<Object, Object> properties) throws Exception {
m_messageConsumerJobReceiveTimeout = NumberUtility.nvl(TypeCastUtility.castValue(properties.get(JMS_MESSAGE_CONSUMER_JOB_RECEIVE_TIMEOUT), Long.class), 0L);
m_replyMessageConsumerJobReceiveTimeout = NumberUtility.nvl(TypeCastUtility.castValue(properties.get(JMS_REPLY_MESSAGE_CONSUMER_JOB_RECEIVE_TIMEOUT), Long.class), 0L);
m_requestCancellationMessageConsumerJobReceiveTimeout = NumberUtility.nvl(TypeCastUtility.castValue(properties.get(JMS_REQUEST_CANCELLATION_MESSAGE_CONSUMER_JOB_RECEIVE_TIMEOUT), Long.class), 0L);
m_requestMaxMessageSize = NumberUtility.nvl(TypeCastUtility.castValue(properties.get(JMS_REQUEST_MAX_MESSAGE_SIZE), Long.class), 0L);
m_subscriptionAwaitStartedSeconds = NumberUtility.nvl(TypeCastUtility.castValue(properties.get(JMS_SUBSCRIPTION_AWAIT_STARTED_TIMEOUT), Integer.class), WAIT_TIME_INFINITE);
m_contextEnvironment = createContextEnvironment(properties);
m_connectionFactory = createConnectionFactory(properties);
Expand Down Expand Up @@ -465,6 +472,7 @@ protected <REQUEST, REPLY> Message requestImpl(final IBiDestination<REQUEST, REP

// send request message
JmsMessageWriter messageWriter = JmsMessageWriter.newInstance(sessionProvider.getSession(), resolveMarshaller(destination))
.withMaxMessageSize(m_requestMaxMessageSize)
.writeReplyTo(temporaryQueue)
.writeReplyId(replyId)
.writeProperties(input.getProperties())
Expand Down Expand Up @@ -673,6 +681,7 @@ public Connection getConnection() {
public <DTO> void send(IJmsSessionProvider sessionProvider, IDestination<DTO> destination, DTO transferObject, PublishInput input) throws JMSException {
Session session = sessionProvider.getSession();
JmsMessageWriter messageWriter = JmsMessageWriter.newInstance(session, resolveMarshaller(destination))
.withMaxMessageSize(m_requestMaxMessageSize)
.writeTransferObject(transferObject)
.writeReplyTo(resolveJmsDestination(input.getReplyTo(), session))
.writeProperties(input.getProperties());
Expand Down
Loading