diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/grease/GreaseInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/grease/GreaseInterceptor.java index 0eca76abc..291e55aae 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/grease/GreaseInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/grease/GreaseInterceptor.java @@ -24,6 +24,7 @@ import static com.predic8.membrane.core.interceptor.Interceptor.Flow.*; import static com.predic8.membrane.core.interceptor.Outcome.*; +import static java.lang.Double.parseDouble; import static java.util.EnumSet.*; @MCElement(name = "greaser") @@ -63,8 +64,8 @@ public Outcome handleResponse(Exchange exc) throws Exception { } @MCAttribute - public void setRate(double rate) { - this.rate = Math.max(0, Math.min(1, rate)); + public void setRate(String rate) { + this.rate = Math.max(0, Math.min(1, parseDouble(rate))); } public double getRate() { diff --git a/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptor.java b/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptor.java index 1d56b3a9b..90c4ad691 100644 --- a/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptor.java @@ -40,9 +40,11 @@ public class ApiDocsInterceptor extends AbstractInterceptor { @Override public Outcome handleRequest(Exchange exc) throws Exception { - if(!initialized) { - ruleApiSpecs = initializeRuleApiSpecs(); - initialized = true; + synchronized(this) { + if (!initialized) { + ruleApiSpecs = initializeRuleApiSpecs(); + initialized = true; + } } var publisher = new OpenAPIPublisher(ruleApiSpecs); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/grease/GreaseInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/grease/GreaseInterceptorTest.java index 071f11126..49abcf62d 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/grease/GreaseInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/grease/GreaseInterceptorTest.java @@ -39,7 +39,7 @@ class GreaseInterceptorTest { @BeforeEach void setup() { greaseInterceptor = new GreaseInterceptor(); - greaseInterceptor.setRate(1); + greaseInterceptor.setRate("1"); greaseInterceptor.setStrategies(List.of(new JsonGrease() {{ setAdditionalProperties(false);}})); } @@ -65,25 +65,25 @@ void testRate() throws Exception { // Test with rate = 1 assertNotEquals(json, requestExc.getRequest().getBodyAsStringDecoded()); - greaseInterceptor.setRate(0.1); + greaseInterceptor.setRate("0.1"); assertEquals(0.1, calculateRate(greaseInterceptor, json), 0.02); - greaseInterceptor.setRate(0.5); + greaseInterceptor.setRate("0.5"); assertEquals(0.5, calculateRate(greaseInterceptor, json), 0.02); - greaseInterceptor.setRate(0.01); + greaseInterceptor.setRate("0.01"); assertEquals(0.01, calculateRate(greaseInterceptor, json), 0.02); } @Test void testSetRate() { - greaseInterceptor.setRate(0.5); + greaseInterceptor.setRate("0.5"); assertEquals(0.5, greaseInterceptor.getRate()); - greaseInterceptor.setRate(1.5); + greaseInterceptor.setRate("1.5"); assertEquals(1.0, greaseInterceptor.getRate()); - greaseInterceptor.setRate(-0.5); + greaseInterceptor.setRate("-0.5"); assertEquals(0.0, greaseInterceptor.getRate()); - greaseInterceptor.setRate(0.0001); + greaseInterceptor.setRate("0.0001"); assertEquals(0.0001, greaseInterceptor.getRate()); }