http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-events/src/main/java/org/superbiz/cdi/events/Notifier.java ---------------------------------------------------------------------- diff --git a/examples/cdi-events/src/main/java/org/superbiz/cdi/events/Notifier.java b/examples/cdi-events/src/main/java/org/superbiz/cdi/events/Notifier.java index 06e6ff7..1b0b811 100644 --- a/examples/cdi-events/src/main/java/org/superbiz/cdi/events/Notifier.java +++ b/examples/cdi-events/src/main/java/org/superbiz/cdi/events/Notifier.java @@ -1,35 +1,35 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.cdi.events; - -import javax.ejb.Schedule; -import javax.ejb.Singleton; -import javax.enterprise.event.Event; -import javax.inject.Inject; -import java.util.Date; - -@Singleton -public class Notifier { - - @Inject - private Event<Date> dateEvent; - - @Schedule(second = "*", minute = "*", hour = "*") - public void sendHour() { - dateEvent.fire(new Date()); - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.cdi.events; + +import javax.ejb.Schedule; +import javax.ejb.Singleton; +import javax.enterprise.event.Event; +import javax.inject.Inject; +import java.util.Date; + +@Singleton +public class Notifier { + + @Inject + private Event<Date> dateEvent; + + @Schedule(second = "*", minute = "*", hour = "*") + public void sendHour() { + dateEvent.fire(new Date()); + } +}
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-events/src/test/java/org/superbiz/cdi/events/EventTest.java ---------------------------------------------------------------------- diff --git a/examples/cdi-events/src/test/java/org/superbiz/cdi/events/EventTest.java b/examples/cdi-events/src/test/java/org/superbiz/cdi/events/EventTest.java index ab0701f..1e8fc18 100644 --- a/examples/cdi-events/src/test/java/org/superbiz/cdi/events/EventTest.java +++ b/examples/cdi-events/src/test/java/org/superbiz/cdi/events/EventTest.java @@ -1,73 +1,73 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.cdi.events; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import javax.ejb.embeddable.EJBContainer; -import javax.inject.Inject; -import javax.naming.NamingException; - -import static org.junit.Assert.assertTrue; - -public class EventTest { - - private static EJBContainer container; - private static String initialLogProperty; - - @Inject - private Observer observer; - - @BeforeClass - public static void start() throws NamingException { - initialLogProperty = System.getProperty("openejb.logger.external"); - System.setProperty("openejb.logger.external", "true"); - container = EJBContainer.createEJBContainer(); - } - - @AfterClass - public static void shutdown() { - if (container != null) { - container.close(); - } - if (initialLogProperty != null) { - System.setProperty("openejb.logger.external", initialLogProperty); - } else { - System.getProperties().remove("openejb.logger.external"); - } - } - - @Before - public void inject() throws NamingException { - container.getContext().bind("inject", this); - } - - @After - public void reset() throws NamingException { - container.getContext().unbind("inject"); - } - - @Test - public void observe() throws InterruptedException { - Thread.sleep(4000); - assertTrue(observer.getDates().size() > 3); // in 4s normally at least 3 events were received - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.cdi.events; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.ejb.embeddable.EJBContainer; +import javax.inject.Inject; +import javax.naming.NamingException; + +import static org.junit.Assert.assertTrue; + +public class EventTest { + + private static EJBContainer container; + private static String initialLogProperty; + + @Inject + private Observer observer; + + @BeforeClass + public static void start() throws NamingException { + initialLogProperty = System.getProperty("openejb.logger.external"); + System.setProperty("openejb.logger.external", "true"); + container = EJBContainer.createEJBContainer(); + } + + @AfterClass + public static void shutdown() { + if (container != null) { + container.close(); + } + if (initialLogProperty != null) { + System.setProperty("openejb.logger.external", initialLogProperty); + } else { + System.getProperties().remove("openejb.logger.external"); + } + } + + @Before + public void inject() throws NamingException { + container.getContext().bind("inject", this); + } + + @After + public void reset() throws NamingException { + container.getContext().unbind("inject"); + } + + @Test + public void observe() throws InterruptedException { + Thread.sleep(4000); + assertTrue(observer.getDates().size() > 3); // in 4s normally at least 3 events were received + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-events/src/test/java/org/superbiz/cdi/events/Observer.java ---------------------------------------------------------------------- diff --git a/examples/cdi-events/src/test/java/org/superbiz/cdi/events/Observer.java b/examples/cdi-events/src/test/java/org/superbiz/cdi/events/Observer.java index f08ff55..05697a5 100644 --- a/examples/cdi-events/src/test/java/org/superbiz/cdi/events/Observer.java +++ b/examples/cdi-events/src/test/java/org/superbiz/cdi/events/Observer.java @@ -1,43 +1,43 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.cdi.events; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.enterprise.event.Observes; -import javax.inject.Singleton; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -@Singleton -public class Observer { - - private static final Logger LOGGER = LoggerFactory.getLogger(Observer.class); - - private List<Date> dates = new ArrayList<Date>(); - - public void saveDate(@Observes Date date) { - dates.add(date); - LOGGER.info("received date '{}'", date); - } - - public List<Date> getDates() { - return dates; - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.cdi.events; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.enterprise.event.Observes; +import javax.inject.Singleton; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Singleton +public class Observer { + + private static final Logger LOGGER = LoggerFactory.getLogger(Observer.class); + + private List<Date> dates = new ArrayList<Date>(); + + public void saveDate(@Observes Date date) { + dates.add(date); + LOGGER.info("received date '{}'", date); + } + + public List<Date> getDates() { + return dates; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/AccessDeniedException.java ---------------------------------------------------------------------- diff --git a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/AccessDeniedException.java b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/AccessDeniedException.java index 65ed85c..18dc935 100644 --- a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/AccessDeniedException.java +++ b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/AccessDeniedException.java @@ -1,32 +1,32 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.cdi; - -import javax.ejb.ApplicationException; - -/** - * @version $Revision$ $Date$ - */ -@ApplicationException -public class AccessDeniedException extends RuntimeException { - - private static final long serialVersionUID = 1L; - - public AccessDeniedException(String s) { - super(s); - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.cdi; + +import javax.ejb.ApplicationException; + +/** + * @version $Revision$ $Date$ + */ +@ApplicationException +public class AccessDeniedException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + public AccessDeniedException(String s) { + super(s); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOldStyleInterceptorBinding.java ---------------------------------------------------------------------- diff --git a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOldStyleInterceptorBinding.java b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOldStyleInterceptorBinding.java index f128ed8..b252a9e 100644 --- a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOldStyleInterceptorBinding.java +++ b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOldStyleInterceptorBinding.java @@ -1,53 +1,53 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.cdi.bookshow.beans; - -import org.superbiz.cdi.bookshow.interceptorbinding.Log; -import org.superbiz.cdi.bookshow.interceptors.BookForAShowLoggingInterceptor; - -import javax.ejb.Stateful; -import javax.interceptor.Interceptors; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -/** - * CDI supports binding an interceptor using @Interceptors - * Not recommended though. Has its disadvantages - * Cannot be disabled easily - * Order dependent on how it is listed in class - * Instead, create interceptor bindings using @InterceptorBinding and bind them - * See {@link Log}, {@link BookForAShowOneInterceptorApplied}, {@link BookForAShowLoggingInterceptor} - */ -@Interceptors(BookForAShowLoggingInterceptor.class) -@Stateful -public class BookForAShowOldStyleInterceptorBinding implements Serializable { - - private static final long serialVersionUID = 6350400892234496909L; - - public List<String> getMoviesList() { - List<String> moviesAvailable = new ArrayList<String>(); - moviesAvailable.add("KungFu Panda 2"); - moviesAvailable.add("Kings speech"); - return moviesAvailable; - } - - public Integer getDiscountedPrice(int ticketPrice) { - return ticketPrice - 50; - } - // assume more methods are present -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.cdi.bookshow.beans; + +import org.superbiz.cdi.bookshow.interceptorbinding.Log; +import org.superbiz.cdi.bookshow.interceptors.BookForAShowLoggingInterceptor; + +import javax.ejb.Stateful; +import javax.interceptor.Interceptors; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * CDI supports binding an interceptor using @Interceptors + * Not recommended though. Has its disadvantages + * Cannot be disabled easily + * Order dependent on how it is listed in class + * Instead, create interceptor bindings using @InterceptorBinding and bind them + * See {@link Log}, {@link BookForAShowOneInterceptorApplied}, {@link BookForAShowLoggingInterceptor} + */ +@Interceptors(BookForAShowLoggingInterceptor.class) +@Stateful +public class BookForAShowOldStyleInterceptorBinding implements Serializable { + + private static final long serialVersionUID = 6350400892234496909L; + + public List<String> getMoviesList() { + List<String> moviesAvailable = new ArrayList<String>(); + moviesAvailable.add("KungFu Panda 2"); + moviesAvailable.add("Kings speech"); + return moviesAvailable; + } + + public Integer getDiscountedPrice(int ticketPrice) { + return ticketPrice - 50; + } + // assume more methods are present +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOneInterceptorApplied.java ---------------------------------------------------------------------- diff --git a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOneInterceptorApplied.java b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOneInterceptorApplied.java index 6b94b79..96fec27 100644 --- a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOneInterceptorApplied.java +++ b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOneInterceptorApplied.java @@ -1,43 +1,43 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.cdi.bookshow.beans; - -import org.superbiz.cdi.bookshow.interceptorbinding.Log; - -import javax.ejb.Stateful; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -@Log -@Stateful -public class BookForAShowOneInterceptorApplied implements Serializable { - - private static final long serialVersionUID = 6350400892234496909L; - - public List<String> getMoviesList() { - List<String> moviesAvailable = new ArrayList<String>(); - moviesAvailable.add("12 Angry Men"); - moviesAvailable.add("Kings speech"); - return moviesAvailable; - } - - public Integer getDiscountedPrice(int ticketPrice) { - return ticketPrice - 50; - } - // assume more methods are present -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.cdi.bookshow.beans; + +import org.superbiz.cdi.bookshow.interceptorbinding.Log; + +import javax.ejb.Stateful; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +@Log +@Stateful +public class BookForAShowOneInterceptorApplied implements Serializable { + + private static final long serialVersionUID = 6350400892234496909L; + + public List<String> getMoviesList() { + List<String> moviesAvailable = new ArrayList<String>(); + moviesAvailable.add("12 Angry Men"); + moviesAvailable.add("Kings speech"); + return moviesAvailable; + } + + public Integer getDiscountedPrice(int ticketPrice) { + return ticketPrice - 50; + } + // assume more methods are present +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowTwoInterceptorsApplied.java ---------------------------------------------------------------------- diff --git a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowTwoInterceptorsApplied.java b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowTwoInterceptorsApplied.java index bc088f2..8c639c2 100644 --- a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowTwoInterceptorsApplied.java +++ b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowTwoInterceptorsApplied.java @@ -1,45 +1,45 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.cdi.bookshow.beans; - -import org.superbiz.cdi.bookshow.interceptorbinding.Log; -import org.superbiz.cdi.bookshow.interceptorbinding.TimeRestricted; - -import javax.ejb.Stateful; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -@Log -@Stateful -public class BookForAShowTwoInterceptorsApplied implements Serializable { - - private static final long serialVersionUID = 6350400892234496909L; - - public List<String> getMoviesList() { - List<String> moviesAvailable = new ArrayList<String>(); - moviesAvailable.add("12 Angry Men"); - moviesAvailable.add("Kings speech"); - return moviesAvailable; - } - - @TimeRestricted - public Integer getDiscountedPrice(int ticketPrice) { - return ticketPrice - 50; - } - // assume more methods are present -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.cdi.bookshow.beans; + +import org.superbiz.cdi.bookshow.interceptorbinding.Log; +import org.superbiz.cdi.bookshow.interceptorbinding.TimeRestricted; + +import javax.ejb.Stateful; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +@Log +@Stateful +public class BookForAShowTwoInterceptorsApplied implements Serializable { + + private static final long serialVersionUID = 6350400892234496909L; + + public List<String> getMoviesList() { + List<String> moviesAvailable = new ArrayList<String>(); + moviesAvailable.add("12 Angry Men"); + moviesAvailable.add("Kings speech"); + return moviesAvailable; + } + + @TimeRestricted + public Integer getDiscountedPrice(int ticketPrice) { + return ticketPrice - 50; + } + // assume more methods are present +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookShowInterceptorBindingInheritanceExplored.java ---------------------------------------------------------------------- diff --git a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookShowInterceptorBindingInheritanceExplored.java b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookShowInterceptorBindingInheritanceExplored.java index 323526f..4a4aa96 100644 --- a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookShowInterceptorBindingInheritanceExplored.java +++ b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookShowInterceptorBindingInheritanceExplored.java @@ -1,43 +1,43 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package org.superbiz.cdi.bookshow.beans; - -import org.superbiz.cdi.bookshow.interceptorbinding.TimeRestrictAndLog; - -import javax.ejb.Stateful; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -@Stateful -public class BookShowInterceptorBindingInheritanceExplored implements Serializable { - - private static final long serialVersionUID = 6350400892234496909L; - - public List<String> getMoviesList() { - List<String> moviesAvailable = new ArrayList<String>(); - moviesAvailable.add("12 Angry Men"); - moviesAvailable.add("Kings speech"); - return moviesAvailable; - } - - @TimeRestrictAndLog - public Integer getDiscountedPrice(int ticketPrice) { - return ticketPrice - 50; - } - // assume more methods are present -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.superbiz.cdi.bookshow.beans; + +import org.superbiz.cdi.bookshow.interceptorbinding.TimeRestrictAndLog; + +import javax.ejb.Stateful; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +@Stateful +public class BookShowInterceptorBindingInheritanceExplored implements Serializable { + + private static final long serialVersionUID = 6350400892234496909L; + + public List<String> getMoviesList() { + List<String> moviesAvailable = new ArrayList<String>(); + moviesAvailable.add("12 Angry Men"); + moviesAvailable.add("Kings speech"); + return moviesAvailable; + } + + @TimeRestrictAndLog + public Integer getDiscountedPrice(int ticketPrice) { + return ticketPrice - 50; + } + // assume more methods are present +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/Log.java ---------------------------------------------------------------------- diff --git a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/Log.java b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/Log.java index cdaf8d7..9096511 100644 --- a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/Log.java +++ b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/Log.java @@ -1,32 +1,32 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.cdi.bookshow.interceptorbinding; - -import javax.interceptor.InterceptorBinding; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -@InterceptorBinding -@Target({TYPE, METHOD}) -@Retention(RUNTIME) -public @interface Log { - -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.cdi.bookshow.interceptorbinding; + +import javax.interceptor.InterceptorBinding; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@InterceptorBinding +@Target({TYPE, METHOD}) +@Retention(RUNTIME) +public @interface Log { + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestrictAndLog.java ---------------------------------------------------------------------- diff --git a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestrictAndLog.java b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestrictAndLog.java index f3315da..9aa4a1f 100644 --- a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestrictAndLog.java +++ b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestrictAndLog.java @@ -1,39 +1,39 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.cdi.bookshow.interceptorbinding; - -import javax.interceptor.InterceptorBinding; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * This InterceptorBinding inherits from @Log and @TimeRestricted Interceptor-Bindings. - */ -@Inherited -@InterceptorBinding -@Target({TYPE, METHOD}) -@Retention(RUNTIME) -@Log -@TimeRestricted -public @interface TimeRestrictAndLog { - -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.cdi.bookshow.interceptorbinding; + +import javax.interceptor.InterceptorBinding; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * This InterceptorBinding inherits from @Log and @TimeRestricted Interceptor-Bindings. + */ +@Inherited +@InterceptorBinding +@Target({TYPE, METHOD}) +@Retention(RUNTIME) +@Log +@TimeRestricted +public @interface TimeRestrictAndLog { + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestricted.java ---------------------------------------------------------------------- diff --git a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestricted.java b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestricted.java index d83bb73..db619e9 100644 --- a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestricted.java +++ b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestricted.java @@ -1,32 +1,32 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.cdi.bookshow.interceptorbinding; - -import javax.interceptor.InterceptorBinding; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -@InterceptorBinding -@Target({TYPE, METHOD}) -@Retention(RUNTIME) -public @interface TimeRestricted { - -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.cdi.bookshow.interceptorbinding; + +import javax.interceptor.InterceptorBinding; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@InterceptorBinding +@Target({TYPE, METHOD}) +@Retention(RUNTIME) +public @interface TimeRestricted { + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowLoggingInterceptor.java ---------------------------------------------------------------------- diff --git a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowLoggingInterceptor.java b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowLoggingInterceptor.java index cc2cce3..38d4c35 100644 --- a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowLoggingInterceptor.java +++ b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowLoggingInterceptor.java @@ -1,73 +1,73 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * <p/> - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.cdi.bookshow.interceptors; - -import org.superbiz.cdi.bookshow.interceptorbinding.Log; -import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker; - -import javax.interceptor.AroundInvoke; -import javax.interceptor.Interceptor; -import javax.interceptor.InvocationContext; -import java.io.Serializable; -import java.util.logging.Logger; - -@Interceptor -@Log -public class BookForAShowLoggingInterceptor implements Serializable { - - private static final long serialVersionUID = 8139854519874743530L; - private Logger logger = Logger.getLogger("BookForAShowApplicationLogger"); - - @AroundInvoke - public Object logMethodEntry(InvocationContext ctx) throws Exception { - logger.info("Before entering method:" + ctx.getMethod().getName()); - InterceptionOrderTracker.getMethodsInterceptedList().add(ctx.getMethod().getName()); - InterceptionOrderTracker.getInterceptedByList().add(this.getClass().getSimpleName()); - return ctx.proceed(); - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * <p/> + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.cdi.bookshow.interceptors; + +import org.superbiz.cdi.bookshow.interceptorbinding.Log; +import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker; + +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; +import java.io.Serializable; +import java.util.logging.Logger; + +@Interceptor +@Log +public class BookForAShowLoggingInterceptor implements Serializable { + + private static final long serialVersionUID = 8139854519874743530L; + private Logger logger = Logger.getLogger("BookForAShowApplicationLogger"); + + @AroundInvoke + public Object logMethodEntry(InvocationContext ctx) throws Exception { + logger.info("Before entering method:" + ctx.getMethod().getName()); + InterceptionOrderTracker.getMethodsInterceptedList().add(ctx.getMethod().getName()); + InterceptionOrderTracker.getInterceptedByList().add(this.getClass().getSimpleName()); + return ctx.proceed(); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/TimeBasedRestrictingInterceptor.java ---------------------------------------------------------------------- diff --git a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/TimeBasedRestrictingInterceptor.java b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/TimeBasedRestrictingInterceptor.java index 07695bb..bbc7188 100644 --- a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/TimeBasedRestrictingInterceptor.java +++ b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/TimeBasedRestrictingInterceptor.java @@ -1,51 +1,51 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.cdi.bookshow.interceptors; - -import org.superbiz.cdi.AccessDeniedException; -import org.superbiz.cdi.bookshow.interceptorbinding.TimeRestricted; -import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker; - -import javax.interceptor.AroundInvoke; -import javax.interceptor.Interceptor; -import javax.interceptor.InvocationContext; -import java.io.Serializable; - -@Interceptor -@TimeRestricted -public class TimeBasedRestrictingInterceptor implements Serializable { - - private static final long serialVersionUID = 8139854519874743530L; - - @AroundInvoke - public Object restrictAccessBasedOnTime(InvocationContext ctx) throws Exception { - InterceptionOrderTracker.getMethodsInterceptedList().add(ctx.getMethod().getName()); - InterceptionOrderTracker.getInterceptedByList().add(this.getClass().getSimpleName()); - if (!isWorkingHours()) { - throw new AccessDeniedException("You are not allowed to access the method at this time"); - } - return ctx.proceed(); - } - - private boolean isWorkingHours() { - /* - * int hourOfDay = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); if (hourOfDay >= 9 && hourOfDay <= 21) { - * return true; } else { return false; } - */ - return true; // Let's assume - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.cdi.bookshow.interceptors; + +import org.superbiz.cdi.AccessDeniedException; +import org.superbiz.cdi.bookshow.interceptorbinding.TimeRestricted; +import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker; + +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; +import java.io.Serializable; + +@Interceptor +@TimeRestricted +public class TimeBasedRestrictingInterceptor implements Serializable { + + private static final long serialVersionUID = 8139854519874743530L; + + @AroundInvoke + public Object restrictAccessBasedOnTime(InvocationContext ctx) throws Exception { + InterceptionOrderTracker.getMethodsInterceptedList().add(ctx.getMethod().getName()); + InterceptionOrderTracker.getInterceptedByList().add(this.getClass().getSimpleName()); + if (!isWorkingHours()) { + throw new AccessDeniedException("You are not allowed to access the method at this time"); + } + return ctx.proceed(); + } + + private boolean isWorkingHours() { + /* + * int hourOfDay = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); if (hourOfDay >= 9 && hourOfDay <= 21) { + * return true; } else { return false; } + */ + return true; // Let's assume + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/tracker/InterceptionOrderTracker.java ---------------------------------------------------------------------- diff --git a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/tracker/InterceptionOrderTracker.java b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/tracker/InterceptionOrderTracker.java index 834c215..88ed092 100644 --- a/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/tracker/InterceptionOrderTracker.java +++ b/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/tracker/InterceptionOrderTracker.java @@ -1,49 +1,49 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.cdi.bookshow.tracker; - -import java.util.ArrayList; -import java.util.List; - -/** - * A helper class for the test. - * Keeps track of methods intercepted during one testXXX run - * Keeps track of interceptors applied during one textXXX run - */ -public class InterceptionOrderTracker { - - /* - * Contains method names that were intercepted by the interceptors - */ - private static List<String> methodsInterceptedList = new ArrayList<String>(); - /* - * Contains the name of the interceptor class that intercepted a method - */ - private static List<String> interceptedByList = new ArrayList<String>(); - - public static List<String> getInterceptedByList() { - return interceptedByList; - } - - public static void setInterceptedByList(List<String> interceptedByList) { - InterceptionOrderTracker.interceptedByList = interceptedByList; - } - - public static List<String> getMethodsInterceptedList() { - return methodsInterceptedList; - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.cdi.bookshow.tracker; + +import java.util.ArrayList; +import java.util.List; + +/** + * A helper class for the test. + * Keeps track of methods intercepted during one testXXX run + * Keeps track of interceptors applied during one textXXX run + */ +public class InterceptionOrderTracker { + + /* + * Contains method names that were intercepted by the interceptors + */ + private static List<String> methodsInterceptedList = new ArrayList<String>(); + /* + * Contains the name of the interceptor class that intercepted a method + */ + private static List<String> interceptedByList = new ArrayList<String>(); + + public static List<String> getInterceptedByList() { + return interceptedByList; + } + + public static void setInterceptedByList(List<String> interceptedByList) { + InterceptionOrderTracker.interceptedByList = interceptedByList; + } + + public static List<String> getMethodsInterceptedList() { + return methodsInterceptedList; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOldStyleInterceptorBindingTest.java ---------------------------------------------------------------------- diff --git a/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOldStyleInterceptorBindingTest.java b/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOldStyleInterceptorBindingTest.java index c86fa40..40bb003 100644 --- a/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOldStyleInterceptorBindingTest.java +++ b/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOldStyleInterceptorBindingTest.java @@ -1,58 +1,58 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.cdi.bookshow.interceptors; - -import junit.framework.TestCase; -import org.superbiz.cdi.bookshow.beans.BookForAShowOldStyleInterceptorBinding; -import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker; - -import javax.ejb.EJB; -import javax.ejb.embeddable.EJBContainer; - -public class BookForAShowOldStyleInterceptorBindingTest extends TestCase { - - @EJB - private BookForAShowOldStyleInterceptorBinding bookForAShowBean; - EJBContainer ejbContainer; - - /** - * Bootstrap the Embedded EJB Container - * - * @throws Exception - */ - protected void setUp() throws Exception { - ejbContainer = EJBContainer.createEJBContainer(); - ejbContainer.getContext().bind("inject", this); - } - - /** - * Test basic interception - */ - public void testMethodShouldBeIntercepted() { - // action - bookForAShowBean.getMoviesList(); - // verify - assertTrue(InterceptionOrderTracker.getMethodsInterceptedList().contains("getMoviesList")); - } - - protected void tearDown() { - // clear the lists after each test - InterceptionOrderTracker.getInterceptedByList().clear(); - InterceptionOrderTracker.getMethodsInterceptedList().clear(); - ejbContainer.close(); - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.cdi.bookshow.interceptors; + +import junit.framework.TestCase; +import org.superbiz.cdi.bookshow.beans.BookForAShowOldStyleInterceptorBinding; +import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker; + +import javax.ejb.EJB; +import javax.ejb.embeddable.EJBContainer; + +public class BookForAShowOldStyleInterceptorBindingTest extends TestCase { + + @EJB + private BookForAShowOldStyleInterceptorBinding bookForAShowBean; + EJBContainer ejbContainer; + + /** + * Bootstrap the Embedded EJB Container + * + * @throws Exception + */ + protected void setUp() throws Exception { + ejbContainer = EJBContainer.createEJBContainer(); + ejbContainer.getContext().bind("inject", this); + } + + /** + * Test basic interception + */ + public void testMethodShouldBeIntercepted() { + // action + bookForAShowBean.getMoviesList(); + // verify + assertTrue(InterceptionOrderTracker.getMethodsInterceptedList().contains("getMoviesList")); + } + + protected void tearDown() { + // clear the lists after each test + InterceptionOrderTracker.getInterceptedByList().clear(); + InterceptionOrderTracker.getMethodsInterceptedList().clear(); + ejbContainer.close(); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOneInterceptorAppliedTest.java ---------------------------------------------------------------------- diff --git a/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOneInterceptorAppliedTest.java b/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOneInterceptorAppliedTest.java index db40612..4b1f0f3 100644 --- a/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOneInterceptorAppliedTest.java +++ b/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOneInterceptorAppliedTest.java @@ -1,58 +1,58 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.cdi.bookshow.interceptors; - -import junit.framework.TestCase; -import org.superbiz.cdi.bookshow.beans.BookForAShowOneInterceptorApplied; -import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker; - -import javax.ejb.EJB; -import javax.ejb.embeddable.EJBContainer; - -public class BookForAShowOneInterceptorAppliedTest extends TestCase { - - @EJB - private BookForAShowOneInterceptorApplied bookForAShowBean; - EJBContainer ejbContainer; - - /** - * Bootstrap the Embedded EJB Container - * - * @throws Exception - */ - protected void setUp() throws Exception { - ejbContainer = EJBContainer.createEJBContainer(); - ejbContainer.getContext().bind("inject", this); - } - - /** - * Test basic interception - */ - public void testMethodShouldBeIntercepted() { - // action - bookForAShowBean.getMoviesList(); - // verify - assertTrue(InterceptionOrderTracker.getMethodsInterceptedList().contains("getMoviesList")); - } - - protected void tearDown() { - // clear the list after each test - InterceptionOrderTracker.getInterceptedByList().clear(); - InterceptionOrderTracker.getMethodsInterceptedList().clear(); - ejbContainer.close(); - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.cdi.bookshow.interceptors; + +import junit.framework.TestCase; +import org.superbiz.cdi.bookshow.beans.BookForAShowOneInterceptorApplied; +import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker; + +import javax.ejb.EJB; +import javax.ejb.embeddable.EJBContainer; + +public class BookForAShowOneInterceptorAppliedTest extends TestCase { + + @EJB + private BookForAShowOneInterceptorApplied bookForAShowBean; + EJBContainer ejbContainer; + + /** + * Bootstrap the Embedded EJB Container + * + * @throws Exception + */ + protected void setUp() throws Exception { + ejbContainer = EJBContainer.createEJBContainer(); + ejbContainer.getContext().bind("inject", this); + } + + /** + * Test basic interception + */ + public void testMethodShouldBeIntercepted() { + // action + bookForAShowBean.getMoviesList(); + // verify + assertTrue(InterceptionOrderTracker.getMethodsInterceptedList().contains("getMoviesList")); + } + + protected void tearDown() { + // clear the list after each test + InterceptionOrderTracker.getInterceptedByList().clear(); + InterceptionOrderTracker.getMethodsInterceptedList().clear(); + ejbContainer.close(); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowTwoInterceptorsAppiledTest.java ---------------------------------------------------------------------- diff --git a/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowTwoInterceptorsAppiledTest.java b/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowTwoInterceptorsAppiledTest.java index 0c0093d..2bd0d24 100644 --- a/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowTwoInterceptorsAppiledTest.java +++ b/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowTwoInterceptorsAppiledTest.java @@ -1,70 +1,70 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.cdi.bookshow.interceptors; - -import junit.framework.TestCase; -import org.superbiz.cdi.bookshow.beans.BookForAShowTwoInterceptorsApplied; -import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker; - -import javax.ejb.EJB; -import javax.ejb.embeddable.EJBContainer; -import java.util.List; - -public class BookForAShowTwoInterceptorsAppiledTest extends TestCase { - - @EJB - private BookForAShowTwoInterceptorsApplied bookForAShowBean; - EJBContainer ejbContainer; - - /** - * Bootstrap the Embedded EJB Container - * - * @throws Exception - */ - protected void setUp() throws Exception { - ejbContainer = EJBContainer.createEJBContainer(); - ejbContainer.getContext().bind("inject", this); - } - - /** - * Interceptors should be applied in order as defined in beans.xml - */ - public void testInterceptorsShouldBeAppliedInOrder() { - // action - bookForAShowBean.getDiscountedPrice(100); - // verify - List<String> interceptedByList = InterceptionOrderTracker.getInterceptedByList(); - int indexOfLogger = interceptedByList.indexOf("BookForAShowLoggingInterceptor"); - int indexOfTimeBasedRestrictor = interceptedByList.indexOf("TimeBasedRestrictingInterceptor"); - assertTrue(indexOfLogger < indexOfTimeBasedRestrictor); - } - - public void testTwoInterceptorsWereInvoked() { - // action - bookForAShowBean.getDiscountedPrice(100); - // verify - List<String> interceptedByList = InterceptionOrderTracker.getInterceptedByList(); - assertTrue(interceptedByList.contains("BookForAShowLoggingInterceptor") && interceptedByList.contains("TimeBasedRestrictingInterceptor")); - } - - protected void tearDown() { - // clear the lists after each test - InterceptionOrderTracker.getInterceptedByList().clear(); - InterceptionOrderTracker.getMethodsInterceptedList().clear(); - ejbContainer.close(); - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.cdi.bookshow.interceptors; + +import junit.framework.TestCase; +import org.superbiz.cdi.bookshow.beans.BookForAShowTwoInterceptorsApplied; +import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker; + +import javax.ejb.EJB; +import javax.ejb.embeddable.EJBContainer; +import java.util.List; + +public class BookForAShowTwoInterceptorsAppiledTest extends TestCase { + + @EJB + private BookForAShowTwoInterceptorsApplied bookForAShowBean; + EJBContainer ejbContainer; + + /** + * Bootstrap the Embedded EJB Container + * + * @throws Exception + */ + protected void setUp() throws Exception { + ejbContainer = EJBContainer.createEJBContainer(); + ejbContainer.getContext().bind("inject", this); + } + + /** + * Interceptors should be applied in order as defined in beans.xml + */ + public void testInterceptorsShouldBeAppliedInOrder() { + // action + bookForAShowBean.getDiscountedPrice(100); + // verify + List<String> interceptedByList = InterceptionOrderTracker.getInterceptedByList(); + int indexOfLogger = interceptedByList.indexOf("BookForAShowLoggingInterceptor"); + int indexOfTimeBasedRestrictor = interceptedByList.indexOf("TimeBasedRestrictingInterceptor"); + assertTrue(indexOfLogger < indexOfTimeBasedRestrictor); + } + + public void testTwoInterceptorsWereInvoked() { + // action + bookForAShowBean.getDiscountedPrice(100); + // verify + List<String> interceptedByList = InterceptionOrderTracker.getInterceptedByList(); + assertTrue(interceptedByList.contains("BookForAShowLoggingInterceptor") && interceptedByList.contains("TimeBasedRestrictingInterceptor")); + } + + protected void tearDown() { + // clear the lists after each test + InterceptionOrderTracker.getInterceptedByList().clear(); + InterceptionOrderTracker.getMethodsInterceptedList().clear(); + ejbContainer.close(); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookShowInterceptorBindingInheritanceTest.java ---------------------------------------------------------------------- diff --git a/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookShowInterceptorBindingInheritanceTest.java b/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookShowInterceptorBindingInheritanceTest.java index 95b854a..258e1b5 100644 --- a/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookShowInterceptorBindingInheritanceTest.java +++ b/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookShowInterceptorBindingInheritanceTest.java @@ -1,58 +1,58 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.cdi.bookshow.interceptors; - -import junit.framework.TestCase; -import org.superbiz.cdi.bookshow.beans.BookShowInterceptorBindingInheritanceExplored; -import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker; - -import javax.ejb.EJB; -import javax.ejb.embeddable.EJBContainer; -import java.util.List; - -public class BookShowInterceptorBindingInheritanceTest extends TestCase { - - @EJB - private BookShowInterceptorBindingInheritanceExplored bookForAShowBean; - EJBContainer ejbContainer; - - /** - * Bootstrap the Embedded EJB Container - * - * @throws Exception - */ - protected void setUp() throws Exception { - ejbContainer = EJBContainer.createEJBContainer(); - ejbContainer.getContext().bind("inject", this); - } - - public void testInterceptorBindingCanInheritFromAnotherBinding() { - // action - bookForAShowBean.getDiscountedPrice(100); - // verify both interceptors were invoked - List<String> interceptedByList = InterceptionOrderTracker.getInterceptedByList(); - System.out.println("Intercepted by:" + interceptedByList); - assertTrue(interceptedByList.contains("BookForAShowLoggingInterceptor") && interceptedByList.contains("TimeBasedRestrictingInterceptor")); - } - - protected void tearDown() { - // clear the list after each test - InterceptionOrderTracker.getInterceptedByList().clear(); - InterceptionOrderTracker.getMethodsInterceptedList().clear(); - ejbContainer.close(); - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.cdi.bookshow.interceptors; + +import junit.framework.TestCase; +import org.superbiz.cdi.bookshow.beans.BookShowInterceptorBindingInheritanceExplored; +import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker; + +import javax.ejb.EJB; +import javax.ejb.embeddable.EJBContainer; +import java.util.List; + +public class BookShowInterceptorBindingInheritanceTest extends TestCase { + + @EJB + private BookShowInterceptorBindingInheritanceExplored bookForAShowBean; + EJBContainer ejbContainer; + + /** + * Bootstrap the Embedded EJB Container + * + * @throws Exception + */ + protected void setUp() throws Exception { + ejbContainer = EJBContainer.createEJBContainer(); + ejbContainer.getContext().bind("inject", this); + } + + public void testInterceptorBindingCanInheritFromAnotherBinding() { + // action + bookForAShowBean.getDiscountedPrice(100); + // verify both interceptors were invoked + List<String> interceptedByList = InterceptionOrderTracker.getInterceptedByList(); + System.out.println("Intercepted by:" + interceptedByList); + assertTrue(interceptedByList.contains("BookForAShowLoggingInterceptor") && interceptedByList.contains("TimeBasedRestrictingInterceptor")); + } + + protected void tearDown() { + // clear the list after each test + InterceptionOrderTracker.getInterceptedByList().clear(); + InterceptionOrderTracker.getMethodsInterceptedList().clear(); + ejbContainer.close(); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/ConsoleHandler.java ---------------------------------------------------------------------- diff --git a/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/ConsoleHandler.java b/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/ConsoleHandler.java index d60ffe0..ab5b1ff 100644 --- a/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/ConsoleHandler.java +++ b/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/ConsoleHandler.java @@ -1,37 +1,37 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.cdi.produces.disposes; - -public class ConsoleHandler implements LogHandler { - - private String name; - - public ConsoleHandler(String name) { - this.name = name; - } - - @Override - public String getName() { - return name; - } - - @Override - public void writeLog(String s) { - System.out.printf("##### Handler: %s, Writing to the console!\n", getName()); - } - -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.cdi.produces.disposes; + +public class ConsoleHandler implements LogHandler { + + private String name; + + public ConsoleHandler(String name) { + this.name = name; + } + + @Override + public String getName() { + return name; + } + + @Override + public void writeLog(String s) { + System.out.printf("##### Handler: %s, Writing to the console!\n", getName()); + } + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/DatabaseHandler.java ---------------------------------------------------------------------- diff --git a/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/DatabaseHandler.java b/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/DatabaseHandler.java index 4b3a12c..01e8864 100644 --- a/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/DatabaseHandler.java +++ b/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/DatabaseHandler.java @@ -1,38 +1,38 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.cdi.produces.disposes; - -public class DatabaseHandler implements LogHandler { - - private String name; - - public DatabaseHandler(String name) { - this.name = name; - } - - @Override - public String getName() { - return name; - } - - @Override - public void writeLog(String s) { - System.out.printf("##### Handler: %s, Writing to the database!\n", getName()); - // Use connection to write log to database - } - -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.cdi.produces.disposes; + +public class DatabaseHandler implements LogHandler { + + private String name; + + public DatabaseHandler(String name) { + this.name = name; + } + + @Override + public String getName() { + return name; + } + + @Override + public void writeLog(String s) { + System.out.printf("##### Handler: %s, Writing to the database!\n", getName()); + // Use connection to write log to database + } + +}