You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2012/02/18 03:41:47 UTC
svn commit: r1245850 - in
/openejb/trunk/openejb/examples/simple-webservice/src:
main/java/org/superbiz/calculator/ main/java/org/superbiz/calculator/ws/
main/java/org/superbiz/calculator/ws/handler/
main/java/org/superbiz/handler/ main/resources/META-...
Author: dblevins
Date: Sat Feb 18 02:41:46 2012
New Revision: 1245850
URL: http://svn.apache.org/viewvc?rev=1245850&view=rev
Log:
Start of OPENEJB-1779: Split simple-webservice example
Repackage and updated to use EJBContainer API
Added:
openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/
openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorImpl.java
openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorLocal.java
openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorWs.java
openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/handler/
- copied from r1245753, openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/handler/
openejb/trunk/openejb/examples/simple-webservice/src/main/resources/org/superbiz/calculator/ws/
openejb/trunk/openejb/examples/simple-webservice/src/main/resources/org/superbiz/calculator/ws/handler.xml
- copied, changed from r1245753, openejb/trunk/openejb/examples/simple-webservice/src/main/resources/org/superbiz/calculator/handler.xml
openejb/trunk/openejb/examples/simple-webservice/src/test/java/org/superbiz/calculator/ws/
openejb/trunk/openejb/examples/simple-webservice/src/test/java/org/superbiz/calculator/ws/CalculatorTest.java (contents, props changed)
- copied, changed from r1245753, openejb/trunk/openejb/examples/simple-webservice/src/test/java/org/superbiz/calculator/CalculatorTest.java
Removed:
openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/CalculatorImpl.java
openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/CalculatorLocal.java
openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/CalculatorWs.java
openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/handler/
openejb/trunk/openejb/examples/simple-webservice/src/main/resources/META-INF/
openejb/trunk/openejb/examples/simple-webservice/src/main/resources/org/superbiz/calculator/handler.xml
openejb/trunk/openejb/examples/simple-webservice/src/test/java/org/superbiz/calculator/CalculatorTest.java
Modified:
openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/handler/DummyInterceptor.java
Added: openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorImpl.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorImpl.java?rev=1245850&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorImpl.java (added)
+++ openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorImpl.java Sat Feb 18 02:41:46 2012
@@ -0,0 +1,79 @@
+/**
+ * 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.calculator.ws;
+
+import javax.ejb.Stateless;
+import javax.jws.HandlerChain;
+import javax.jws.WebService;
+import javax.xml.ws.Holder;
+import java.util.Date;
+
+/**
+ * This is an EJB 3 style pojo stateless session bean
+ * Every stateless session bean implementation must be annotated
+ * using the annotation @Stateless
+ * This EJB has a 2 interfaces:
+ * <ul>
+ * <li>CalculatorWs a webservice interface</li>
+ * <li>CalculatorLocal a local interface</li>
+ * </ul>
+ */
+//START SNIPPET: code
+@Stateless
+@WebService(
+ portName = "CalculatorPort",
+ serviceName = "CalculatorWsService",
+ targetNamespace = "http://superbiz.org/wsdl",
+ endpointInterface = "org.superbiz.calculator.ws.CalculatorWs")
+@HandlerChain(file = "handler.xml")
+public class CalculatorImpl implements CalculatorWs, CalculatorLocal {
+
+ public int sum(int add1, int add2) {
+ return add1 + add2;
+ }
+
+ public int multiply(int mul1, int mul2) {
+ return mul1 * mul2;
+ }
+
+ public int factorial(
+ int number,
+ Holder<String> userId,
+ Holder<String> returnCode,
+ Holder<Date> datetime) {
+
+ if (number == 0) {
+ returnCode.value = "Can not calculate factorial for zero.";
+ return -1;
+ }
+
+ returnCode.value = userId.value;
+ datetime.value = new Date();
+ return (int) factorial(number);
+ }
+
+ // return n!
+ // precondition: n >= 0 and n <= 20
+
+ private static long factorial(long n) {
+ if (n < 0) throw new RuntimeException("Underflow error in factorial");
+ else if (n > 20) throw new RuntimeException("Overflow error in factorial");
+ else if (n == 0) return 1;
+ else return n * factorial(n - 1);
+ }
+}
+//END SNIPPET: code
Added: openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorLocal.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorLocal.java?rev=1245850&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorLocal.java (added)
+++ openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorLocal.java Sat Feb 18 02:41:46 2012
@@ -0,0 +1,24 @@
+/**
+ * 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.calculator.ws;
+
+import javax.ejb.Local;
+
+@Local
+public interface CalculatorLocal extends CalculatorWs {
+
+}
\ No newline at end of file
Added: openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorWs.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorWs.java?rev=1245850&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorWs.java (added)
+++ openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorWs.java Sat Feb 18 02:41:46 2012
@@ -0,0 +1,55 @@
+/**
+ * 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.calculator.ws;
+
+import javax.jws.WebParam;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+import javax.jws.soap.SOAPBinding.ParameterStyle;
+import javax.jws.soap.SOAPBinding.Style;
+import javax.jws.soap.SOAPBinding.Use;
+import javax.xml.ws.Holder;
+import java.util.Date;
+
+//END SNIPPET: code
+
+/**
+ * This is an EJB 3 webservice interface
+ * A webservice interface must be annotated with the @WebService
+ * annotation.
+ */
+//START SNIPPET: code
+@WebService(
+ name = "CalculatorWs",
+ targetNamespace = "http://superbiz.org/wsdl")
+public interface CalculatorWs {
+
+ public int sum(int add1, int add2);
+
+ public int multiply(int mul1, int mul2);
+
+ // because of CXF bug, BARE must be used instead of default WRAPPED
+
+ @SOAPBinding(use = Use.LITERAL, parameterStyle = ParameterStyle.BARE, style = Style.DOCUMENT)
+ public int factorial(
+ int number,
+ @WebParam(name = "userid", header = true, mode = WebParam.Mode.IN) Holder<String> userId,
+ @WebParam(name = "returncode", header = true, mode = WebParam.Mode.OUT) Holder<String> returnCode,
+ @WebParam(name = "datetime", header = true, mode = WebParam.Mode.INOUT) Holder<Date> datetime);
+
+}
+//END SNIPPET: code
\ No newline at end of file
Modified: openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/handler/DummyInterceptor.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/handler/DummyInterceptor.java?rev=1245850&r1=1245753&r2=1245850&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/handler/DummyInterceptor.java (original)
+++ openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/handler/DummyInterceptor.java Sat Feb 18 02:41:46 2012
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.superbiz.handler;
+package org.superbiz.calculator.ws.handler;
import javax.xml.namespace.QName;
import javax.xml.ws.handler.MessageContext;
Copied: openejb/trunk/openejb/examples/simple-webservice/src/main/resources/org/superbiz/calculator/ws/handler.xml (from r1245753, openejb/trunk/openejb/examples/simple-webservice/src/main/resources/org/superbiz/calculator/handler.xml)
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/simple-webservice/src/main/resources/org/superbiz/calculator/ws/handler.xml?p2=openejb/trunk/openejb/examples/simple-webservice/src/main/resources/org/superbiz/calculator/ws/handler.xml&p1=openejb/trunk/openejb/examples/simple-webservice/src/main/resources/org/superbiz/calculator/handler.xml&r1=1245753&r2=1245850&rev=1245850&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/simple-webservice/src/main/resources/org/superbiz/calculator/handler.xml (original)
+++ openejb/trunk/openejb/examples/simple-webservice/src/main/resources/org/superbiz/calculator/ws/handler.xml Sat Feb 18 02:41:46 2012
@@ -22,8 +22,8 @@
<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
<handler-chain>
<handler>
- <handler-name>org.superbiz.handler.DummyInterceptor</handler-name>
- <handler-class>org.superbiz.handler.DummyInterceptor</handler-class>
+ <handler-name>org.superbiz.calculator.ws.handler.DummyInterceptor</handler-name>
+ <handler-class>org.superbiz.calculator.ws.handler.DummyInterceptor</handler-class>
</handler>
</handler-chain>
</handler-chains>
Copied: openejb/trunk/openejb/examples/simple-webservice/src/test/java/org/superbiz/calculator/ws/CalculatorTest.java (from r1245753, openejb/trunk/openejb/examples/simple-webservice/src/test/java/org/superbiz/calculator/CalculatorTest.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/simple-webservice/src/test/java/org/superbiz/calculator/ws/CalculatorTest.java?p2=openejb/trunk/openejb/examples/simple-webservice/src/test/java/org/superbiz/calculator/ws/CalculatorTest.java&p1=openejb/trunk/openejb/examples/simple-webservice/src/test/java/org/superbiz/calculator/CalculatorTest.java&r1=1245753&r2=1245850&rev=1245850&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/simple-webservice/src/test/java/org/superbiz/calculator/CalculatorTest.java (original)
+++ openejb/trunk/openejb/examples/simple-webservice/src/test/java/org/superbiz/calculator/ws/CalculatorTest.java Sat Feb 18 02:41:46 2012
@@ -14,13 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.superbiz.calculator;
+package org.superbiz.calculator.ws;
import junit.framework.TestCase;
import org.apache.openejb.api.LocalClient;
+import org.superbiz.calculator.ws.CalculatorLocal;
+import org.superbiz.calculator.ws.CalculatorWs;
+import javax.ejb.embeddable.EJBContainer;
import javax.naming.Context;
-import javax.naming.InitialContext;
import javax.xml.namespace.QName;
import javax.xml.ws.Holder;
import javax.xml.ws.Service;
@@ -37,19 +39,18 @@ public class CalculatorTest extends Test
)
private CalculatorWs calculatorWs;
- //START SNIPPET: setup
- private InitialContext initialContext;
-
// date used to invoke a web service with INOUT parameters
private static final Date date = new Date();
+ private Context context;
protected void setUp() throws Exception {
+
Properties properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
properties.setProperty("openejb.embedded.remotable", "true");
- initialContext = new InitialContext(properties);
- initialContext.bind("inject", this);
+ context = EJBContainer.createEJBContainer(properties).getContext();
+ context.bind("inject", this);
}
//END SNIPPET: setup
@@ -91,7 +92,7 @@ public class CalculatorTest extends Test
}
public void testCalculatorViaRemoteInterface() throws Exception {
- CalculatorLocal calc = (CalculatorLocal) initialContext.lookup("CalculatorImplLocal");
+ CalculatorLocal calc = (CalculatorLocal) context.lookup("java:global/simple-webservice/CalculatorImpl");
assertEquals(10, calc.sum(4, 6));
assertEquals(12, calc.multiply(3, 4));
Propchange: openejb/trunk/openejb/examples/simple-webservice/src/test/java/org/superbiz/calculator/ws/CalculatorTest.java
------------------------------------------------------------------------------
svn:keywords = Date Rev Author Id Revision HeadURL