Skip to content

Commit

Permalink
ACS-6057 Gytheio removal (#2206)
Browse files Browse the repository at this point in the history
  • Loading branch information
pzhyland authored Sep 25, 2023
1 parent dee199d commit d1585e4
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 31 deletions.
4 changes: 0 additions & 4 deletions packaging/distribution/src/main/resources/licenses/notice.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
<dependency.xercesImpl.version>2.12.2</dependency.xercesImpl.version>
<dependency.slf4j.version>2.0.7</dependency.slf4j.version>
<dependency.log4j.version>2.20.0</dependency.log4j.version>
<dependency.gytheio.version>0.20.0-A1</dependency.gytheio.version>
<dependency.groovy.version>3.0.19</dependency.groovy.version>
<dependency.tika.version>2.4.1</dependency.tika.version>
<dependency.spring-security.version>6.1.3</dependency.spring-security.version>
Expand Down Expand Up @@ -1036,7 +1035,7 @@
<configuration>
<failOnMissing>true</failOnMissing>
<excludedScopes>provided,test</excludedScopes>
<excludedGroups>^(org\.alfresco|com\.alfresco|org\.activiti|org\.gytheio).*</excludedGroups>
<excludedGroups>^(org\.alfresco|com\.alfresco|org\.activiti).*</excludedGroups>
<failIfWarning>true</failIfWarning>
<includedLicenses>
https://raw.githubusercontent.com/Alfresco/third-party-license-overrides/master/includedLicenses.txt
Expand Down
15 changes: 0 additions & 15 deletions repository/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -560,21 +560,6 @@
<artifactId>alfresco-sync-events</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>org.gytheio</groupId>
<artifactId>gytheio-messaging-camel</artifactId>
<version>${dependency.gytheio.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
* #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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
* #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> T readValue(InputStream inputStream, Class<T> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
* #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<String, Object> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
* #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;
}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
* #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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<bean id="eventsDispatcher" class="org.gytheio.messaging.camel.CamelMessageProducer">
<property name="producer" ref="camelProducerTemplate" />
<property name="endpoint" value="direct:alfresco.events" />
<bean id="eventsDispatcher" class="org.alfresco.repo.events.CamelMessageProducer">
<constructor-arg ref="camelProducerTemplate" />
<constructor-arg value="direct:alfresco.events" />
</bean>

<bean id="eventsRegistry" class="org.alfresco.sync.events.EventRegistryImpl">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<context:component-scan base-package="org.alfresco.messaging.camel.configuration"/>

<bean id="messagingObjectMapper" class="org.gytheio.messaging.jackson.ObjectMapperFactory"
<bean id="messagingObjectMapper" class="org.alfresco.messaging.jackson.ObjectMapperFactory"
factory-method="createInstance" />

<bean id="defaultDataFormat" class="org.apache.camel.component.jackson.JacksonDataFormat">
Expand Down Expand Up @@ -96,6 +96,6 @@
</bean>

<!-- In the default routes, this is where a message goes if no queue is specified -->
<bean id="deadLetterQueue" class="org.gytheio.messaging.LoggingDeadLetterQueue" />
<bean id="deadLetterQueue" class="org.alfresco.messaging.LoggingDeadLetterQueue" />

</beans>

0 comments on commit d1585e4

Please sign in to comment.