diff --git a/packaging/distribution/src/main/resources/licenses/notice.txt b/packaging/distribution/src/main/resources/licenses/notice.txt index d76401367cd..291b511332d 100644 --- a/packaging/distribution/src/main/resources/licenses/notice.txt +++ b/packaging/distribution/src/main/resources/licenses/notice.txt @@ -208,10 +208,6 @@ Hibernate http://www.hibernate.org/ jid3lib http://javamusictag.sourceforge.net/ TinyMCE http://www.tinymce.com/ - -=== LGPL 3.0 === -Gytheio https://github.com/Alfresco/gytheio - === MIT License === Bouncy Castle http://www.bouncycastle.org/ diff --git a/pom.xml b/pom.xml index c19e380969f..de9870f9d05 100644 --- a/pom.xml +++ b/pom.xml @@ -79,7 +79,6 @@ 2.12.2 2.0.7 2.20.0 - 0.20.0-A1 3.0.19 2.4.1 6.1.3 @@ -1036,7 +1035,7 @@ true provided,test - ^(org\.alfresco|com\.alfresco|org\.activiti|org\.gytheio).* + ^(org\.alfresco|com\.alfresco|org\.activiti).* true https://raw.githubusercontent.com/Alfresco/third-party-license-overrides/master/includedLicenses.txt diff --git a/repository/pom.xml b/repository/pom.xml index df870143a7d..f01fb8b6d59 100644 --- a/repository/pom.xml +++ b/repository/pom.xml @@ -560,21 +560,6 @@ alfresco-sync-events 1.2.14 - - org.gytheio - gytheio-messaging-camel - ${dependency.gytheio.version} - - - org.apache.camel - camel-core - - - org.apache.camel - camel-jackson - - - org.apache.camel camel-core diff --git a/repository/src/main/java/org/alfresco/messaging/LoggingDeadLetterQueue.java b/repository/src/main/java/org/alfresco/messaging/LoggingDeadLetterQueue.java new file mode 100644 index 00000000000..a683dfd14ea --- /dev/null +++ b/repository/src/main/java/org/alfresco/messaging/LoggingDeadLetterQueue.java @@ -0,0 +1,42 @@ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2023 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.messaging; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class LoggingDeadLetterQueue +{ + private static final Logger LOG = LoggerFactory.getLogger(LoggingDeadLetterQueue.class); + + public void onReceive(Object message) + { + if (message != null) + { + LOG.debug("Received:\n\n{}}\n\n", message); + } + } +} diff --git a/repository/src/main/java/org/alfresco/messaging/jackson/ObjectMapperFactory.java b/repository/src/main/java/org/alfresco/messaging/jackson/ObjectMapperFactory.java new file mode 100644 index 00000000000..1223a93a25d --- /dev/null +++ b/repository/src/main/java/org/alfresco/messaging/jackson/ObjectMapperFactory.java @@ -0,0 +1,93 @@ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2023 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.messaging.jackson; + +import java.io.IOException; +import java.io.InputStream; +import java.io.Serial; +import java.io.StringWriter; + +import org.apache.commons.io.IOUtils; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; + +public class ObjectMapperFactory +{ + private ObjectMapperFactory() + { + //no instantiation + } + + public static ObjectMapper createInstance() + { + QpidJsonBodyCleanerObjectMapper mapper = new QpidJsonBodyCleanerObjectMapper(); + mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY); + return mapper; + } + + private static class QpidJsonBodyCleanerObjectMapper extends ObjectMapper + { + @Serial + private static final long serialVersionUID = 2568701685293341501L; + + private static final String DEFAULT_ENCODING = "utf8"; + + public T readValue(InputStream inputStream, Class valueType) throws IOException + { + try + { + // Try to unmarshal normally + if (inputStream.markSupported()) + { + inputStream.mark(1024 * 512); + } + return super.readValue(inputStream, valueType); + } + catch (JsonParseException e) + { + if (!inputStream.markSupported()) + { + // We can't reset this stream, bail out + throw e; + } + // Reset the stream + inputStream.reset(); + } + // Clean the message body and try again + StringWriter writer = new StringWriter(); + IOUtils.copy(inputStream, writer, DEFAULT_ENCODING); + String content = writer.toString(); + content = content.substring(content.indexOf('{')); + return readValue(content, valueType); + } + } +} diff --git a/repository/src/main/java/org/alfresco/repo/events/AbstractEventsService.java b/repository/src/main/java/org/alfresco/repo/events/AbstractEventsService.java index d71f24f919e..87338e6fb92 100644 --- a/repository/src/main/java/org/alfresco/repo/events/AbstractEventsService.java +++ b/repository/src/main/java/org/alfresco/repo/events/AbstractEventsService.java @@ -74,8 +74,6 @@ import org.apache.chemistry.opencmis.commons.server.CallContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.gytheio.messaging.MessageProducer; -import org.gytheio.messaging.MessagingException; import com.google.common.base.Splitter; import com.google.common.collect.Sets; @@ -294,7 +292,7 @@ protected boolean shouldSendCommitEvent() } /** - * Filter out event before sending them to {@link org.gytheio.messaging.MessageProducer} + * Filter out event before sending them to {@link MessageProducer} * * @param events the events to be filtered * diff --git a/repository/src/main/java/org/alfresco/repo/events/CamelMessageProducer.java b/repository/src/main/java/org/alfresco/repo/events/CamelMessageProducer.java new file mode 100644 index 00000000000..6bc7ee6219d --- /dev/null +++ b/repository/src/main/java/org/alfresco/repo/events/CamelMessageProducer.java @@ -0,0 +1,57 @@ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2023 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.repo.events; + +import java.util.Map; +import java.util.Objects; + +import org.apache.camel.ProducerTemplate; + +class CamelMessageProducer implements MessageProducer +{ + private static final Map AMQP_HEADERS = Map.of("JMS_AMQP_MESSAGE_FORMAT", 0L); + private final ProducerTemplate producer; + private final String endpoint; + + CamelMessageProducer(ProducerTemplate producer, String endpoint) + { + this.producer = Objects.requireNonNull(producer); + this.endpoint = Objects.requireNonNull(endpoint); + } + + @Override + public void send(Object message) + { + try + { + producer.sendBodyAndHeaders(endpoint, message, AMQP_HEADERS); + } + catch (Exception e) + { + throw new MessagingException("Could not send message", e); + } + } +} diff --git a/repository/src/main/java/org/alfresco/repo/events/ExceptionEventsServiceImpl.java b/repository/src/main/java/org/alfresco/repo/events/ExceptionEventsServiceImpl.java index a683be3b188..d4a9a7e2a0c 100644 --- a/repository/src/main/java/org/alfresco/repo/events/ExceptionEventsServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/events/ExceptionEventsServiceImpl.java @@ -30,8 +30,6 @@ import org.alfresco.repo.tenant.TenantUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.gytheio.messaging.MessageProducer; -import org.gytheio.messaging.MessagingException; public class ExceptionEventsServiceImpl extends AbstractEventsService implements ExceptionEventsService { diff --git a/repository/src/main/java/org/alfresco/repo/events/MessageProducer.java b/repository/src/main/java/org/alfresco/repo/events/MessageProducer.java new file mode 100644 index 00000000000..88b9288f66e --- /dev/null +++ b/repository/src/main/java/org/alfresco/repo/events/MessageProducer.java @@ -0,0 +1,37 @@ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2023 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.repo.events; + +public interface MessageProducer +{ + /** + * Send the given POJO message to the default queue for the producer + * + * @param message message to send + * @throws MessagingException on failure + */ + void send(Object message) throws MessagingException; +} diff --git a/repository/src/main/java/org/alfresco/repo/events/MessagingException.java b/repository/src/main/java/org/alfresco/repo/events/MessagingException.java new file mode 100644 index 00000000000..25760b8a634 --- /dev/null +++ b/repository/src/main/java/org/alfresco/repo/events/MessagingException.java @@ -0,0 +1,50 @@ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2023 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.repo.events; + +import java.io.Serial; +import java.time.LocalDate; +import java.util.concurrent.atomic.AtomicInteger; + +public class MessagingException extends RuntimeException +{ + @Serial + private static final long serialVersionUID = 8192266871339806688L; + private static final AtomicInteger ERROR_COUNTER = new AtomicInteger(); + + public MessagingException(String message, Throwable cause) + { + super(buildErrorLogNumber(message), cause); + } + + private static String buildErrorLogNumber(String message) + { + final LocalDate today = LocalDate.now(); + message = message == null ? "" : message; + + return "%02d%02d%04d %s".formatted(today.getMonthValue(), today.getDayOfMonth(), ERROR_COUNTER.getAndIncrement(), message); + } +} diff --git a/repository/src/main/resources/alfresco/subsystems/Events/default/events-context.xml b/repository/src/main/resources/alfresco/subsystems/Events/default/events-context.xml index 5385cd85c27..f9ea0ae82e6 100644 --- a/repository/src/main/resources/alfresco/subsystems/Events/default/events-context.xml +++ b/repository/src/main/resources/alfresco/subsystems/Events/default/events-context.xml @@ -9,9 +9,9 @@ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> - - - + + + diff --git a/repository/src/main/resources/alfresco/subsystems/Messaging/default/messaging-context.xml b/repository/src/main/resources/alfresco/subsystems/Messaging/default/messaging-context.xml index 7aeb272667a..6ccc7bc8ef6 100644 --- a/repository/src/main/resources/alfresco/subsystems/Messaging/default/messaging-context.xml +++ b/repository/src/main/resources/alfresco/subsystems/Messaging/default/messaging-context.xml @@ -11,7 +11,7 @@ - @@ -96,6 +96,6 @@ - +