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/19 04:19:28 UTC

svn commit: r1290928 - in /openejb/trunk/openejb/examples/simple-webservice: ./ src/main/java/org/superbiz/calculator/ws/ src/main/java/org/superbiz/calculator/ws/handler/ src/main/resources/org/ src/test/java/org/superbiz/calculator/ws/ src/test/resou...

Author: dblevins
Date: Sun Feb 19 03:19:28 2012
New Revision: 1290928

URL: http://svn.apache.org/viewvc?rev=1290928&view=rev
Log:
Trimmed the example down now that it has been split up into three separate examples
OPENEJB-1779

Added:
    openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/Calculator.java
      - copied, changed from r1245850, openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorImpl.java
Removed:
    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/handler/
    openejb/trunk/openejb/examples/simple-webservice/src/main/resources/org/
    openejb/trunk/openejb/examples/simple-webservice/src/test/resources/META-INF/ejb-jar.xml
Modified:
    openejb/trunk/openejb/examples/simple-webservice/README.md
    openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorWs.java
    openejb/trunk/openejb/examples/simple-webservice/src/test/java/org/superbiz/calculator/ws/CalculatorTest.java

Modified: openejb/trunk/openejb/examples/simple-webservice/README.md
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/simple-webservice/README.md?rev=1290928&r1=1290927&r2=1290928&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/simple-webservice/README.md (original)
+++ openejb/trunk/openejb/examples/simple-webservice/README.md Sun Feb 19 03:19:28 2012
@@ -1,301 +1,226 @@
-Title: Simple Webservice
+Title: JAX-WS @WebService example
 
-*Help us document this example! Source available in [svn](http://svn.apache.org/repos/asf/openejb/trunk/openejb/examples/simple-webservice) or [git](https://github.com/apache/openejb/tree/trunk/openejb/examples/simple-webservice). Open a [JIRA](https://issues.apache.org/jira/browse/TOMEE) with patch or pull request*
+Creating Web Services with JAX-WS is quite easy.  Little has to be done aside from annotating a class with `@WebService`.  For
+the purposes of this example we will also annotate our component with `@Stateless` which takes some of the configuration out of
+the process and gives us some nice options such as transactions and security.
 
-## CalculatorImpl
+## @WebService
+
+The following is all that is required.  No external xml files are needed.  This class placed in a jar or war and deployed into a compliant Java EE server like TomEE is enough to have the Calculator class discovered and deployed and the webservice online.
 
-    package org.superbiz.calculator;
-    
     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>
-     */
+
     @Stateless
     @WebService(
             portName = "CalculatorPort",
-            serviceName = "CalculatorWsService",
+            serviceName = "CalculatorService",
             targetNamespace = "http://superbiz.org/wsdl",
-            endpointInterface = "org.superbiz.calculator.CalculatorWs")
-    @HandlerChain(file = "handler.xml")
-    public class CalculatorImpl implements CalculatorWs, CalculatorLocal {
-    
+            endpointInterface = "org.superbiz.calculator.ws.CalculatorWs")
+    public class Calculator implements CalculatorWs {
+
         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);
-        }
     }
 
-## CalculatorLocal
-
-    package org.superbiz.calculator;
-    
-    import javax.ejb.Local;
-    
-    @Local
-    public interface CalculatorLocal extends CalculatorWs {
-    }
+## @WebService Endpoint Interface
 
-## CalculatorWs
+Having an endpoint interface is not required, but it can make testing and using the web service from other Java clients far easier.
 
-    package org.superbiz.calculator;
-    
-    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;
     
-    /**
-     * This is an EJB 3 webservice interface
-     * A webservice interface must be annotated with the @WebService
-     * annotation.
-     */
-    @WebService(
-            name = "CalculatorWs",
-            targetNamespace = "http://superbiz.org/wsdl")
+    @WebService(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);
     }
 
-## DummyInterceptor
+## Calculator WSDL
 
-    package org.superbiz.handler;
-    
-    import javax.xml.namespace.QName;
-    import javax.xml.ws.handler.MessageContext;
-    import javax.xml.ws.handler.soap.SOAPHandler;
-    import javax.xml.ws.handler.soap.SOAPMessageContext;
-    import java.util.Collections;
-    import java.util.Set;
-    
-    public class DummyInterceptor implements SOAPHandler<SOAPMessageContext> {
-        public DummyInterceptor() {
-            super();
-        }
-    
-        public Set<QName> getHeaders() {
-            return Collections.emptySet();
-        }
-    
-        public void close(MessageContext mc) {
-        }
-    
-        public boolean handleFault(SOAPMessageContext mc) {
-            return true;
-        }
-    
-        public boolean handleMessage(SOAPMessageContext mc) {
-            return true;
-        }
-    }
+The wsdl for our is automatically created and available at `http://theserver?appName/Calculator?wsdl`  where `theServer` is the address of the server, such as `localhost:8080` and `appName
 
-## handler.xml
+## Accessing the @WebService with javax.xml.ws.Service
 
-    <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>
-      </handler-chain>
-    </handler-chains>
-    
+In our testcase we see how to create a client for our `Calculator` service via the `javax.xml.ws.Service` class and leveraging our `CalculatorWs` endpoint interface.
 
-## CalculatorTest
+With this we can get an implementation of the interfacce generated dynamically for us that can be used to send compliant SOAP messages to our service.
 
-    package org.superbiz.calculator;
-    
-    import junit.framework.TestCase;
-    import org.apache.openejb.api.LocalClient;
+    import org.junit.BeforeClass;
+    import org.junit.Test;
     
-    import javax.naming.Context;
-    import javax.naming.InitialContext;
+    import javax.ejb.embeddable.EJBContainer;
     import javax.xml.namespace.QName;
-    import javax.xml.ws.Holder;
     import javax.xml.ws.Service;
-    import javax.xml.ws.WebServiceRef;
     import java.net.URL;
-    import java.util.Date;
     import java.util.Properties;
     
-    @LocalClient
-    public class CalculatorTest extends TestCase {
-    
-        @WebServiceRef(
-                wsdlLocation = "http://127.0.0.1:4204/CalculatorImpl?wsdl"
-        )
-        private CalculatorWs calculatorWs;
-    
-        private InitialContext initialContext;
+    import static org.junit.Assert.assertEquals;
+    import static org.junit.Assert.assertNotNull;
     
-        // date used to invoke a web service with INOUT parameters
-        private static final Date date = new Date();
+    public class CalculatorTest {
     
-        protected void setUp() throws Exception {
+        @BeforeClass
+        public static 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);
-        }
-
-        /**
-         * Create a webservice client using wsdl url
-         *
-         * @throws Exception
-         */
-        public void testCalculatorViaWsInterface() throws Exception {
-            Service calcService = Service.create(
-                    new URL("http://127.0.0.1:4204/CalculatorImpl?wsdl"),
-                    new QName("http://superbiz.org/wsdl", "CalculatorWsService"));
-            assertNotNull(calcService);
-    
-            CalculatorWs calc = calcService.getPort(CalculatorWs.class);
-            assertEquals(10, calc.sum(4, 6));
-            assertEquals(12, calc.multiply(3, 4));
-    
-            Holder<String> userIdHolder = new Holder<String>("jane");
-            Holder<String> returnCodeHolder = new Holder<String>();
-            Holder<Date> datetimeHolder = new Holder<Date>(date);
-            assertEquals(6, calc.factorial(3, userIdHolder, returnCodeHolder, datetimeHolder));
-            assertEquals(userIdHolder.value, returnCodeHolder.value);
-            assertTrue(date.before(datetimeHolder.value));
-        }
-    
-        public void testWebServiceRefInjection() throws Exception {
-            assertEquals(10, calculatorWs.sum(4, 6));
-            assertEquals(12, calculatorWs.multiply(3, 4));
-    
-            Holder<String> userIdHolder = new Holder<String>("jane");
-            Holder<String> returnCodeHolder = new Holder<String>();
-            Holder<Date> datetimeHolder = new Holder<Date>(date);
-            assertEquals(6, calculatorWs.factorial(3, userIdHolder, returnCodeHolder, datetimeHolder));
-            assertEquals(userIdHolder.value, returnCodeHolder.value);
-            assertTrue(date.before(datetimeHolder.value));
-        }
-    
-        public void testCalculatorViaRemoteInterface() throws Exception {
-            CalculatorLocal calc = (CalculatorLocal) initialContext.lookup("CalculatorImplLocal");
-            assertEquals(10, calc.sum(4, 6));
-            assertEquals(12, calc.multiply(3, 4));
-    
-            Holder<String> userIdHolder = new Holder<String>("jane");
-            Holder<String> returnCodeHolder = new Holder<String>();
-            Holder<Date> datetimeHolder = new Holder<Date>(date);
-            assertEquals(6, calc.factorial(3, userIdHolder, returnCodeHolder, datetimeHolder));
-            assertEquals(userIdHolder.value, returnCodeHolder.value);
-            assertTrue(date.before(datetimeHolder.value));
+            properties.setProperty("httpejbd.print", "true");
+            properties.setProperty("httpejbd.indent.xml", "true");
+            EJBContainer.createEJBContainer(properties);
+        }
+    
+        @Test
+        public void test() throws Exception {
+            Service calculatorService = Service.create(
+                    new URL("http://127.0.0.1:4204/Calculator?wsdl"),
+                    new QName("http://superbiz.org/wsdl", "CalculatorService"));
+    
+            assertNotNull(calculatorService);
+    
+            CalculatorWs calculator = calculatorService.getPort(CalculatorWs.class);
+            assertEquals(10, calculator.sum(4, 6));
+            assertEquals(12, calculator.multiply(3, 4));
         }
     }
 
-## ejb-jar.xml
-
-    <ejb-jar/>
+For easy testing we'll use the Embeddable EJBContainer API part of EJB 3.1 to boot CXF in our testcase.  This will deploy our application in the embedded container and bring the web service online so we can invoke it.
 
 # Running
 
-    
+Running the example can be done from maven with a simple 'mvn clean install' command run from the 'simple-webservice' directory.
+
+When run you should see output similar to the following.
+
     -------------------------------------------------------
      T E S T S
     -------------------------------------------------------
-    Running org.superbiz.calculator.CalculatorTest
-    Apache OpenEJB 4.0.0-beta-1    build: 20111002-04:06
-    http://openejb.apache.org/
-    INFO - openejb.home = /Users/dblevins/examples/simple-webservice
-    INFO - openejb.base = /Users/dblevins/examples/simple-webservice
+    Running org.superbiz.calculator.ws.CalculatorTest
+    INFO - ********************************************************************************
+    INFO - OpenEJB http://openejb.apache.org/
+    INFO - Startup: Sat Feb 18 19:11:50 PST 2012
+    INFO - Copyright 1999-2012 (C) Apache OpenEJB Project, All Rights Reserved.
+    INFO - Version: 4.0.0-beta-3-SNAPSHOT
+    INFO - Build date: 20120218
+    INFO - Build time: 03:32
+    INFO - ********************************************************************************
+    INFO - openejb.home = /Users/dblevins/work/all/trunk/openejb/examples/simple-webservice
+    INFO - openejb.base = /Users/dblevins/work/all/trunk/openejb/examples/simple-webservice
+    INFO - Created new singletonService org.apache.openejb.cdi.ThreadSingletonServiceImpl@16bdb503
+    INFO - succeeded in installing singleton service
+    INFO - Using 'javax.ejb.embeddable.EJBContainer=true'
+    INFO - Cannot find the configuration file [conf/openejb.xml].  Will attempt to create one for the beans deployed.
     INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
     INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
-    INFO - Found EjbModule in classpath: /Users/dblevins/examples/simple-webservice/target/test-classes
-    INFO - Found EjbModule in classpath: /Users/dblevins/examples/simple-webservice/target/classes
-    INFO - Beginning load: /Users/dblevins/examples/simple-webservice/target/test-classes
-    INFO - Beginning load: /Users/dblevins/examples/simple-webservice/target/classes
-    INFO - Configuring enterprise application: /Users/dblevins/examples/simple-webservice/classpath.ear
+    INFO - Creating TransactionManager(id=Default Transaction Manager)
+    INFO - Creating SecurityService(id=Default Security Service)
+    INFO - Beginning load: /Users/dblevins/work/all/trunk/openejb/examples/simple-webservice/target/classes
+    INFO - Using 'openejb.embedded=true'
+    INFO - Configuring enterprise application: /Users/dblevins/work/all/trunk/openejb/examples/simple-webservice
+    INFO - Auto-deploying ejb Calculator: EjbDeployment(deployment-id=Calculator)
     INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container)
-    INFO - Auto-creating a container for bean CalculatorImpl: Container(type=STATELESS, id=Default Stateless Container)
-    INFO - Enterprise application "/Users/dblevins/examples/simple-webservice/classpath.ear" loaded.
-    INFO - Assembling app: /Users/dblevins/examples/simple-webservice/classpath.ear
-    INFO - Jndi(name=CalculatorImplLocal) --> Ejb(deployment-id=CalculatorImpl)
-    INFO - Jndi(name=global/classpath.ear/simple-webservice/CalculatorImpl!org.superbiz.calculator.CalculatorLocal) --> Ejb(deployment-id=CalculatorImpl)
-    INFO - Jndi(name=global/classpath.ear/simple-webservice/CalculatorImpl) --> Ejb(deployment-id=CalculatorImpl)
-    INFO - Created Ejb(deployment-id=CalculatorImpl, ejb-name=CalculatorImpl, container=Default Stateless Container)
-    INFO - Started Ejb(deployment-id=CalculatorImpl, ejb-name=CalculatorImpl, container=Default Stateless Container)
-    INFO - LocalClient(class=org.superbiz.calculator.CalculatorTest, module=test-classes) 
-    INFO - Deployed Application(path=/Users/dblevins/examples/simple-webservice/classpath.ear)
+    INFO - Auto-creating a container for bean Calculator: Container(type=STATELESS, id=Default Stateless Container)
+    INFO - Creating Container(id=Default Stateless Container)
+    INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
+    INFO - Auto-creating a container for bean org.superbiz.calculator.ws.CalculatorTest: Container(type=MANAGED, id=Default Managed Container)
+    INFO - Creating Container(id=Default Managed Container)
+    INFO - Using directory /var/folders/bd/f9ntqy1m8xj_fs006s6crtjh0000gn/T for stateful session passivation
+    INFO - Enterprise application "/Users/dblevins/work/all/trunk/openejb/examples/simple-webservice" loaded.
+    INFO - Assembling app: /Users/dblevins/work/all/trunk/openejb/examples/simple-webservice
+    INFO - ignoreXmlConfiguration == true
+    INFO - ignoreXmlConfiguration == true
+    INFO - existing thread singleton service in SystemInstance() org.apache.openejb.cdi.ThreadSingletonServiceImpl@16bdb503
+    INFO - OpenWebBeans Container is starting...
+    INFO - Adding OpenWebBeansPlugin : [CdiPlugin]
+    INFO - All injection points were validated successfully.
+    INFO - OpenWebBeans Container has started, it took [62] ms.
+    INFO - Created Ejb(deployment-id=Calculator, ejb-name=Calculator, container=Default Stateless Container)
+    INFO - Started Ejb(deployment-id=Calculator, ejb-name=Calculator, container=Default Stateless Container)
+    INFO - Deployed Application(path=/Users/dblevins/work/all/trunk/openejb/examples/simple-webservice)
     INFO - Initializing network services
+    INFO - can't find log4j MDC class
     INFO - Creating ServerService(id=httpejbd)
     INFO - Creating ServerService(id=cxf)
     INFO - Creating ServerService(id=admin)
     INFO - Creating ServerService(id=ejbd)
     INFO - Creating ServerService(id=ejbds)
     INFO - Initializing network services
-      ** Starting Services **
-      NAME                 IP              PORT  
-      httpejbd             127.0.0.1       4204  
-      admin thread         127.0.0.1       4200  
-      ejbd                 127.0.0.1       4201  
-      ejbd                 127.0.0.1       4203  
-    -------
-    Ready!
-    Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.211 sec
-    
+    INFO -   ** Starting Services **
+    INFO -   NAME                 IP              PORT
+    INFO -   httpejbd             127.0.0.1       4204
+    INFO - Creating Service {http://superbiz.org/wsdl}CalculatorService from class org.superbiz.calculator.ws.CalculatorWs
+    INFO - Setting the server's publish address to be http://nopath:80
+    INFO - Webservice(wsdl=http://127.0.0.1:4204/Calculator, qname={http://superbiz.org/wsdl}CalculatorService) --> Ejb(id=Calculator)
+    INFO -   admin thread         127.0.0.1       4200
+    INFO -   ejbd                 127.0.0.1       4201
+    INFO -   ejbd                 127.0.0.1       4203
+    INFO - -------
+    INFO - Ready!
+    INFO - Creating Service {http://superbiz.org/wsdl}CalculatorService from WSDL: http://127.0.0.1:4204/Calculator?wsdl
+    INFO - Creating Service {http://superbiz.org/wsdl}CalculatorService from WSDL: http://127.0.0.1:4204/Calculator?wsdl
+    INFO - Default SAAJ universe not set
+    INFO - TX NotSupported: Suspended transaction null
+    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.584 sec
+
     Results :
-    
-    Tests run: 3, Failures: 0, Errors: 0, Skipped: 0
-    
+
+    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
+
+## Inspecting the messages
+
+The above test case will result in the following SOAP messages being sent between the clien and server.
+
+### sum(int, int)
+
+Request SOAP message:
+
+    <?xml version="1.0" encoding="UTF-8"?>
+    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+      <soap:Body>
+        <ns1:sum xmlns:ns1="http://superbiz.org/wsdl">
+          <arg0>4</arg0>
+          <arg1>6</arg1>
+        </ns1:sum>
+      </soap:Body>
+    </soap:Envelope>
+
+Response SOAP message:
+
+    <?xml version="1.0" encoding="UTF-8"?>
+    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+      <soap:Body>
+        <ns1:sumResponse xmlns:ns1="http://superbiz.org/wsdl">
+          <return>10</return>
+        </ns1:sumResponse>
+      </soap:Body>
+    </soap:Envelope>
+
+### multiply(int, int)
+
+Request SOAP message:
+
+    <?xml version="1.0" encoding="UTF-8"?>
+    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+      <soap:Body>
+        <ns1:multiply xmlns:ns1="http://superbiz.org/wsdl">
+          <arg0>3</arg0>
+          <arg1>4</arg1>
+        </ns1:multiply>
+      </soap:Body>
+    </soap:Envelope>
+
+Response SOAP message:
+
+    <?xml version="1.0" encoding="UTF-8"?>
+    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+      <soap:Body>
+        <ns1:multiplyResponse xmlns:ns1="http://superbiz.org/wsdl">
+          <return>12</return>
+        </ns1:multiplyResponse>
+      </soap:Body>
+    </soap:Envelope>

Copied: openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/Calculator.java (from r1245850, 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/Calculator.java?p2=openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/Calculator.java&p1=openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorImpl.java&r1=1245850&r2=1290928&rev=1290928&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorImpl.java (original)
+++ openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/Calculator.java Sun Feb 19 03:19:28 2012
@@ -17,30 +17,15 @@
 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",
+        serviceName = "CalculatorService",
         targetNamespace = "http://superbiz.org/wsdl",
         endpointInterface = "org.superbiz.calculator.ws.CalculatorWs")
-@HandlerChain(file = "handler.xml")
-public class CalculatorImpl implements CalculatorWs, CalculatorLocal {
+public class Calculator implements CalculatorWs {
 
     public int sum(int add1, int add2) {
         return add1 + add2;
@@ -49,31 +34,4 @@ public class CalculatorImpl implements C
     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

Modified: 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=1290928&r1=1290927&r2=1290928&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorWs.java (original)
+++ openejb/trunk/openejb/examples/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorWs.java Sun Feb 19 03:19:28 2012
@@ -16,40 +16,12 @@
  */
 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")
+@WebService(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/test/java/org/superbiz/calculator/ws/CalculatorTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/simple-webservice/src/test/java/org/superbiz/calculator/ws/CalculatorTest.java?rev=1290928&r1=1290927&r2=1290928&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/simple-webservice/src/test/java/org/superbiz/calculator/ws/CalculatorTest.java (original)
+++ openejb/trunk/openejb/examples/simple-webservice/src/test/java/org/superbiz/calculator/ws/CalculatorTest.java Sun Feb 19 03:19:28 2012
@@ -16,93 +16,39 @@
  */
 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 org.junit.BeforeClass;
+import org.junit.Test;
 
 import javax.ejb.embeddable.EJBContainer;
-import javax.naming.Context;
 import javax.xml.namespace.QName;
-import javax.xml.ws.Holder;
 import javax.xml.ws.Service;
-import javax.xml.ws.WebServiceRef;
 import java.net.URL;
-import java.util.Date;
 import java.util.Properties;
 
-@LocalClient
-public class CalculatorTest extends TestCase {
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
-    @WebServiceRef(
-            wsdlLocation = "http://127.0.0.1:4204/CalculatorImpl?wsdl"
-    )
-    private CalculatorWs calculatorWs;
-
-    // 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 {
+public class CalculatorTest {
 
+    @BeforeClass
+    public static 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");
-
-        context = EJBContainer.createEJBContainer(properties).getContext();
-        context.bind("inject", this);
-
-    }
-    //END SNIPPET: setup    
-
-    /**
-     * Create a webservice client using wsdl url
-     *
-     * @throws Exception
-     */
-    //START SNIPPET: webservice
-    public void testCalculatorViaWsInterface() throws Exception {
-        Service calcService = Service.create(
-                new URL("http://127.0.0.1:4204/CalculatorImpl?wsdl"),
-                new QName("http://superbiz.org/wsdl", "CalculatorWsService"));
-        assertNotNull(calcService);
-
-        CalculatorWs calc = calcService.getPort(CalculatorWs.class);
-        assertEquals(10, calc.sum(4, 6));
-        assertEquals(12, calc.multiply(3, 4));
-
-        Holder<String> userIdHolder = new Holder<String>("jane");
-        Holder<String> returnCodeHolder = new Holder<String>();
-        Holder<Date> datetimeHolder = new Holder<Date>(date);
-        assertEquals(6, calc.factorial(3, userIdHolder, returnCodeHolder, datetimeHolder));
-        assertEquals(userIdHolder.value, returnCodeHolder.value);
-        assertTrue(date.before(datetimeHolder.value));
-    }
-
-    public void testWebServiceRefInjection() throws Exception {
-        assertEquals(10, calculatorWs.sum(4, 6));
-        assertEquals(12, calculatorWs.multiply(3, 4));
-
-        Holder<String> userIdHolder = new Holder<String>("jane");
-        Holder<String> returnCodeHolder = new Holder<String>();
-        Holder<Date> datetimeHolder = new Holder<Date>(date);
-        assertEquals(6, calculatorWs.factorial(3, userIdHolder, returnCodeHolder, datetimeHolder));
-        assertEquals(userIdHolder.value, returnCodeHolder.value);
-        assertTrue(date.before(datetimeHolder.value));
+        //properties.setProperty("httpejbd.print", "true");
+        //properties.setProperty("httpejbd.indent.xml", "true");
+        EJBContainer.createEJBContainer(properties);
     }
 
-    public void testCalculatorViaRemoteInterface() throws Exception {
-        CalculatorLocal calc = (CalculatorLocal) context.lookup("java:global/simple-webservice/CalculatorImpl");
-        assertEquals(10, calc.sum(4, 6));
-        assertEquals(12, calc.multiply(3, 4));
-
-        Holder<String> userIdHolder = new Holder<String>("jane");
-        Holder<String> returnCodeHolder = new Holder<String>();
-        Holder<Date> datetimeHolder = new Holder<Date>(date);
-        assertEquals(6, calc.factorial(3, userIdHolder, returnCodeHolder, datetimeHolder));
-        assertEquals(userIdHolder.value, returnCodeHolder.value);
-        assertTrue(date.before(datetimeHolder.value));
+    @Test
+    public void test() throws Exception {
+        Service calculatorService = Service.create(
+                new URL("http://127.0.0.1:4204/Calculator?wsdl"),
+                new QName("http://superbiz.org/wsdl", "CalculatorService"));
+
+        assertNotNull(calculatorService);
+
+        CalculatorWs calculator = calculatorService.getPort(CalculatorWs.class);
+        assertEquals(10, calculator.sum(4, 6));
+        assertEquals(12, calculator.multiply(3, 4));
     }
-    //END SNIPPET: webservice
-
 }