-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
286 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
repository/src/main/java/org/alfresco/messaging/LoggingDeadLetterQueue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
repository/src/main/java/org/alfresco/messaging/jackson/ObjectMapperFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
repository/src/main/java/org/alfresco/repo/events/CamelMessageProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
repository/src/main/java/org/alfresco/repo/events/MessageProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
50 changes: 50 additions & 0 deletions
50
repository/src/main/java/org/alfresco/repo/events/MessagingException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters