You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by an...@apache.org on 2015/12/01 23:03:25 UTC
[13/77] [abbrv] [partial] tomee git commit: removing ^M (windows eol)
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/FileHandler.java
----------------------------------------------------------------------
diff --git a/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/FileHandler.java b/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/FileHandler.java
index ba319c2..59fd3f2 100644
--- a/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/FileHandler.java
+++ b/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/FileHandler.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 FileHandler implements LogHandler {
-
- private String name;
-
- public FileHandler(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 file!\n", getName());
- // Write to log file
- }
-
-}
+/**
+ * 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 FileHandler implements LogHandler {
+
+ private String name;
+
+ public FileHandler(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 file!\n", getName());
+ // Write to log file
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LogFactory.java
----------------------------------------------------------------------
diff --git a/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LogFactory.java b/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LogFactory.java
index baf798c..fb5b2fc 100644
--- a/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LogFactory.java
+++ b/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LogFactory.java
@@ -1,54 +1,54 @@
-/**
- * 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;
-
-import javax.enterprise.inject.Disposes;
-import javax.enterprise.inject.Produces;
-
-public class LogFactory {
-
- private int type = 2;
-
- @Produces
- public LogHandler getLogHandler() {
- switch (type) {
- case 1:
- return new FileHandler("@Produces created FileHandler!");
- case 2:
- return new DatabaseHandler("@Produces created DatabaseHandler!");
- case 3:
- default:
- return new ConsoleHandler("@Produces created ConsoleHandler!");
- }
-
- }
-
- public void closeLogHandler(@Disposes LogHandler handler) {
- switch (type) {
- case 1:
- System.out.println("Closing File handler!");
- break;
- case 2:
- System.out.println("Closing DB handler!");
- break;
- case 3:
- default:
- System.out.println("Closing Console handler!");
- }
- }
-
-}
+/**
+ * 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;
+
+import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.Produces;
+
+public class LogFactory {
+
+ private int type = 2;
+
+ @Produces
+ public LogHandler getLogHandler() {
+ switch (type) {
+ case 1:
+ return new FileHandler("@Produces created FileHandler!");
+ case 2:
+ return new DatabaseHandler("@Produces created DatabaseHandler!");
+ case 3:
+ default:
+ return new ConsoleHandler("@Produces created ConsoleHandler!");
+ }
+
+ }
+
+ public void closeLogHandler(@Disposes LogHandler handler) {
+ switch (type) {
+ case 1:
+ System.out.println("Closing File handler!");
+ break;
+ case 2:
+ System.out.println("Closing DB handler!");
+ break;
+ case 3:
+ default:
+ System.out.println("Closing Console handler!");
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LogHandler.java
----------------------------------------------------------------------
diff --git a/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LogHandler.java b/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LogHandler.java
index adc22b7..40d3a56 100644
--- a/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LogHandler.java
+++ b/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LogHandler.java
@@ -1,25 +1,25 @@
-/**
- * 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 interface LogHandler {
-
- public String getName();
-
- public void writeLog(String 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.produces.disposes;
+
+public interface LogHandler {
+
+ public String getName();
+
+ public void writeLog(String s);
+
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/Logger.java
----------------------------------------------------------------------
diff --git a/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/Logger.java b/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/Logger.java
index b46975a..4a0cc31 100644
--- a/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/Logger.java
+++ b/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/Logger.java
@@ -1,25 +1,25 @@
-/**
- * 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 interface Logger {
-
- public void log(String s);
-
- public LogHandler getHandler();
-
-}
+/**
+ * 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 interface Logger {
+
+ public void log(String s);
+
+ public LogHandler getHandler();
+
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LoggerImpl.java
----------------------------------------------------------------------
diff --git a/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LoggerImpl.java b/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LoggerImpl.java
index 69cc006..10bc230 100644
--- a/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LoggerImpl.java
+++ b/examples/cdi-produces-disposes/src/main/java/org/superbiz/cdi/produces/disposes/LoggerImpl.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;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-@Named("logger")
-public class LoggerImpl implements Logger {
-
- @Inject
- private LogHandler handler;
-
- @Override
- public void log(String s) {
- getHandler().writeLog(s);
- }
-
- public LogHandler getHandler() {
- return handler;
- }
-
-}
+/**
+ * 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;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+@Named("logger")
+public class LoggerImpl implements Logger {
+
+ @Inject
+ private LogHandler handler;
+
+ @Override
+ public void log(String s) {
+ getHandler().writeLog(s);
+ }
+
+ public LogHandler getHandler() {
+ return handler;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-produces-disposes/src/test/java/org/superbiz/cdi/produces/disposes/LoggerTest.java
----------------------------------------------------------------------
diff --git a/examples/cdi-produces-disposes/src/test/java/org/superbiz/cdi/produces/disposes/LoggerTest.java b/examples/cdi-produces-disposes/src/test/java/org/superbiz/cdi/produces/disposes/LoggerTest.java
index 4fcc086..0c954aa 100644
--- a/examples/cdi-produces-disposes/src/test/java/org/superbiz/cdi/produces/disposes/LoggerTest.java
+++ b/examples/cdi-produces-disposes/src/test/java/org/superbiz/cdi/produces/disposes/LoggerTest.java
@@ -1,67 +1,67 @@
-/**
- * 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;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import javax.ejb.embeddable.EJBContainer;
-import javax.inject.Inject;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-public class LoggerTest {
-
- @Inject
- Logger logger;
-
- private EJBContainer container;
-
- @Before
- public void setUp() {
- try {
- container = EJBContainer.createEJBContainer();
- container.getContext().bind("inject", this);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @After
- public void cleanUp() {
- try {
- container.getContext().unbind("inject");
- container.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Test
- public void testLogHandler() {
- assertNotNull(logger);
- assertFalse("Handler should not be a ConsoleHandler", logger.getHandler() instanceof ConsoleHandler);
- assertFalse("Handler should not be a FileHandler", logger.getHandler() instanceof FileHandler);
- assertTrue("Handler should be a DatabaseHandler", logger.getHandler() instanceof DatabaseHandler);
- logger.log("##### Testing write\n");
- logger = null;
- }
-
-}
+/**
+ * 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;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.ejb.embeddable.EJBContainer;
+import javax.inject.Inject;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class LoggerTest {
+
+ @Inject
+ Logger logger;
+
+ private EJBContainer container;
+
+ @Before
+ public void setUp() {
+ try {
+ container = EJBContainer.createEJBContainer();
+ container.getContext().bind("inject", this);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @After
+ public void cleanUp() {
+ try {
+ container.getContext().unbind("inject");
+ container.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testLogHandler() {
+ assertNotNull(logger);
+ assertFalse("Handler should not be a ConsoleHandler", logger.getHandler() instanceof ConsoleHandler);
+ assertFalse("Handler should not be a FileHandler", logger.getHandler() instanceof FileHandler);
+ assertTrue("Handler should be a DatabaseHandler", logger.getHandler() instanceof DatabaseHandler);
+ logger.log("##### Testing write\n");
+ logger = null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-produces-field/README.md
----------------------------------------------------------------------
diff --git a/examples/cdi-produces-field/README.md b/examples/cdi-produces-field/README.md
index c2f61d9..60f0387 100644
--- a/examples/cdi-produces-field/README.md
+++ b/examples/cdi-produces-field/README.md
@@ -1,270 +1,270 @@
-Title: CDI field producer
-
-This example shows the usage of the @Produces annotation. @Produces is a CDI mechanism which allows defining a source
- for injection. This example shows one of two ways of declaring a producer. Instead of a producer method (see CDI-produces-disposes example)
-a producer field can be used. A producer field can be used instead of a simple getter method. It could be used to
-inject resources, such as persistence contexts. One caveat to using producer fields over producer
- methods is that a @Disposes method cannot be used in conjunction with @Produces field.
-
-## ConsoleHandler
-
- package org.superbiz.cdi.produces.field;
-
- 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());
- }
- }
-
-## DatabaseHandler
-
- package org.superbiz.cdi.produces.field;
-
- 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
- }
- }
-
-## FileHandler
-
- package org.superbiz.cdi.produces.field;
-
- public class FileHandler implements LogHandler {
-
- private String name;
-
- public FileHandler(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 file!\n", getName());
- // Write to log file
- }
- }
-
-## LogFactory
-
- package org.superbiz.cdi.produces.field;
-
- import javax.enterprise.inject.Produces;
-
- public class LogFactory {
-
- private int type = 2;
-
- @Produces
- LogHandler handler;
-
- public LogFactory(){
- handler = getLogHandler();
- }
-
- public LogHandler getLogHandler() {
- switch (type) {
- case 1:
- return new FileHandler("@Produces created FileHandler!");
- case 2:
- return new DatabaseHandler("@Produces created DatabaseHandler!");
- case 3:
- default:
- return new ConsoleHandler("@Produces created ConsoleHandler!");
- }
-
- }
- }
-
-## Logger
-
- package org.superbiz.cdi.produces.field;
-
- public interface Logger {
-
- public void log(String s);
-
- public LogHandler getHandler();
- }
-
-## LoggerImpl
-
- package org.superbiz.cdi.produces.field;
-
- import javax.inject.Inject;
- import javax.inject.Named;
-
- @Named("logger")
- public class LoggerImpl implements Logger {
-
- @Inject
- private LogHandler handler;
-
- @Override
- public void log(String s) {
- getHandler().writeLog(s);
- }
-
- public LogHandler getHandler() {
- return handler;
- }
- }
-
-## LogHandler
-
- package org.superbiz.cdi.produces.field;
-
- public interface LogHandler {
-
- public String getName();
-
- public void writeLog(String s);
- }
-
-## beans.xml
-
- <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
-
- </beans>
-
-## LoggerTest
-
- package org.superbiz.cdi.produces.field;
-
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
-
- import javax.ejb.embeddable.EJBContainer;
- import javax.inject.Inject;
- import javax.naming.Context;
-
- import static junit.framework.Assert.assertNotNull;
- import static org.junit.Assert.assertFalse;
- import static org.junit.Assert.assertTrue;
-
- public class LoggerTest {
-
- @Inject
- Logger logger;
-
- private Context ctxt;
-
- @Before
- public void setUp() {
- try {
- ctxt = EJBContainer.createEJBContainer().getContext();
- ctxt.bind("inject", this);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @After
- public void cleanUp() {
- try {
- ctxt.unbind("inject");
- ctxt.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Test
- public void testLogHandler() {
- assertNotNull(logger);
- assertFalse("Handler should not be a ConsoleHandler", logger.getHandler() instanceof ConsoleHandler);
- assertFalse("Handler should not be a FileHandler", logger.getHandler() instanceof FileHandler);
- assertTrue("Handler should be a DatabaseHandler", logger.getHandler() instanceof DatabaseHandler);
- logger.log("##### Testing write\n");
- logger = null;
- }
-
- }
-
-# Running
-
-
- -------------------------------------------------------
- T E S T S
- -------------------------------------------------------
- Running org.superbiz.cdi.produces.field.LoggerTest
- INFO - ********************************************************************************
- INFO - OpenEJB http://tomee.apache.org/
- INFO - Startup: Thu May 10 01:28:19 CDT 2012
- INFO - Copyright 1999-2012 (C) Apache OpenEJB Project, All Rights Reserved.
- INFO - Version: 7.0.0-SNAPSHOT
- INFO - Build date: 20120510
- INFO - Build time: 04:06
- INFO - ********************************************************************************
- INFO - openejb.home = /home/daniel/projects/openejb/source/openejb/examples/cdi-produces-field
- INFO - openejb.base = /home/daniel/projects/openejb/source/openejb/examples/cdi-produces-field
- INFO - Created new singletonService org.apache.openejb.cdi.ThreadSingletonServiceImpl@a81b1fb
- INFO - succeeded in installing singleton service
- INFO - Using 'javax.ejb.embeddable.EJBContainer=true'
- INFO - Cannot find the configuration file [conf/openejb.xml]. Will attempt to create one for the beans deployed.
- INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
- INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
- INFO - Creating TransactionManager(id=Default Transaction Manager)
- INFO - Creating SecurityService(id=Default Security Service)
- INFO - Inspecting classpath for applications: 26 urls. Consider adjusting your exclude/include. Current settings: openejb.deployments.classpath.exclude='', openejb.deployments.classpath.include='.*'
- INFO - Searched 26 classpath urls in 2015 milliseconds. Average 77 milliseconds per url.
- INFO - Beginning load: /home/daniel/projects/openejb/source/openejb/examples/cdi-produces-field/target/classes
- INFO - Configuring enterprise application: /home/daniel/projects/openejb/source/openejb/examples/cdi-produces-field
- INFO - Auto-deploying ejb cdi-produces-field.Comp: EjbDeployment(deployment-id=cdi-produces-field.Comp)
- INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
- INFO - Auto-creating a container for bean cdi-produces-field.Comp: Container(type=MANAGED, id=Default Managed Container)
- INFO - Creating Container(id=Default Managed Container)
- INFO - Using directory /tmp for stateful session passivation
- INFO - Enterprise application "/home/daniel/projects/openejb/source/openejb/examples/cdi-produces-field" loaded.
- INFO - Assembling app: /home/daniel/projects/openejb/source/openejb/examples/cdi-produces-field
- INFO - ignoreXmlConfiguration == true
- INFO - ignoreXmlConfiguration == true
- INFO - existing thread singleton service in SystemInstance() org.apache.openejb.cdi.ThreadSingletonServiceImpl@a81b1fb
- INFO - OpenWebBeans Container is starting...
- INFO - Adding OpenWebBeansPlugin : [CdiPlugin]
- INFO - All injection points were validated successfully.
- INFO - OpenWebBeans Container has started, it took [69] ms.
- INFO - Deployed Application(path=/home/daniel/projects/openejb/source/openejb/examples/cdi-produces-field)
- ##### Handler: @Produces created DatabaseHandler!, Writing to the database!
- INFO - Undeploying app: /home/daniel/projects/openejb/source/openejb/examples/cdi-produces-field
- Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.79 sec
-
- Results :
-
- Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
-
+Title: CDI field producer
+
+This example shows the usage of the @Produces annotation. @Produces is a CDI mechanism which allows defining a source
+ for injection. This example shows one of two ways of declaring a producer. Instead of a producer method (see CDI-produces-disposes example)
+a producer field can be used. A producer field can be used instead of a simple getter method. It could be used to
+inject resources, such as persistence contexts. One caveat to using producer fields over producer
+ methods is that a @Disposes method cannot be used in conjunction with @Produces field.
+
+## ConsoleHandler
+
+ package org.superbiz.cdi.produces.field;
+
+ 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());
+ }
+ }
+
+## DatabaseHandler
+
+ package org.superbiz.cdi.produces.field;
+
+ 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
+ }
+ }
+
+## FileHandler
+
+ package org.superbiz.cdi.produces.field;
+
+ public class FileHandler implements LogHandler {
+
+ private String name;
+
+ public FileHandler(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 file!\n", getName());
+ // Write to log file
+ }
+ }
+
+## LogFactory
+
+ package org.superbiz.cdi.produces.field;
+
+ import javax.enterprise.inject.Produces;
+
+ public class LogFactory {
+
+ private int type = 2;
+
+ @Produces
+ LogHandler handler;
+
+ public LogFactory(){
+ handler = getLogHandler();
+ }
+
+ public LogHandler getLogHandler() {
+ switch (type) {
+ case 1:
+ return new FileHandler("@Produces created FileHandler!");
+ case 2:
+ return new DatabaseHandler("@Produces created DatabaseHandler!");
+ case 3:
+ default:
+ return new ConsoleHandler("@Produces created ConsoleHandler!");
+ }
+
+ }
+ }
+
+## Logger
+
+ package org.superbiz.cdi.produces.field;
+
+ public interface Logger {
+
+ public void log(String s);
+
+ public LogHandler getHandler();
+ }
+
+## LoggerImpl
+
+ package org.superbiz.cdi.produces.field;
+
+ import javax.inject.Inject;
+ import javax.inject.Named;
+
+ @Named("logger")
+ public class LoggerImpl implements Logger {
+
+ @Inject
+ private LogHandler handler;
+
+ @Override
+ public void log(String s) {
+ getHandler().writeLog(s);
+ }
+
+ public LogHandler getHandler() {
+ return handler;
+ }
+ }
+
+## LogHandler
+
+ package org.superbiz.cdi.produces.field;
+
+ public interface LogHandler {
+
+ public String getName();
+
+ public void writeLog(String s);
+ }
+
+## beans.xml
+
+ <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+ http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+
+ </beans>
+
+## LoggerTest
+
+ package org.superbiz.cdi.produces.field;
+
+ import org.junit.After;
+ import org.junit.Before;
+ import org.junit.Test;
+
+ import javax.ejb.embeddable.EJBContainer;
+ import javax.inject.Inject;
+ import javax.naming.Context;
+
+ import static junit.framework.Assert.assertNotNull;
+ import static org.junit.Assert.assertFalse;
+ import static org.junit.Assert.assertTrue;
+
+ public class LoggerTest {
+
+ @Inject
+ Logger logger;
+
+ private Context ctxt;
+
+ @Before
+ public void setUp() {
+ try {
+ ctxt = EJBContainer.createEJBContainer().getContext();
+ ctxt.bind("inject", this);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @After
+ public void cleanUp() {
+ try {
+ ctxt.unbind("inject");
+ ctxt.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testLogHandler() {
+ assertNotNull(logger);
+ assertFalse("Handler should not be a ConsoleHandler", logger.getHandler() instanceof ConsoleHandler);
+ assertFalse("Handler should not be a FileHandler", logger.getHandler() instanceof FileHandler);
+ assertTrue("Handler should be a DatabaseHandler", logger.getHandler() instanceof DatabaseHandler);
+ logger.log("##### Testing write\n");
+ logger = null;
+ }
+
+ }
+
+# Running
+
+
+ -------------------------------------------------------
+ T E S T S
+ -------------------------------------------------------
+ Running org.superbiz.cdi.produces.field.LoggerTest
+ INFO - ********************************************************************************
+ INFO - OpenEJB http://tomee.apache.org/
+ INFO - Startup: Thu May 10 01:28:19 CDT 2012
+ INFO - Copyright 1999-2012 (C) Apache OpenEJB Project, All Rights Reserved.
+ INFO - Version: 7.0.0-SNAPSHOT
+ INFO - Build date: 20120510
+ INFO - Build time: 04:06
+ INFO - ********************************************************************************
+ INFO - openejb.home = /home/daniel/projects/openejb/source/openejb/examples/cdi-produces-field
+ INFO - openejb.base = /home/daniel/projects/openejb/source/openejb/examples/cdi-produces-field
+ INFO - Created new singletonService org.apache.openejb.cdi.ThreadSingletonServiceImpl@a81b1fb
+ INFO - succeeded in installing singleton service
+ INFO - Using 'javax.ejb.embeddable.EJBContainer=true'
+ INFO - Cannot find the configuration file [conf/openejb.xml]. Will attempt to create one for the beans deployed.
+ INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
+ INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
+ INFO - Creating TransactionManager(id=Default Transaction Manager)
+ INFO - Creating SecurityService(id=Default Security Service)
+ INFO - Inspecting classpath for applications: 26 urls. Consider adjusting your exclude/include. Current settings: openejb.deployments.classpath.exclude='', openejb.deployments.classpath.include='.*'
+ INFO - Searched 26 classpath urls in 2015 milliseconds. Average 77 milliseconds per url.
+ INFO - Beginning load: /home/daniel/projects/openejb/source/openejb/examples/cdi-produces-field/target/classes
+ INFO - Configuring enterprise application: /home/daniel/projects/openejb/source/openejb/examples/cdi-produces-field
+ INFO - Auto-deploying ejb cdi-produces-field.Comp: EjbDeployment(deployment-id=cdi-produces-field.Comp)
+ INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
+ INFO - Auto-creating a container for bean cdi-produces-field.Comp: Container(type=MANAGED, id=Default Managed Container)
+ INFO - Creating Container(id=Default Managed Container)
+ INFO - Using directory /tmp for stateful session passivation
+ INFO - Enterprise application "/home/daniel/projects/openejb/source/openejb/examples/cdi-produces-field" loaded.
+ INFO - Assembling app: /home/daniel/projects/openejb/source/openejb/examples/cdi-produces-field
+ INFO - ignoreXmlConfiguration == true
+ INFO - ignoreXmlConfiguration == true
+ INFO - existing thread singleton service in SystemInstance() org.apache.openejb.cdi.ThreadSingletonServiceImpl@a81b1fb
+ INFO - OpenWebBeans Container is starting...
+ INFO - Adding OpenWebBeansPlugin : [CdiPlugin]
+ INFO - All injection points were validated successfully.
+ INFO - OpenWebBeans Container has started, it took [69] ms.
+ INFO - Deployed Application(path=/home/daniel/projects/openejb/source/openejb/examples/cdi-produces-field)
+ ##### Handler: @Produces created DatabaseHandler!, Writing to the database!
+ INFO - Undeploying app: /home/daniel/projects/openejb/source/openejb/examples/cdi-produces-field
+ Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.79 sec
+
+ Results :
+
+ Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
+
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/ConsoleHandler.java
----------------------------------------------------------------------
diff --git a/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/ConsoleHandler.java b/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/ConsoleHandler.java
index f8852e1..6c6b5cf 100644
--- a/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/ConsoleHandler.java
+++ b/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/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.field;
-
-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.field;
+
+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-field/src/main/java/org/superbiz/cdi/produces/field/DatabaseHandler.java
----------------------------------------------------------------------
diff --git a/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/DatabaseHandler.java b/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/DatabaseHandler.java
index ef9a658..3dbab3e 100644
--- a/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/DatabaseHandler.java
+++ b/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/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.field;
-
-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.field;
+
+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
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/FileHandler.java
----------------------------------------------------------------------
diff --git a/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/FileHandler.java b/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/FileHandler.java
index 3681058..35556b4 100644
--- a/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/FileHandler.java
+++ b/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/FileHandler.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.field;
-
-public class FileHandler implements LogHandler {
-
- private String name;
-
- public FileHandler(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 file!\n", getName());
- // Write to log file
- }
-
-}
+/**
+ * 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.field;
+
+public class FileHandler implements LogHandler {
+
+ private String name;
+
+ public FileHandler(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 file!\n", getName());
+ // Write to log file
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/LogFactory.java
----------------------------------------------------------------------
diff --git a/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/LogFactory.java b/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/LogFactory.java
index 87e9410..c135b20 100644
--- a/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/LogFactory.java
+++ b/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/LogFactory.java
@@ -1,44 +1,44 @@
-/**
- * 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.field;
-
-import javax.enterprise.inject.Produces;
-
-public class LogFactory {
-
- private int type = 2;
-
- @Produces
- LogHandler handler;
-
- public LogFactory() {
- handler = getLogHandler();
- }
-
- public LogHandler getLogHandler() {
- switch (type) {
- case 1:
- return new FileHandler("@Produces created FileHandler!");
- case 2:
- return new DatabaseHandler("@Produces created DatabaseHandler!");
- case 3:
- default:
- return new ConsoleHandler("@Produces created ConsoleHandler!");
- }
-
- }
-}
+/**
+ * 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.field;
+
+import javax.enterprise.inject.Produces;
+
+public class LogFactory {
+
+ private int type = 2;
+
+ @Produces
+ LogHandler handler;
+
+ public LogFactory() {
+ handler = getLogHandler();
+ }
+
+ public LogHandler getLogHandler() {
+ switch (type) {
+ case 1:
+ return new FileHandler("@Produces created FileHandler!");
+ case 2:
+ return new DatabaseHandler("@Produces created DatabaseHandler!");
+ case 3:
+ default:
+ return new ConsoleHandler("@Produces created ConsoleHandler!");
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/LogHandler.java
----------------------------------------------------------------------
diff --git a/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/LogHandler.java b/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/LogHandler.java
index b0c892a..981db18 100644
--- a/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/LogHandler.java
+++ b/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/LogHandler.java
@@ -1,25 +1,25 @@
-/**
- * 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.field;
-
-public interface LogHandler {
-
- public String getName();
-
- public void writeLog(String 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.produces.field;
+
+public interface LogHandler {
+
+ public String getName();
+
+ public void writeLog(String s);
+
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/Logger.java
----------------------------------------------------------------------
diff --git a/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/Logger.java b/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/Logger.java
index 8dd628e..541ba5f 100644
--- a/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/Logger.java
+++ b/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/Logger.java
@@ -1,25 +1,25 @@
-/**
- * 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.field;
-
-public interface Logger {
-
- public void log(String s);
-
- public LogHandler getHandler();
-
-}
+/**
+ * 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.field;
+
+public interface Logger {
+
+ public void log(String s);
+
+ public LogHandler getHandler();
+
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/LoggerImpl.java
----------------------------------------------------------------------
diff --git a/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/LoggerImpl.java b/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/LoggerImpl.java
index ca039fe..2750e6d 100644
--- a/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/LoggerImpl.java
+++ b/examples/cdi-produces-field/src/main/java/org/superbiz/cdi/produces/field/LoggerImpl.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.field;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-@Named("logger")
-public class LoggerImpl implements Logger {
-
- @Inject
- private LogHandler handler;
-
- @Override
- public void log(String s) {
- getHandler().writeLog(s);
- }
-
- public LogHandler getHandler() {
- return handler;
- }
-
-}
+/**
+ * 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.field;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+@Named("logger")
+public class LoggerImpl implements Logger {
+
+ @Inject
+ private LogHandler handler;
+
+ @Override
+ public void log(String s) {
+ getHandler().writeLog(s);
+ }
+
+ public LogHandler getHandler() {
+ return handler;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-produces-field/src/main/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/examples/cdi-produces-field/src/main/resources/META-INF/beans.xml b/examples/cdi-produces-field/src/main/resources/META-INF/beans.xml
index 04392fd..c33918a 100644
--- a/examples/cdi-produces-field/src/main/resources/META-INF/beans.xml
+++ b/examples/cdi-produces-field/src/main/resources/META-INF/beans.xml
@@ -1,24 +1,24 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
-
-</beans>
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+ http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+
+</beans>
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-produces-field/src/test/java/org/superbiz/cdi/produces/field/LoggerTest.java
----------------------------------------------------------------------
diff --git a/examples/cdi-produces-field/src/test/java/org/superbiz/cdi/produces/field/LoggerTest.java b/examples/cdi-produces-field/src/test/java/org/superbiz/cdi/produces/field/LoggerTest.java
index 6a7b434..873f8fe 100644
--- a/examples/cdi-produces-field/src/test/java/org/superbiz/cdi/produces/field/LoggerTest.java
+++ b/examples/cdi-produces-field/src/test/java/org/superbiz/cdi/produces/field/LoggerTest.java
@@ -1,67 +1,67 @@
-/**
- * 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.field;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import javax.ejb.embeddable.EJBContainer;
-import javax.inject.Inject;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-public class LoggerTest {
-
- @Inject
- Logger logger;
-
- private EJBContainer container;
-
- @Before
- public void setUp() {
- try {
- container = EJBContainer.createEJBContainer();
- container.getContext().bind("inject", this);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @After
- public void cleanUp() {
- try {
- container.getContext().unbind("inject");
- container.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Test
- public void testLogHandler() {
- assertNotNull(logger);
- assertFalse("Handler should not be a ConsoleHandler", logger.getHandler() instanceof ConsoleHandler);
- assertFalse("Handler should not be a FileHandler", logger.getHandler() instanceof FileHandler);
- assertTrue("Handler should be a DatabaseHandler", logger.getHandler() instanceof DatabaseHandler);
- logger.log("##### Testing write\n");
- logger = null;
- }
-
-}
+/**
+ * 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.field;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.ejb.embeddable.EJBContainer;
+import javax.inject.Inject;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class LoggerTest {
+
+ @Inject
+ Logger logger;
+
+ private EJBContainer container;
+
+ @Before
+ public void setUp() {
+ try {
+ container = EJBContainer.createEJBContainer();
+ container.getContext().bind("inject", this);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @After
+ public void cleanUp() {
+ try {
+ container.getContext().unbind("inject");
+ container.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testLogHandler() {
+ assertNotNull(logger);
+ assertFalse("Handler should not be a ConsoleHandler", logger.getHandler() instanceof ConsoleHandler);
+ assertFalse("Handler should not be a FileHandler", logger.getHandler() instanceof FileHandler);
+ assertTrue("Handler should be a DatabaseHandler", logger.getHandler() instanceof DatabaseHandler);
+ logger.log("##### Testing write\n");
+ logger = null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-realm/src/main/java/org/superbiz/AuthBean.java
----------------------------------------------------------------------
diff --git a/examples/cdi-realm/src/main/java/org/superbiz/AuthBean.java b/examples/cdi-realm/src/main/java/org/superbiz/AuthBean.java
index d74f34d..778c67d 100644
--- a/examples/cdi-realm/src/main/java/org/superbiz/AuthBean.java
+++ b/examples/cdi-realm/src/main/java/org/superbiz/AuthBean.java
@@ -1,48 +1,48 @@
-/**
- * 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;
-
-import javax.enterprise.context.RequestScoped;
-import java.security.Principal;
-
-@RequestScoped // just to show we can be bound to the request but @ApplicationScoped is what makes sense
-public class AuthBean {
- public Principal authenticate(final String username, String password) {
- if (("userA".equals(username) || "userB".equals(username)) && "test".equals(password)) {
- return new Principal() {
- @Override
- public String getName() {
- return username;
- }
-
- @Override
- public String toString() {
- return username;
- }
- };
- }
- return null;
- }
-
- public boolean hasRole(final Principal principal, final String role) {
- return principal != null && (
- principal.getName().equals("userA") && (role.equals("admin")
- || role.equals("user"))
- || principal.getName().equals("userB") && (role.equals("user"))
- );
- }
-}
+/**
+ * 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;
+
+import javax.enterprise.context.RequestScoped;
+import java.security.Principal;
+
+@RequestScoped // just to show we can be bound to the request but @ApplicationScoped is what makes sense
+public class AuthBean {
+ public Principal authenticate(final String username, String password) {
+ if (("userA".equals(username) || "userB".equals(username)) && "test".equals(password)) {
+ return new Principal() {
+ @Override
+ public String getName() {
+ return username;
+ }
+
+ @Override
+ public String toString() {
+ return username;
+ }
+ };
+ }
+ return null;
+ }
+
+ public boolean hasRole(final Principal principal, final String role) {
+ return principal != null && (
+ principal.getName().equals("userA") && (role.equals("admin")
+ || role.equals("user"))
+ || principal.getName().equals("userB") && (role.equals("user"))
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-realm/src/main/java/org/superbiz/SecuredServlet.java
----------------------------------------------------------------------
diff --git a/examples/cdi-realm/src/main/java/org/superbiz/SecuredServlet.java b/examples/cdi-realm/src/main/java/org/superbiz/SecuredServlet.java
index ec1a18f..63aa90b 100644
--- a/examples/cdi-realm/src/main/java/org/superbiz/SecuredServlet.java
+++ b/examples/cdi-realm/src/main/java/org/superbiz/SecuredServlet.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;
-
-import javax.servlet.ServletException;
-import javax.servlet.annotation.WebServlet;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-@WebServlet("/servlet")
-public class SecuredServlet extends HttpServlet {
- @Override
- protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
- resp.getWriter().write("Servlet!");
- }
-}
+/**
+ * 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;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+@WebServlet("/servlet")
+public class SecuredServlet extends HttpServlet {
+ @Override
+ protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
+ resp.getWriter().write("Servlet!");
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/cdi-realm/src/test/java/org/superbiz/AuthBeanTest.java
----------------------------------------------------------------------
diff --git a/examples/cdi-realm/src/test/java/org/superbiz/AuthBeanTest.java b/examples/cdi-realm/src/test/java/org/superbiz/AuthBeanTest.java
index 9f22037..ed27f94 100644
--- a/examples/cdi-realm/src/test/java/org/superbiz/AuthBeanTest.java
+++ b/examples/cdi-realm/src/test/java/org/superbiz/AuthBeanTest.java
@@ -1,102 +1,102 @@
-/**
- * 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;
-
-import org.apache.http.HttpHost;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.client.AuthCache;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.protocol.HttpClientContext;
-import org.apache.http.impl.auth.BasicScheme;
-import org.apache.http.impl.client.BasicAuthCache;
-import org.apache.http.impl.client.BasicCredentialsProvider;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.util.EntityUtils;
-import org.apache.openejb.arquillian.common.IO;
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.arquillian.test.api.ArquillianResource;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.EmptyAsset;
-import org.jboss.shrinkwrap.api.asset.FileAsset;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-
-import static org.hamcrest.CoreMatchers.startsWith;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-
-@RunWith(Arquillian.class)
-public class AuthBeanTest {
- @Deployment(testable = false)
- public static WebArchive createDeployment() {
- return ShrinkWrap.create(WebArchive.class, "low-typed-realm.war")
- .addClasses(SecuredServlet.class, AuthBean.class)
- .addAsManifestResource(new FileAsset(new File("src/main/webapp/META-INF/context.xml")), "context.xml")
- .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
- }
-
- @ArquillianResource
- private URL webapp;
-
- @Test
- public void success() throws IOException {
- assertEquals("200 Servlet!", get("userA", "test"));
- }
-
- @Test
- public void failure() throws IOException {
- assertThat(get("userA", "oops, wrong password"), startsWith("401"));
- }
-
- private String get(final String user, final String password) {
- final BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider();
- basicCredentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password));
- final CloseableHttpClient client = HttpClients.custom()
- .setDefaultCredentialsProvider(basicCredentialsProvider).build();
-
- final HttpHost httpHost = new HttpHost(webapp.getHost(), webapp.getPort(), webapp.getProtocol());
- final AuthCache authCache = new BasicAuthCache();
- final BasicScheme basicAuth = new BasicScheme();
- authCache.put(httpHost, basicAuth);
- final HttpClientContext context = HttpClientContext.create();
- context.setAuthCache(authCache);
-
- final HttpGet get = new HttpGet(webapp.toExternalForm() + "servlet");
- CloseableHttpResponse response = null;
- try {
- response = client.execute(httpHost, get, context);
- return response.getStatusLine().getStatusCode() + " " + EntityUtils.toString(response.getEntity());
- } catch (final IOException e) {
- throw new IllegalStateException(e);
- } finally {
- try {
- IO.close(response);
- } catch (final IOException e) {
- // no-op
- }
- }
- }
-}
+/**
+ * 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;
+
+import org.apache.http.HttpHost;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.AuthCache;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.impl.auth.BasicScheme;
+import org.apache.http.impl.client.BasicAuthCache;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import org.apache.openejb.arquillian.common.IO;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.asset.FileAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+@RunWith(Arquillian.class)
+public class AuthBeanTest {
+ @Deployment(testable = false)
+ public static WebArchive createDeployment() {
+ return ShrinkWrap.create(WebArchive.class, "low-typed-realm.war")
+ .addClasses(SecuredServlet.class, AuthBean.class)
+ .addAsManifestResource(new FileAsset(new File("src/main/webapp/META-INF/context.xml")), "context.xml")
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
+ }
+
+ @ArquillianResource
+ private URL webapp;
+
+ @Test
+ public void success() throws IOException {
+ assertEquals("200 Servlet!", get("userA", "test"));
+ }
+
+ @Test
+ public void failure() throws IOException {
+ assertThat(get("userA", "oops, wrong password"), startsWith("401"));
+ }
+
+ private String get(final String user, final String password) {
+ final BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider();
+ basicCredentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password));
+ final CloseableHttpClient client = HttpClients.custom()
+ .setDefaultCredentialsProvider(basicCredentialsProvider).build();
+
+ final HttpHost httpHost = new HttpHost(webapp.getHost(), webapp.getPort(), webapp.getProtocol());
+ final AuthCache authCache = new BasicAuthCache();
+ final BasicScheme basicAuth = new BasicScheme();
+ authCache.put(httpHost, basicAuth);
+ final HttpClientContext context = HttpClientContext.create();
+ context.setAuthCache(authCache);
+
+ final HttpGet get = new HttpGet(webapp.toExternalForm() + "servlet");
+ CloseableHttpResponse response = null;
+ try {
+ response = client.execute(httpHost, get, context);
+ return response.getStatusLine().getStatusCode() + " " + EntityUtils.toString(response.getEntity());
+ } catch (final IOException e) {
+ throw new IllegalStateException(e);
+ } finally {
+ try {
+ IO.close(response);
+ } catch (final IOException e) {
+ // no-op
+ }
+ }
+ }
+}