This is an automated email from the ASF dual-hosted git repository. jgallimore pushed a commit to branch tomee-1.7.x in repository https://gitbox.apache.org/repos/asf/tomee.git
commit bfe855e04b33478e0d5d741723da2d0b6104c371 Author: Otavio Santana <[email protected]> AuthorDate: Mon Feb 25 11:53:16 2019 -0300 add ejb-remote-2 --- examples/ejb-remote-call-2/README.adoc | 36 +++++++ examples/ejb-remote-call-2/pom.xml | 108 +++++++++++++++++++++ .../org/superbiz/remote/BusinessException.java | 35 +++++++ .../main/java/org/superbiz/remote/Calculator.java | 27 ++++++ .../org/superbiz/remote/DefaultCalculator.java | 54 +++++++++++ .../src/main/webapp/WEB-INF/web.xml | 27 ++++++ .../src/test/conf/system.properties | 84 ++++++++++++++++ .../src/test/java/org/superbiz/remote/App.java | 53 ++++++++++ 8 files changed, 424 insertions(+) diff --git a/examples/ejb-remote-call-2/README.adoc b/examples/ejb-remote-call-2/README.adoc new file mode 100644 index 0000000..752d7d9 --- /dev/null +++ b/examples/ejb-remote-call-2/README.adoc @@ -0,0 +1,36 @@ +:index-group: Misc +:jbake-type: page +:jbake-status: published +title=EJB Remote Call +~~~~~~ + + +## Calculator + + +@Stateless(name = "Calculator", description = "Calculator", mappedName = "Calculator") +@Remote(Calculator.class) +public class DefaultCalculator implements Calculator { + @Override + public int sum(int add1, int add2) { + return add1 + add2; + } + + @Override + public int multiply(int mul1, int mul2) { + return mul1 * mul2; + } + + +} + +## web.xml + + <web-app 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/web-app_2_5.xsd" + metadata-complete="false" + version="2.5"> + + </web-app> + diff --git a/examples/ejb-remote-call-2/pom.xml b/examples/ejb-remote-call-2/pom.xml new file mode 100644 index 0000000..60af4ba --- /dev/null +++ b/examples/ejb-remote-call-2/pom.xml @@ -0,0 +1,108 @@ +<?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. +--> + +<!-- $Rev: 684173 $ $Date: 2008-08-08 20:13:24 -0700 (Fri, 08 Aug 2008) $ --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.superbiz</groupId> + <artifactId>ejb-remote-call</artifactId> + <packaging>war</packaging> + <version>8.0.0-SNAPSHOT</version> + <name>OpenEJB :: Web Examples :: EJB Remote Call</name> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + <repositories> + <repository> + <id>apache-m2-snapshot</id> + <name>Apache Snapshot Repository</name> + <url>https://repository.apache.org/content/groups/snapshots</url> + </repository> + </repositories> + <build> + <defaultGoal>install</defaultGoal> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.18.1</version> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-war-plugin</artifactId> + <version>3.1.0</version> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.5.1</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.tomee.maven</groupId> + <artifactId>tomee-maven-plugin</artifactId> + <version>8.0.0-SNAPSHOT</version> + <configuration> + <args>-Xmx512m -XX:PermSize=256m</args> + <config>${project.basedir}/src/test/conf</config> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>org.apache.tomee</groupId> + <artifactId>javaee-api</artifactId> + <version>8.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.tomee</groupId> + <artifactId>openejb-client</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>test</scope> + </dependency> + </dependencies> + <!-- + This section allows you to configure where to publish libraries for sharing. + It is not required and may be deleted. For more information see: + http://maven.apache.org/plugins/maven-deploy-plugin/ + --> + <distributionManagement> + <repository> + <id>localhost</id> + <url>file://${basedir}/target/repo/</url> + </repository> + <snapshotRepository> + <id>localhost</id> + <url>file://${basedir}/target/snapshot-repo/</url> + </snapshotRepository> + </distributionManagement> +</project> diff --git a/examples/ejb-remote-call-2/src/main/java/org/superbiz/remote/BusinessException.java b/examples/ejb-remote-call-2/src/main/java/org/superbiz/remote/BusinessException.java new file mode 100644 index 0000000..9257647 --- /dev/null +++ b/examples/ejb-remote-call-2/src/main/java/org/superbiz/remote/BusinessException.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.remote; + +public class BusinessException extends Exception { + + public BusinessException() { + } + + public BusinessException(String message) { + super(message); + } + + public BusinessException(String message, Throwable cause) { + super(message, cause); + } + + public BusinessException(Throwable cause) { + super(cause); + } +} diff --git a/examples/ejb-remote-call-2/src/main/java/org/superbiz/remote/Calculator.java b/examples/ejb-remote-call-2/src/main/java/org/superbiz/remote/Calculator.java new file mode 100644 index 0000000..c238b9b --- /dev/null +++ b/examples/ejb-remote-call-2/src/main/java/org/superbiz/remote/Calculator.java @@ -0,0 +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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.remote; + +public interface Calculator { + + int sum(int add1, int add2); + + int multiply(int mul1, int mul2); + + String echo(String input) throws BusinessException; +} + diff --git a/examples/ejb-remote-call-2/src/main/java/org/superbiz/remote/DefaultCalculator.java b/examples/ejb-remote-call-2/src/main/java/org/superbiz/remote/DefaultCalculator.java new file mode 100644 index 0000000..a030188 --- /dev/null +++ b/examples/ejb-remote-call-2/src/main/java/org/superbiz/remote/DefaultCalculator.java @@ -0,0 +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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.remote; + +import javax.ejb.Remote; +import javax.ejb.Stateless; + +@Stateless(name = "Calculator", description = "Calculator", mappedName = "Calculator") +@Remote(Calculator.class) +public class DefaultCalculator implements Calculator { + @Override + public int sum(int add1, int add2) { + return add1 + add2; + } + + @Override + public int multiply(int mul1, int mul2) { + return mul1 * mul2; + } + + @Override + public String echo(final String input) throws BusinessException { + if ("CHECKED".equals(input)) { + throw new BusinessException("This is a checked exception"); + } + + if ("RUNTIME".equals(input)) { + throw new RuntimeException("This is a runtime exception"); + } + + if (input == null) { + return "Input was null"; + } + + return "Input was: " + input; + } + + + +} diff --git a/examples/ejb-remote-call-2/src/main/webapp/WEB-INF/web.xml b/examples/ejb-remote-call-2/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..addbd2d --- /dev/null +++ b/examples/ejb-remote-call-2/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,27 @@ +<?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. +--> + +<!-- $Rev: 634170 $ $Date: 2008-03-05 21:30:10 -0800 (Wed, 05 Mar 2008) $ --> + +<web-app 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/web-app_2_5.xsd" + metadata-complete="false" + version="2.5"> +</web-app> diff --git a/examples/ejb-remote-call-2/src/test/conf/system.properties b/examples/ejb-remote-call-2/src/test/conf/system.properties new file mode 100644 index 0000000..17df9d4 --- /dev/null +++ b/examples/ejb-remote-call-2/src/test/conf/system.properties @@ -0,0 +1,84 @@ +# all this properties are added at JVM system properties at startup +# here some default Apache TomEE system properties +# for more information please see http://tomee.apache.org/properties-listing.html + +# allowed packages to be deserialized, by security we denied all by default, tune tomee.serialization.class.whitelist packages to change it +tomee.remote.support = true +# tomee.serialization.class.blacklist = * +# tomee.serialization.class.whitelist = my.package +# Johnzon prevents too big string to be unserialized by default +# You can either configure it by Mapper/Parser instance or globally +# With this property: +# org.apache.johnzon.max-string-length = 8192 + +# Should a jar with at least one EJB activate CDI for this module? +# Spec says so but this can imply more (permgen) memory usage +# openejb.cdi.activated-on-ejb = true + +# openejb.check.classloader = false +# openejb.check.classloader.verbose = false + +# Activate EE default resources (ManagedExecutorService, JMSConnectionFactory if JMS is there...)openejb.environment.default = true + +# tomee.jaxws.subcontext = webservices +# tomee.jaxws.oldsubcontext = false + +# if you want to propagate a deployment on a cluster when a tomcat cluster is defined +# tomee.cluster.deployment = false + +# openejb.system.apps = true +# openejb.servicemanager.enabled = true +# openejb.jmx.active = false +# openejb.descriptors.output = false +# openejb.strict.interface.declaration = false +# openejb.conf.file = conf/tomee.xml +# openejb.debuggable-vm-hackery = false +# openejb.validation.skip = false +# openejb.webservices.enabled = true +# openejb.validation.output.level = MEDIUM +# openejb.user.mbeans.list = * +# openejb.deploymentId.format = {appId}/{ejbJarId}/{ejbName} +# openejb.jndiname.format = {deploymentId}{interfaceType.annotationName} +# openejb.deployments.package.include = .* +# openejb.deployments.package.exclude = +# openejb.autocreate.jta-datasource-from-non-jta-one = true +# openejb.altdd.prefix = +# org.apache.openejb.default.system.interceptors = +# openejb.jndiname.failoncollision = true +# openejb.wsAddress.format = /{ejbDeploymentId} +# org.apache.openejb.server.webservices.saaj.provider = +# openejb.nobanner = true +# openejb.offline = false +# openejb.jmx.active = true +# openejb.exclude-include.order = include-exclude +# openejb.additional.exclude = +# openejb.additional.include = +# openejb.crosscontext = false +# openejb.jsessionid-support = +# openejb.myfaces.disable-default-values = true +# openejb.web.xml.major = +# openjpa.Log = +# openejb.jdbc.log = false +# javax.persistence.provider = org.apache.openjpa.persistence.PersistenceProviderImpl +# javax.persistence.transactionType = +# javax.persistence.jtaDataSource = +# javax.persistence.nonJtaDataSource = +# +# Properties for JAS RS +# openejb.jaxrs.application = +# openejb.cxf-rs.wadl-generator.ignoreRequests = false +# openejb.cxf-rs.wadl-generator.ignoreMessageWriters = true +# Replace the Jonhzon JSON Providers with the following classes [comma seperated, no spaces] +# openejb.jaxrs.jsonProviders = +# +# These properties are only for cxf service (SOAP webservices) and TomEE+ +# If you don't use special tricks and sun default implementation, uncommenting these 4 lines forces TomEE to use it without overhead at all = +# javax.xml.soap.MessageFactory = com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl +# javax.xml.soap.SOAPFactory = com.sun.xml.messaging.saaj.soap.ver1_1.SOAPFactory1_1Impl +# javax.xml.soap.SOAPConnectionFactory = com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnectionFactory +# javax.xml.soap.MetaFactory = com.sun.xml.messaging.saaj.soap.SAAJMetaFactoryImpl +# +# Which paths / libraries should be scanned? +openejb.scan.webapp.container = true +openejb.scan.webapp.container.includes = .*(geronimo|mp-jwt|mp-common|failsafe).* +openejb.scan.webapp.container.excludes = diff --git a/examples/ejb-remote-call-2/src/test/java/org/superbiz/remote/App.java b/examples/ejb-remote-call-2/src/test/java/org/superbiz/remote/App.java new file mode 100644 index 0000000..b60ce0f --- /dev/null +++ b/examples/ejb-remote-call-2/src/test/java/org/superbiz/remote/App.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.remote; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import java.util.Properties; + +public class App { + + public static void main(String[] args) throws NamingException, BusinessException { + Properties properties = new Properties(); + properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory"); + properties.put(Context.PROVIDER_URL, "http://localhost:8080/tomee/ejb"); + + Context ctx = new InitialContext(properties); + Object ref = ctx.lookup("global/ejb-remote-call-8.0.0-SNAPSHOT/Calculator!org.superbiz.remote.Calculator"); + + Calculator calculator = Calculator.class.cast(ref); + System.out.println(calculator.sum(1, 2)); + + System.out.println("Expecting Hello world: " + calculator.echo("Hello world")); + try { + System.out.println("Expecting checked exception: "); + System.out.println(calculator.echo("CHECKED")); + } catch (BusinessException e) { + e.printStackTrace(); + } + + try { + System.out.println("Expecting runtime exception: "); + System.out.println(calculator.echo("RUNTIME")); + } catch (RuntimeException e) { + e.printStackTrace(); + } + + } +}
