Skip to content

Commit

Permalink
Merge pull request #5947 from arieki/FISH-6238-P6
Browse files Browse the repository at this point in the history
FISH-6238 Microprofile Interceptors [@fallback@/CircuitBreaker] are not getting invoked if the EJB is a @stateless Bean
  • Loading branch information
arieki authored Sep 21, 2022
2 parents adb03c5 + 8eacf14 commit 0908b50
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import fish.payara.microprofile.faulttolerance.FaultToleranceService;
import fish.payara.microprofile.faulttolerance.policy.FaultTolerancePolicy;
import fish.payara.microprofile.faulttolerance.service.Stereotypes;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.InvocationContext;
import org.eclipse.microprofile.faulttolerance.exceptions.FaultToleranceDefinitionException;
import org.glassfish.internal.api.Globals;

Expand All @@ -51,7 +53,6 @@
import jakarta.enterprise.inject.Instance;
import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.inject.Inject;
import jakarta.interceptor.InvocationContext;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.util.Map;
Expand All @@ -77,6 +78,7 @@ public class FaultToleranceInterceptor implements Stereotypes, Serializable {
protected static final String PAYARA_FAULT_TOLERANCE_INTERCEPTOR_EXECUTED =
"fish.payara.microprofile.faulttolerance.executed";

@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {
if (!shouldIntercept(context)) {
return context.proceed();
Expand Down
14 changes: 14 additions & 0 deletions appserver/tests/payara-samples/samples/reproducers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>reproducers</artifactId>
<name>Payara Samples - Reproducers</name>

<properties>
<maven.compiler.source>11</maven.compiler.source>
Expand All @@ -63,6 +64,19 @@
<groupId>org.eclipse.microprofile.metrics</groupId>
<artifactId>microprofile-metrics-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<version>4.1</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>10.0.0</version>
<scope>provided</scope>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2022 Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://github.com/payara/Payara/blob/master/LICENSE.txt
* See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* The Payara Foundation designates this particular file as subject to the "Classpath"
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package fish.payara.samples.resource.fish6238;

import jakarta.inject.Singleton;
import org.eclipse.microprofile.faulttolerance.CircuitBreaker;
import org.eclipse.microprofile.faulttolerance.Fallback;

@Singleton
public class SingletonBean {

@Fallback(fallbackMethod = "fallback")
@CircuitBreaker
public String sayHello(String message) {
throw new RuntimeException("Testing the fallback method");
}

public String fallback(String message) {
return "fallback singleton";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2022 Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://github.com/payara/Payara/blob/master/LICENSE.txt
* See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* The Payara Foundation designates this particular file as subject to the "Classpath"
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package fish.payara.samples.resource.fish6238;

import jakarta.ejb.Stateless;
import org.eclipse.microprofile.faulttolerance.CircuitBreaker;
import org.eclipse.microprofile.faulttolerance.Fallback;

@Stateless
public class StatelessBean {

@Fallback(fallbackMethod = "fallback")
@CircuitBreaker
public String sayHello(String message) {
throw new RuntimeException("Testing the fallback method");
}

public String fallback(String message) {
return "fallback stateless";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2022 Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://github.com/payara/Payara/blob/master/LICENSE.txt
* See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* The Payara Foundation designates this particular file as subject to the "Classpath"
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package fish.payara.samples.resource.fish6238;

import fish.payara.samples.resource.fish6238.SingletonBean;
import fish.payara.samples.resource.fish6238.StatelessBean;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;

import jakarta.inject.Inject;
import static org.junit.Assert.assertEquals;


@RunWith(Arquillian.class)
public class FaultToleranceTest {

@Inject
private SingletonBean singletonBean;

@Inject
private StatelessBean statelessBean;

@Deployment
public static WebArchive deployment() {
return ShrinkWrap.create(WebArchive.class)
.addClasses(SingletonBean.class, StatelessBean.class);
}

@Test
public void statelessBeanTest() {
assertEquals(statelessBean.sayHello("MyMessage"), "fallback stateless");
}

@Test
public void singletonBeanTest() {
assertEquals(singletonBean.sayHello("MyMessage"), "fallback singleton");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2016-2021] [Payara Foundation and/or its affiliates]
// Portions Copyright [2016-2022] [Payara Foundation and/or its affiliates]

package org.glassfish.weld.services;

Expand All @@ -53,7 +53,6 @@
import java.lang.reflect.Method;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import jakarta.annotation.PostConstruct;
Expand All @@ -68,7 +67,7 @@
import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.glassfish.cdi.CDILoggerInfo;
import jakarta.interceptor.InvocationContext;
import org.glassfish.ejb.api.EjbContainerServices;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.weld.ejb.EjbDescriptorImpl;
Expand Down Expand Up @@ -282,7 +281,7 @@ private List<EjbInterceptor> makeInterceptorChain(InterceptionType interceptionT
Class<?> interceptorClass = next.getBeanClass();

while (interceptorClass != null && !interceptorClass.equals(Object.class)) {
String methodName = getInterceptorMethod( interceptorClass, getInterceptorAnnotationType(interceptionType));
String methodName = getInterceptorMethod(interceptorClass, getInterceptorAnnotationType(interceptionType));
if (methodName != null) {
LifecycleCallbackDescriptor lifecycleDesc = new LifecycleCallbackDescriptor();

Expand Down

0 comments on commit 0908b50

Please sign in to comment.