http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/ear-testing/business-logic/src/main/java/org/superbiz/logic/MoviesImpl.java ---------------------------------------------------------------------- diff --git a/examples/ear-testing/business-logic/src/main/java/org/superbiz/logic/MoviesImpl.java b/examples/ear-testing/business-logic/src/main/java/org/superbiz/logic/MoviesImpl.java index d13f845..22b32f4 100644 --- a/examples/ear-testing/business-logic/src/main/java/org/superbiz/logic/MoviesImpl.java +++ b/examples/ear-testing/business-logic/src/main/java/org/superbiz/logic/MoviesImpl.java @@ -1,50 +1,50 @@ -/** - * 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.logic; - -//START SNIPPET: code - -import org.superbiz.model.Movie; - -import javax.ejb.Stateful; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.PersistenceContextType; -import javax.persistence.Query; -import java.util.List; - -@Stateful(name = "Movies") -public class MoviesImpl implements Movies { - - @PersistenceContext(unitName = "movie-unit", type = PersistenceContextType.EXTENDED) - private EntityManager entityManager; - - public void addMovie(Movie movie) throws Exception { - entityManager.persist(movie); - } - - public void deleteMovie(Movie movie) throws Exception { - entityManager.remove(movie); - } - - public List<Movie> getMovies() throws Exception { - Query query = entityManager.createQuery("SELECT m from Movie as m"); - return query.getResultList(); - } - -} -//END SNIPPET: code +/** + * 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.logic; + +//START SNIPPET: code + +import org.superbiz.model.Movie; + +import javax.ejb.Stateful; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.PersistenceContextType; +import javax.persistence.Query; +import java.util.List; + +@Stateful(name = "Movies") +public class MoviesImpl implements Movies { + + @PersistenceContext(unitName = "movie-unit", type = PersistenceContextType.EXTENDED) + private EntityManager entityManager; + + public void addMovie(Movie movie) throws Exception { + entityManager.persist(movie); + } + + public void deleteMovie(Movie movie) throws Exception { + entityManager.remove(movie); + } + + public List<Movie> getMovies() throws Exception { + Query query = entityManager.createQuery("SELECT m from Movie as m"); + return query.getResultList(); + } + +} +//END SNIPPET: code
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/ear-testing/business-logic/src/test/java/org/superbiz/logic/MoviesTest.java ---------------------------------------------------------------------- diff --git a/examples/ear-testing/business-logic/src/test/java/org/superbiz/logic/MoviesTest.java b/examples/ear-testing/business-logic/src/test/java/org/superbiz/logic/MoviesTest.java index db6d1b5..3d79988 100644 --- a/examples/ear-testing/business-logic/src/test/java/org/superbiz/logic/MoviesTest.java +++ b/examples/ear-testing/business-logic/src/test/java/org/superbiz/logic/MoviesTest.java @@ -1,64 +1,64 @@ -/** - * 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.logic; - -import junit.framework.TestCase; -import org.superbiz.model.Movie; - -import javax.naming.Context; -import javax.naming.InitialContext; -import java.util.List; -import java.util.Properties; - -//START SNIPPET: code - -public class MoviesTest extends TestCase { - - public void test() throws Exception { - Properties p = new Properties(); - p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory"); - - p.put("openejb.deployments.classpath.ear", "true"); - - p.put("movieDatabase", "new://Resource?type=DataSource"); - p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver"); - p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); - - p.put("movieDatabaseUnmanaged", "new://Resource?type=DataSource"); - p.put("movieDatabaseUnmanaged.JdbcDriver", "org.hsqldb.jdbcDriver"); - p.put("movieDatabaseUnmanaged.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); - p.put("movieDatabaseUnmanaged.JtaManaged", "false"); - - Context context = new InitialContext(p); - - Movies movies = (Movies) context.lookup("MoviesLocal"); - - movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992)); - movies.addMovie(new Movie("Joel Coen", "Fargo", 1996)); - movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998)); - - List<Movie> list = movies.getMovies(); - assertEquals("List.size()", 3, list.size()); - - for (Movie movie : list) { - movies.deleteMovie(movie); - } - - assertEquals("Movies.getMovies()", 0, movies.getMovies().size()); - } -} -//END SNIPPET: code +/** + * 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.logic; + +import junit.framework.TestCase; +import org.superbiz.model.Movie; + +import javax.naming.Context; +import javax.naming.InitialContext; +import java.util.List; +import java.util.Properties; + +//START SNIPPET: code + +public class MoviesTest extends TestCase { + + public void test() throws Exception { + Properties p = new Properties(); + p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory"); + + p.put("openejb.deployments.classpath.ear", "true"); + + p.put("movieDatabase", "new://Resource?type=DataSource"); + p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver"); + p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); + + p.put("movieDatabaseUnmanaged", "new://Resource?type=DataSource"); + p.put("movieDatabaseUnmanaged.JdbcDriver", "org.hsqldb.jdbcDriver"); + p.put("movieDatabaseUnmanaged.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); + p.put("movieDatabaseUnmanaged.JtaManaged", "false"); + + Context context = new InitialContext(p); + + Movies movies = (Movies) context.lookup("MoviesLocal"); + + movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992)); + movies.addMovie(new Movie("Joel Coen", "Fargo", 1996)); + movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998)); + + List<Movie> list = movies.getMovies(); + assertEquals("List.size()", 3, list.size()); + + for (Movie movie : list) { + movies.deleteMovie(movie); + } + + assertEquals("Movies.getMovies()", 0, movies.getMovies().size()); + } +} +//END SNIPPET: code http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/ear-testing/business-model/src/main/java/org/superbiz/model/Movie.java ---------------------------------------------------------------------- diff --git a/examples/ear-testing/business-model/src/main/java/org/superbiz/model/Movie.java b/examples/ear-testing/business-model/src/main/java/org/superbiz/model/Movie.java index 99f397f..02c8126 100644 --- a/examples/ear-testing/business-model/src/main/java/org/superbiz/model/Movie.java +++ b/examples/ear-testing/business-model/src/main/java/org/superbiz/model/Movie.java @@ -1,62 +1,62 @@ -/** - * 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.model; -//START SNIPPET: code - -import javax.persistence.Entity; - -@Entity -public class Movie { - - private String director; - private String title; - private int year; - - public Movie() { - } - - public Movie(String director, String title, int year) { - this.director = director; - this.title = title; - this.year = year; - } - - public String getDirector() { - return director; - } - - public void setDirector(String director) { - this.director = director; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public int getYear() { - return year; - } - - public void setYear(int year) { - this.year = year; - } -} -//END SNIPPET: code +/** + * 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.model; +//START SNIPPET: code + +import javax.persistence.Entity; + +@Entity +public class Movie { + + private String director; + private String title; + private int year; + + public Movie() { + } + + public Movie(String director, String title, int year) { + this.director = director; + this.title = title; + this.year = year; + } + + public String getDirector() { + return director; + } + + public void setDirector(String director) { + this.director = director; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } +} +//END SNIPPET: code http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/ejb-examples/src/main/java/org/superbiz/servlet/AnnotatedEJB.java ---------------------------------------------------------------------- diff --git a/examples/ejb-examples/src/main/java/org/superbiz/servlet/AnnotatedEJB.java b/examples/ejb-examples/src/main/java/org/superbiz/servlet/AnnotatedEJB.java index 811808a..5377c6b 100644 --- a/examples/ejb-examples/src/main/java/org/superbiz/servlet/AnnotatedEJB.java +++ b/examples/ejb-examples/src/main/java/org/superbiz/servlet/AnnotatedEJB.java @@ -1,52 +1,52 @@ -/** - * 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.servlet; - -import javax.annotation.Resource; -import javax.ejb.LocalBean; -import javax.ejb.Stateless; -import javax.sql.DataSource; - -@Stateless -@LocalBean -public class AnnotatedEJB implements AnnotatedEJBLocal, AnnotatedEJBRemote { - - @Resource - private DataSource ds; - - private String name = "foo"; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public DataSource getDs() { - return ds; - } - - public void setDs(DataSource ds) { - this.ds = ds; - } - - public String toString() { - return "AnnotatedEJB[name=" + name + "]"; - } -} +/** + * 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.servlet; + +import javax.annotation.Resource; +import javax.ejb.LocalBean; +import javax.ejb.Stateless; +import javax.sql.DataSource; + +@Stateless +@LocalBean +public class AnnotatedEJB implements AnnotatedEJBLocal, AnnotatedEJBRemote { + + @Resource + private DataSource ds; + + private String name = "foo"; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public DataSource getDs() { + return ds; + } + + public void setDs(DataSource ds) { + this.ds = ds; + } + + public String toString() { + return "AnnotatedEJB[name=" + name + "]"; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/ejb-examples/src/main/java/org/superbiz/servlet/AnnotatedEJBLocal.java ---------------------------------------------------------------------- diff --git a/examples/ejb-examples/src/main/java/org/superbiz/servlet/AnnotatedEJBLocal.java b/examples/ejb-examples/src/main/java/org/superbiz/servlet/AnnotatedEJBLocal.java index 0bf9326..8c0d16b 100644 --- a/examples/ejb-examples/src/main/java/org/superbiz/servlet/AnnotatedEJBLocal.java +++ b/examples/ejb-examples/src/main/java/org/superbiz/servlet/AnnotatedEJBLocal.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.servlet; - -import javax.ejb.Local; -import javax.sql.DataSource; - -@Local -public interface AnnotatedEJBLocal { - - String getName(); - - void setName(String name); - - DataSource getDs(); - - void setDs(DataSource ds); -} +/** + * 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.servlet; + +import javax.ejb.Local; +import javax.sql.DataSource; + +@Local +public interface AnnotatedEJBLocal { + + String getName(); + + void setName(String name); + + DataSource getDs(); + + void setDs(DataSource ds); +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/ejb-examples/src/main/java/org/superbiz/servlet/AnnotatedEJBRemote.java ---------------------------------------------------------------------- diff --git a/examples/ejb-examples/src/main/java/org/superbiz/servlet/AnnotatedEJBRemote.java b/examples/ejb-examples/src/main/java/org/superbiz/servlet/AnnotatedEJBRemote.java index 3b58d9f..2b627a0 100644 --- a/examples/ejb-examples/src/main/java/org/superbiz/servlet/AnnotatedEJBRemote.java +++ b/examples/ejb-examples/src/main/java/org/superbiz/servlet/AnnotatedEJBRemote.java @@ -1,27 +1,27 @@ -/** - * 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.servlet; - -import javax.ejb.Remote; - -@Remote -public interface AnnotatedEJBRemote { - - String getName(); - - void setName(String name); -} +/** + * 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.servlet; + +import javax.ejb.Remote; + +@Remote +public interface AnnotatedEJBRemote { + + String getName(); + + void setName(String name); +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/ejb-examples/src/main/java/org/superbiz/servlet/AnnotatedServlet.java ---------------------------------------------------------------------- diff --git a/examples/ejb-examples/src/main/java/org/superbiz/servlet/AnnotatedServlet.java b/examples/ejb-examples/src/main/java/org/superbiz/servlet/AnnotatedServlet.java index ca8facf..8c42ace 100644 --- a/examples/ejb-examples/src/main/java/org/superbiz/servlet/AnnotatedServlet.java +++ b/examples/ejb-examples/src/main/java/org/superbiz/servlet/AnnotatedServlet.java @@ -1,87 +1,87 @@ -/** - * 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.servlet; - -import javax.annotation.Resource; -import javax.ejb.EJB; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.sql.DataSource; -import java.io.IOException; - -public class AnnotatedServlet extends HttpServlet { - - @EJB - private AnnotatedEJBLocal localEJB; - - @EJB - private AnnotatedEJBRemote remoteEJB; - - @EJB - private AnnotatedEJB localbeanEJB; - - @Resource - private DataSource ds; - - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - response.setContentType("text/plain"); - ServletOutputStream out = response.getOutputStream(); - - out.println("LocalBean EJB"); - out.println("@EJB=" + localbeanEJB); - if (localbeanEJB != null) { - out.println("@EJB.getName()=" + localbeanEJB.getName()); - out.println("@EJB.getDs()=" + localbeanEJB.getDs()); - } - out.println("JNDI=" + lookupField("localbeanEJB")); - out.println(); - - out.println("Local EJB"); - out.println("@EJB=" + localEJB); - if (localEJB != null) { - out.println("@EJB.getName()=" + localEJB.getName()); - out.println("@EJB.getDs()=" + localEJB.getDs()); - } - out.println("JNDI=" + lookupField("localEJB")); - out.println(); - - out.println("Remote EJB"); - out.println("@EJB=" + remoteEJB); - if (localEJB != null) { - out.println("@EJB.getName()=" + remoteEJB.getName()); - } - out.println("JNDI=" + lookupField("remoteEJB")); - out.println(); - - out.println("DataSource"); - out.println("@Resource=" + ds); - out.println("JNDI=" + lookupField("ds")); - } - - private Object lookupField(String name) { - try { - return new InitialContext().lookup("java:comp/env/" + getClass().getName() + "/" + name); - } catch (NamingException e) { - return 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.servlet; + +import javax.annotation.Resource; +import javax.ejb.EJB; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.sql.DataSource; +import java.io.IOException; + +public class AnnotatedServlet extends HttpServlet { + + @EJB + private AnnotatedEJBLocal localEJB; + + @EJB + private AnnotatedEJBRemote remoteEJB; + + @EJB + private AnnotatedEJB localbeanEJB; + + @Resource + private DataSource ds; + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.setContentType("text/plain"); + ServletOutputStream out = response.getOutputStream(); + + out.println("LocalBean EJB"); + out.println("@EJB=" + localbeanEJB); + if (localbeanEJB != null) { + out.println("@EJB.getName()=" + localbeanEJB.getName()); + out.println("@EJB.getDs()=" + localbeanEJB.getDs()); + } + out.println("JNDI=" + lookupField("localbeanEJB")); + out.println(); + + out.println("Local EJB"); + out.println("@EJB=" + localEJB); + if (localEJB != null) { + out.println("@EJB.getName()=" + localEJB.getName()); + out.println("@EJB.getDs()=" + localEJB.getDs()); + } + out.println("JNDI=" + lookupField("localEJB")); + out.println(); + + out.println("Remote EJB"); + out.println("@EJB=" + remoteEJB); + if (localEJB != null) { + out.println("@EJB.getName()=" + remoteEJB.getName()); + } + out.println("JNDI=" + lookupField("remoteEJB")); + out.println(); + + out.println("DataSource"); + out.println("@Resource=" + ds); + out.println("JNDI=" + lookupField("ds")); + } + + private Object lookupField(String name) { + try { + return new InitialContext().lookup("java:comp/env/" + getClass().getName() + "/" + name); + } catch (NamingException e) { + return null; + } + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/ejb-examples/src/main/java/org/superbiz/servlet/ClientHandler.java ---------------------------------------------------------------------- diff --git a/examples/ejb-examples/src/main/java/org/superbiz/servlet/ClientHandler.java b/examples/ejb-examples/src/main/java/org/superbiz/servlet/ClientHandler.java index 040353a..ebad6f5 100644 --- a/examples/ejb-examples/src/main/java/org/superbiz/servlet/ClientHandler.java +++ b/examples/ejb-examples/src/main/java/org/superbiz/servlet/ClientHandler.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.servlet; - -import javax.xml.ws.handler.Handler; -import javax.xml.ws.handler.MessageContext; - -public class ClientHandler implements Handler { - - public boolean handleMessage(MessageContext messageContext) { - WebserviceServlet.write(" ClientHandler handleMessage"); - return true; - } - - public void close(MessageContext messageContext) { - WebserviceServlet.write(" ClientHandler close"); - } - - public boolean handleFault(MessageContext messageContext) { - WebserviceServlet.write(" ClientHandler handleFault"); - return true; - } +/** + * 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.servlet; + +import javax.xml.ws.handler.Handler; +import javax.xml.ws.handler.MessageContext; + +public class ClientHandler implements Handler { + + public boolean handleMessage(MessageContext messageContext) { + WebserviceServlet.write(" ClientHandler handleMessage"); + return true; + } + + public void close(MessageContext messageContext) { + WebserviceServlet.write(" ClientHandler close"); + } + + public boolean handleFault(MessageContext messageContext) { + WebserviceServlet.write(" ClientHandler handleFault"); + return true; + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/ejb-examples/src/main/java/org/superbiz/servlet/HelloEjb.java ---------------------------------------------------------------------- diff --git a/examples/ejb-examples/src/main/java/org/superbiz/servlet/HelloEjb.java b/examples/ejb-examples/src/main/java/org/superbiz/servlet/HelloEjb.java index 6d9545c..a4824e9 100644 --- a/examples/ejb-examples/src/main/java/org/superbiz/servlet/HelloEjb.java +++ b/examples/ejb-examples/src/main/java/org/superbiz/servlet/HelloEjb.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.servlet; - -import javax.jws.WebService; - -@WebService(targetNamespace = "http://examples.org/wsdl") -public interface HelloEjb { - - String hello(String name); -} +/** + * 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.servlet; + +import javax.jws.WebService; + +@WebService(targetNamespace = "http://examples.org/wsdl") +public interface HelloEjb { + + String hello(String name); +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/ejb-examples/src/main/java/org/superbiz/servlet/HelloEjbService.java ---------------------------------------------------------------------- diff --git a/examples/ejb-examples/src/main/java/org/superbiz/servlet/HelloEjbService.java b/examples/ejb-examples/src/main/java/org/superbiz/servlet/HelloEjbService.java index 759d210..3bb1429 100644 --- a/examples/ejb-examples/src/main/java/org/superbiz/servlet/HelloEjbService.java +++ b/examples/ejb-examples/src/main/java/org/superbiz/servlet/HelloEjbService.java @@ -1,40 +1,40 @@ -/** - * 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.servlet; - -import javax.ejb.Stateless; -import javax.jws.HandlerChain; -import javax.jws.WebService; - -@WebService( - portName = "HelloEjbPort", - serviceName = "HelloEjbService", - targetNamespace = "http://examples.org/wsdl", - endpointInterface = "org.superbiz.servlet.HelloEjb" -) -@HandlerChain(file = "server-handlers.xml") -@Stateless -public class HelloEjbService implements HelloEjb { - - public String hello(String name) { - WebserviceServlet.write(" HelloEjbService hello(" + name + ")"); - if (name == null) { - name = "World"; - } - return "Hello " + name + " from EJB Webservice!"; - } -} +/** + * 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.servlet; + +import javax.ejb.Stateless; +import javax.jws.HandlerChain; +import javax.jws.WebService; + +@WebService( + portName = "HelloEjbPort", + serviceName = "HelloEjbService", + targetNamespace = "http://examples.org/wsdl", + endpointInterface = "org.superbiz.servlet.HelloEjb" +) +@HandlerChain(file = "server-handlers.xml") +@Stateless +public class HelloEjbService implements HelloEjb { + + public String hello(String name) { + WebserviceServlet.write(" HelloEjbService hello(" + name + ")"); + if (name == null) { + name = "World"; + } + return "Hello " + name + " from EJB Webservice!"; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/ejb-examples/src/main/java/org/superbiz/servlet/HelloPojo.java ---------------------------------------------------------------------- diff --git a/examples/ejb-examples/src/main/java/org/superbiz/servlet/HelloPojo.java b/examples/ejb-examples/src/main/java/org/superbiz/servlet/HelloPojo.java index 23b48af..e84bc44 100644 --- a/examples/ejb-examples/src/main/java/org/superbiz/servlet/HelloPojo.java +++ b/examples/ejb-examples/src/main/java/org/superbiz/servlet/HelloPojo.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.servlet; - -import javax.jws.WebService; - -@WebService(targetNamespace = "http://examples.org/wsdl") -public interface HelloPojo { - - String hello(String name); -} +/** + * 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.servlet; + +import javax.jws.WebService; + +@WebService(targetNamespace = "http://examples.org/wsdl") +public interface HelloPojo { + + String hello(String name); +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/ejb-examples/src/main/java/org/superbiz/servlet/HelloPojoService.java ---------------------------------------------------------------------- diff --git a/examples/ejb-examples/src/main/java/org/superbiz/servlet/HelloPojoService.java b/examples/ejb-examples/src/main/java/org/superbiz/servlet/HelloPojoService.java index 622f315..97fbb87 100644 --- a/examples/ejb-examples/src/main/java/org/superbiz/servlet/HelloPojoService.java +++ b/examples/ejb-examples/src/main/java/org/superbiz/servlet/HelloPojoService.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.servlet; - -import javax.jws.HandlerChain; -import javax.jws.WebService; - -@WebService( - portName = "HelloPojoPort", - serviceName = "HelloPojoService", - targetNamespace = "http://examples.org/wsdl", - endpointInterface = "org.superbiz.servlet.HelloPojo" -) -@HandlerChain(file = "server-handlers.xml") -public class HelloPojoService implements HelloPojo { - - public String hello(String name) { - WebserviceServlet.write(" HelloPojoService hello(" + name + ")"); - if (name == null) { - name = "World"; - } - return "Hello " + name + " from Pojo Webservice!"; - } -} +/** + * 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.servlet; + +import javax.jws.HandlerChain; +import javax.jws.WebService; + +@WebService( + portName = "HelloPojoPort", + serviceName = "HelloPojoService", + targetNamespace = "http://examples.org/wsdl", + endpointInterface = "org.superbiz.servlet.HelloPojo" +) +@HandlerChain(file = "server-handlers.xml") +public class HelloPojoService implements HelloPojo { + + public String hello(String name) { + WebserviceServlet.write(" HelloPojoService hello(" + name + ")"); + if (name == null) { + name = "World"; + } + return "Hello " + name + " from Pojo Webservice!"; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/ejb-examples/src/main/java/org/superbiz/servlet/JndiServlet.java ---------------------------------------------------------------------- diff --git a/examples/ejb-examples/src/main/java/org/superbiz/servlet/JndiServlet.java b/examples/ejb-examples/src/main/java/org/superbiz/servlet/JndiServlet.java index 7482814..73232b5 100644 --- a/examples/ejb-examples/src/main/java/org/superbiz/servlet/JndiServlet.java +++ b/examples/ejb-examples/src/main/java/org/superbiz/servlet/JndiServlet.java @@ -1,84 +1,84 @@ -/** - * 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.servlet; - -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NameClassPair; -import javax.naming.NamingException; -import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.Collections; -import java.util.Map; -import java.util.TreeMap; - -public class JndiServlet extends HttpServlet { - - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - response.setContentType("text/plain"); - ServletOutputStream out = response.getOutputStream(); - - Map<String, Object> bindings = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER); - try { - Context context = (Context) new InitialContext().lookup("java:comp/"); - addBindings("", bindings, context); - } catch (NamingException e) { - throw new ServletException(e); - } - - out.println("JNDI Context:"); - for (Map.Entry<String, Object> entry : bindings.entrySet()) { - if (entry.getValue() != null) { - out.println(" " + entry.getKey() + "=" + entry.getValue()); - } else { - out.println(" " + entry.getKey()); - } - } - } - - private void addBindings(String path, Map<String, Object> bindings, Context context) { - try { - for (NameClassPair pair : Collections.list(context.list(""))) { - String name = pair.getName(); - String className = pair.getClassName(); - if ("org.apache.naming.resources.FileDirContext$FileResource".equals(className)) { - bindings.put(path + name, "<file>"); - } else { - try { - Object value = context.lookup(name); - if (value instanceof Context) { - Context nextedContext = (Context) value; - bindings.put(path + name, ""); - addBindings(path + name + "/", bindings, nextedContext); - } else { - bindings.put(path + name, value); - } - } catch (NamingException e) { - // lookup failed - bindings.put(path + name, "ERROR: " + e.getMessage()); - } - } - } - } catch (NamingException e) { - bindings.put(path, "ERROR: list bindings threw an exception: " + e.getMessage()); - } - } -} +/** + * 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.servlet; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NameClassPair; +import javax.naming.NamingException; +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.Collections; +import java.util.Map; +import java.util.TreeMap; + +public class JndiServlet extends HttpServlet { + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.setContentType("text/plain"); + ServletOutputStream out = response.getOutputStream(); + + Map<String, Object> bindings = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER); + try { + Context context = (Context) new InitialContext().lookup("java:comp/"); + addBindings("", bindings, context); + } catch (NamingException e) { + throw new ServletException(e); + } + + out.println("JNDI Context:"); + for (Map.Entry<String, Object> entry : bindings.entrySet()) { + if (entry.getValue() != null) { + out.println(" " + entry.getKey() + "=" + entry.getValue()); + } else { + out.println(" " + entry.getKey()); + } + } + } + + private void addBindings(String path, Map<String, Object> bindings, Context context) { + try { + for (NameClassPair pair : Collections.list(context.list(""))) { + String name = pair.getName(); + String className = pair.getClassName(); + if ("org.apache.naming.resources.FileDirContext$FileResource".equals(className)) { + bindings.put(path + name, "<file>"); + } else { + try { + Object value = context.lookup(name); + if (value instanceof Context) { + Context nextedContext = (Context) value; + bindings.put(path + name, ""); + addBindings(path + name + "/", bindings, nextedContext); + } else { + bindings.put(path + name, value); + } + } catch (NamingException e) { + // lookup failed + bindings.put(path + name, "ERROR: " + e.getMessage()); + } + } + } + } catch (NamingException e) { + bindings.put(path, "ERROR: list bindings threw an exception: " + e.getMessage()); + } + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/ejb-examples/src/main/java/org/superbiz/servlet/JpaBean.java ---------------------------------------------------------------------- diff --git a/examples/ejb-examples/src/main/java/org/superbiz/servlet/JpaBean.java b/examples/ejb-examples/src/main/java/org/superbiz/servlet/JpaBean.java index 284efbb..9b08497 100644 --- a/examples/ejb-examples/src/main/java/org/superbiz/servlet/JpaBean.java +++ b/examples/ejb-examples/src/main/java/org/superbiz/servlet/JpaBean.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.servlet; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; - -@Entity -public class JpaBean { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id") - private int id; - - @Column(name = "name") - private String name; - - public int getId() { - return id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String toString() { - return "[JpaBean id=" + id + ", name=" + name + "]"; - } +/** + * 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.servlet; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class JpaBean { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private int id; + + @Column(name = "name") + private String name; + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String toString() { + return "[JpaBean id=" + id + ", name=" + name + "]"; + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/ejb-examples/src/main/java/org/superbiz/servlet/JpaServlet.java ---------------------------------------------------------------------- diff --git a/examples/ejb-examples/src/main/java/org/superbiz/servlet/JpaServlet.java b/examples/ejb-examples/src/main/java/org/superbiz/servlet/JpaServlet.java index 92419ac..0ec6d48 100644 --- a/examples/ejb-examples/src/main/java/org/superbiz/servlet/JpaServlet.java +++ b/examples/ejb-examples/src/main/java/org/superbiz/servlet/JpaServlet.java @@ -1,72 +1,72 @@ -/** - * 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.servlet; - -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.EntityTransaction; -import javax.persistence.PersistenceUnit; -import javax.persistence.Query; -import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -public class JpaServlet extends HttpServlet { - - @PersistenceUnit(name = "jpa-example") - private EntityManagerFactory emf; - - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - response.setContentType("text/plain"); - ServletOutputStream out = response.getOutputStream(); - - out.println("@PersistenceUnit=" + emf); - - EntityManager em = emf.createEntityManager(); - EntityTransaction transaction = em.getTransaction(); - transaction.begin(); - - JpaBean jpaBean = new JpaBean(); - jpaBean.setName("JpaBean"); - em.persist(jpaBean); - - transaction.commit(); - transaction.begin(); - - Query query = em.createQuery("SELECT j FROM JpaBean j WHERE j.name='JpaBean'"); - jpaBean = (JpaBean) query.getSingleResult(); - out.println("Loaded " + jpaBean); - - em.remove(jpaBean); - - transaction.commit(); - transaction.begin(); - - query = em.createQuery("SELECT count(j) FROM JpaBean j WHERE j.name='JpaBean'"); - int count = ((Number) query.getSingleResult()).intValue(); - if (count == 0) { - out.println("Removed " + jpaBean); - } else { - out.println("ERROR: unable to remove" + jpaBean); - } - - transaction.commit(); - } -} +/** + * 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.servlet; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityTransaction; +import javax.persistence.PersistenceUnit; +import javax.persistence.Query; +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class JpaServlet extends HttpServlet { + + @PersistenceUnit(name = "jpa-example") + private EntityManagerFactory emf; + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.setContentType("text/plain"); + ServletOutputStream out = response.getOutputStream(); + + out.println("@PersistenceUnit=" + emf); + + EntityManager em = emf.createEntityManager(); + EntityTransaction transaction = em.getTransaction(); + transaction.begin(); + + JpaBean jpaBean = new JpaBean(); + jpaBean.setName("JpaBean"); + em.persist(jpaBean); + + transaction.commit(); + transaction.begin(); + + Query query = em.createQuery("SELECT j FROM JpaBean j WHERE j.name='JpaBean'"); + jpaBean = (JpaBean) query.getSingleResult(); + out.println("Loaded " + jpaBean); + + em.remove(jpaBean); + + transaction.commit(); + transaction.begin(); + + query = em.createQuery("SELECT count(j) FROM JpaBean j WHERE j.name='JpaBean'"); + int count = ((Number) query.getSingleResult()).intValue(); + if (count == 0) { + out.println("Removed " + jpaBean); + } else { + out.println("ERROR: unable to remove" + jpaBean); + } + + transaction.commit(); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/ejb-examples/src/main/java/org/superbiz/servlet/ResourceBean.java ---------------------------------------------------------------------- diff --git a/examples/ejb-examples/src/main/java/org/superbiz/servlet/ResourceBean.java b/examples/ejb-examples/src/main/java/org/superbiz/servlet/ResourceBean.java index 8a57be2..6fffc4f 100644 --- a/examples/ejb-examples/src/main/java/org/superbiz/servlet/ResourceBean.java +++ b/examples/ejb-examples/src/main/java/org/superbiz/servlet/ResourceBean.java @@ -1,34 +1,34 @@ -/** - * 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.servlet; - -public class ResourceBean { - - private String value; - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - public String toString() { - return "[ResourceBean " + value + "]"; - } -} +/** + * 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.servlet; + +public class ResourceBean { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String toString() { + return "[ResourceBean " + value + "]"; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/ejb-examples/src/main/java/org/superbiz/servlet/RunAsServlet.java ---------------------------------------------------------------------- diff --git a/examples/ejb-examples/src/main/java/org/superbiz/servlet/RunAsServlet.java b/examples/ejb-examples/src/main/java/org/superbiz/servlet/RunAsServlet.java index 6fd3f46..7f1dbfd 100644 --- a/examples/ejb-examples/src/main/java/org/superbiz/servlet/RunAsServlet.java +++ b/examples/ejb-examples/src/main/java/org/superbiz/servlet/RunAsServlet.java @@ -1,92 +1,92 @@ -/** - * 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.servlet; - -import javax.ejb.EJB; -import javax.ejb.EJBAccessException; -import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.security.Principal; - -public class RunAsServlet extends HttpServlet { - - @EJB - private SecureEJBLocal secureEJBLocal; - - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - response.setContentType("text/plain"); - ServletOutputStream out = response.getOutputStream(); - - out.println("Servlet"); - Principal principal = request.getUserPrincipal(); - if (principal != null) { - out.println("Servlet.getUserPrincipal()=" + principal + " [" + principal.getName() + "]"); - } else { - out.println("Servlet.getUserPrincipal()=<null>"); - } - out.println("Servlet.isCallerInRole(\"user\")=" + request.isUserInRole("user")); - out.println("Servlet.isCallerInRole(\"manager\")=" + request.isUserInRole("manager")); - out.println("Servlet.isCallerInRole(\"fake\")=" + request.isUserInRole("fake")); - out.println(); - - out.println("@EJB=" + secureEJBLocal); - if (secureEJBLocal != null) { - principal = secureEJBLocal.getCallerPrincipal(); - if (principal != null) { - out.println("@EJB.getCallerPrincipal()=" + principal + " [" + principal.getName() + "]"); - } else { - out.println("@EJB.getCallerPrincipal()=<null>"); - } - out.println("@EJB.isCallerInRole(\"user\")=" + secureEJBLocal.isCallerInRole("user")); - out.println("@EJB.isCallerInRole(\"manager\")=" + secureEJBLocal.isCallerInRole("manager")); - out.println("@EJB.isCallerInRole(\"fake\")=" + secureEJBLocal.isCallerInRole("fake")); - - try { - secureEJBLocal.allowUserMethod(); - out.println("@EJB.allowUserMethod() ALLOWED"); - } catch (EJBAccessException e) { - out.println("@EJB.allowUserMethod() DENIED"); - } - - try { - secureEJBLocal.allowManagerMethod(); - out.println("@EJB.allowManagerMethod() ALLOWED"); - } catch (EJBAccessException e) { - out.println("@EJB.allowManagerMethod() DENIED"); - } - - try { - secureEJBLocal.allowFakeMethod(); - out.println("@EJB.allowFakeMethod() ALLOWED"); - } catch (EJBAccessException e) { - out.println("@EJB.allowFakeMethod() DENIED"); - } - - try { - secureEJBLocal.denyAllMethod(); - out.println("@EJB.denyAllMethod() ALLOWED"); - } catch (EJBAccessException e) { - out.println("@EJB.denyAllMethod() DENIED"); - } - } - out.println(); - } -} +/** + * 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.servlet; + +import javax.ejb.EJB; +import javax.ejb.EJBAccessException; +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.security.Principal; + +public class RunAsServlet extends HttpServlet { + + @EJB + private SecureEJBLocal secureEJBLocal; + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.setContentType("text/plain"); + ServletOutputStream out = response.getOutputStream(); + + out.println("Servlet"); + Principal principal = request.getUserPrincipal(); + if (principal != null) { + out.println("Servlet.getUserPrincipal()=" + principal + " [" + principal.getName() + "]"); + } else { + out.println("Servlet.getUserPrincipal()=<null>"); + } + out.println("Servlet.isCallerInRole(\"user\")=" + request.isUserInRole("user")); + out.println("Servlet.isCallerInRole(\"manager\")=" + request.isUserInRole("manager")); + out.println("Servlet.isCallerInRole(\"fake\")=" + request.isUserInRole("fake")); + out.println(); + + out.println("@EJB=" + secureEJBLocal); + if (secureEJBLocal != null) { + principal = secureEJBLocal.getCallerPrincipal(); + if (principal != null) { + out.println("@EJB.getCallerPrincipal()=" + principal + " [" + principal.getName() + "]"); + } else { + out.println("@EJB.getCallerPrincipal()=<null>"); + } + out.println("@EJB.isCallerInRole(\"user\")=" + secureEJBLocal.isCallerInRole("user")); + out.println("@EJB.isCallerInRole(\"manager\")=" + secureEJBLocal.isCallerInRole("manager")); + out.println("@EJB.isCallerInRole(\"fake\")=" + secureEJBLocal.isCallerInRole("fake")); + + try { + secureEJBLocal.allowUserMethod(); + out.println("@EJB.allowUserMethod() ALLOWED"); + } catch (EJBAccessException e) { + out.println("@EJB.allowUserMethod() DENIED"); + } + + try { + secureEJBLocal.allowManagerMethod(); + out.println("@EJB.allowManagerMethod() ALLOWED"); + } catch (EJBAccessException e) { + out.println("@EJB.allowManagerMethod() DENIED"); + } + + try { + secureEJBLocal.allowFakeMethod(); + out.println("@EJB.allowFakeMethod() ALLOWED"); + } catch (EJBAccessException e) { + out.println("@EJB.allowFakeMethod() DENIED"); + } + + try { + secureEJBLocal.denyAllMethod(); + out.println("@EJB.denyAllMethod() ALLOWED"); + } catch (EJBAccessException e) { + out.println("@EJB.denyAllMethod() DENIED"); + } + } + out.println(); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/ejb-examples/src/main/java/org/superbiz/servlet/SecureEJB.java ---------------------------------------------------------------------- diff --git a/examples/ejb-examples/src/main/java/org/superbiz/servlet/SecureEJB.java b/examples/ejb-examples/src/main/java/org/superbiz/servlet/SecureEJB.java index 3684dab..f6dd599 100644 --- a/examples/ejb-examples/src/main/java/org/superbiz/servlet/SecureEJB.java +++ b/examples/ejb-examples/src/main/java/org/superbiz/servlet/SecureEJB.java @@ -1,61 +1,61 @@ -/** - * 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.servlet; - -import javax.annotation.Resource; -import javax.annotation.security.DeclareRoles; -import javax.annotation.security.DenyAll; -import javax.annotation.security.RolesAllowed; -import javax.ejb.SessionContext; -import javax.ejb.Stateless; -import java.security.Principal; - -@Stateless -@DeclareRoles({"user", "manager", "fake"}) -public class SecureEJB implements SecureEJBLocal { - - @Resource - private SessionContext context; - - public Principal getCallerPrincipal() { - return context.getCallerPrincipal(); - } - - public boolean isCallerInRole(String role) { - return context.isCallerInRole(role); - } - - @RolesAllowed("user") - public void allowUserMethod() { - } - - @RolesAllowed("manager") - public void allowManagerMethod() { - } - - @RolesAllowed("fake") - public void allowFakeMethod() { - } - - @DenyAll - public void denyAllMethod() { - } - - public String toString() { - return "SecureEJB[userName=" + getCallerPrincipal() + "]"; - } -} +/** + * 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.servlet; + +import javax.annotation.Resource; +import javax.annotation.security.DeclareRoles; +import javax.annotation.security.DenyAll; +import javax.annotation.security.RolesAllowed; +import javax.ejb.SessionContext; +import javax.ejb.Stateless; +import java.security.Principal; + +@Stateless +@DeclareRoles({"user", "manager", "fake"}) +public class SecureEJB implements SecureEJBLocal { + + @Resource + private SessionContext context; + + public Principal getCallerPrincipal() { + return context.getCallerPrincipal(); + } + + public boolean isCallerInRole(String role) { + return context.isCallerInRole(role); + } + + @RolesAllowed("user") + public void allowUserMethod() { + } + + @RolesAllowed("manager") + public void allowManagerMethod() { + } + + @RolesAllowed("fake") + public void allowFakeMethod() { + } + + @DenyAll + public void denyAllMethod() { + } + + public String toString() { + return "SecureEJB[userName=" + getCallerPrincipal() + "]"; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/ejb-examples/src/main/java/org/superbiz/servlet/SecureEJBLocal.java ---------------------------------------------------------------------- diff --git a/examples/ejb-examples/src/main/java/org/superbiz/servlet/SecureEJBLocal.java b/examples/ejb-examples/src/main/java/org/superbiz/servlet/SecureEJBLocal.java index d253617..a2dcad2 100644 --- a/examples/ejb-examples/src/main/java/org/superbiz/servlet/SecureEJBLocal.java +++ b/examples/ejb-examples/src/main/java/org/superbiz/servlet/SecureEJBLocal.java @@ -1,36 +1,36 @@ -/** - * 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.servlet; - -import javax.ejb.Local; -import java.security.Principal; - -@Local -public interface SecureEJBLocal { - - Principal getCallerPrincipal(); - - boolean isCallerInRole(String role); - - void allowUserMethod(); - - void allowManagerMethod(); - - void allowFakeMethod(); - - void denyAllMethod(); -} +/** + * 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.servlet; + +import javax.ejb.Local; +import java.security.Principal; + +@Local +public interface SecureEJBLocal { + + Principal getCallerPrincipal(); + + boolean isCallerInRole(String role); + + void allowUserMethod(); + + void allowManagerMethod(); + + void allowFakeMethod(); + + void denyAllMethod(); +}
