From 60eea4e2fdf10204147a22e78a165ed087fddbef Mon Sep 17 00:00:00 2001 From: Fiete Ostkamp Date: Wed, 10 Jan 2024 11:59:21 +0100 Subject: Ensure HttpEntry bean is request scoped in aai-common - change beans to request scoped since the transaction handling inside it is not thread-safe - bean injection in jersey is "request" scoped by default, but in a spring web context it is "prototype" - in the prototype scope, multiple threads could access the same HttpEntry Issue-ID: AAI-3723 Change-Id: I083e3b06cdbe4491f22746033cdcc80aa48a2d1b Signed-off-by: Fiete Ostkamp --- aai-core/src/main/java/org/onap/aai/config/RestBeanConfig.java | 8 ++++---- aai-core/src/test/java/org/onap/aai/AAISetup.java | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'aai-core') diff --git a/aai-core/src/main/java/org/onap/aai/config/RestBeanConfig.java b/aai-core/src/main/java/org/onap/aai/config/RestBeanConfig.java index 4dc8860e..123d530a 100644 --- a/aai-core/src/main/java/org/onap/aai/config/RestBeanConfig.java +++ b/aai-core/src/main/java/org/onap/aai/config/RestBeanConfig.java @@ -5,6 +5,7 @@ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Modifications Copyright © 2018 IBM. + * Modifications Copyright © 2024 DEUTSCHE TELEKOM AG. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,21 +26,20 @@ package org.onap.aai.config; import org.onap.aai.introspection.ModelType; import org.onap.aai.rest.db.HttpEntry; import org.onap.aai.serialization.engines.QueryStyle; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Scope; +import org.springframework.web.context.annotation.RequestScope; @Configuration public class RestBeanConfig { + @RequestScope @Bean(name = "traversalUriHttpEntry") - @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE) public HttpEntry traversalUriHttpEntry() { return new HttpEntry(ModelType.MOXY, QueryStyle.TRAVERSAL_URI); } + @RequestScope @Bean(name = "traversalHttpEntry") - @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE) public HttpEntry traversalHttpEntry() { return new HttpEntry(ModelType.MOXY, QueryStyle.TRAVERSAL); } diff --git a/aai-core/src/test/java/org/onap/aai/AAISetup.java b/aai-core/src/test/java/org/onap/aai/AAISetup.java index 72d8273a..a44226c8 100644 --- a/aai-core/src/test/java/org/onap/aai/AAISetup.java +++ b/aai-core/src/test/java/org/onap/aai/AAISetup.java @@ -43,7 +43,9 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.rules.SpringClassRule; import org.springframework.test.context.junit4.rules.SpringMethodRule; +import org.springframework.test.context.web.WebAppConfiguration; +@WebAppConfiguration @ContextConfiguration( classes = {ConfigConfiguration.class, AAIConfigTranslator.class, EdgeIngestor.class, EdgeSerializer.class, NodeIngestor.class, SpringContextAware.class, IntrospectionConfig.class, RestBeanConfig.class, -- cgit 1.2.3-korg