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 06:15:30 UTC

svn commit: r1245862 - in /openejb/trunk/openejb/examples/webservice-handlers: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/superbiz/ src/main/java/org/superbiz/calculator/ src/main/java/org/superbiz/calculator/wsh/ src/main/re...

Author: dblevins
Date: Sat Feb 18 05:15:28 2012
New Revision: 1245862

URL: http://svn.apache.org/viewvc?rev=1245862&view=rev
Log:
TOMEE-139: Example: @WebService @HandlerChain

Added:
    openejb/trunk/openejb/examples/webservice-handlers/
    openejb/trunk/openejb/examples/webservice-handlers/README.md
    openejb/trunk/openejb/examples/webservice-handlers/build.xml   (with props)
    openejb/trunk/openejb/examples/webservice-handlers/pom.xml   (with props)
    openejb/trunk/openejb/examples/webservice-handlers/src/
    openejb/trunk/openejb/examples/webservice-handlers/src/main/
    openejb/trunk/openejb/examples/webservice-handlers/src/main/java/
    openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/
    openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/
    openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/
    openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/
    openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/Calculator.java   (with props)
    openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/CalculatorWs.java   (with props)
    openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/Increment.java   (with props)
    openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/Inflate.java   (with props)
    openejb/trunk/openejb/examples/webservice-handlers/src/main/resources/
    openejb/trunk/openejb/examples/webservice-handlers/src/main/resources/org/
    openejb/trunk/openejb/examples/webservice-handlers/src/main/resources/org/superbiz/
    openejb/trunk/openejb/examples/webservice-handlers/src/main/resources/org/superbiz/calculator/
    openejb/trunk/openejb/examples/webservice-handlers/src/main/resources/org/superbiz/calculator/wsh/
    openejb/trunk/openejb/examples/webservice-handlers/src/main/resources/org/superbiz/calculator/wsh/handlers.xml   (with props)
    openejb/trunk/openejb/examples/webservice-handlers/src/test/
    openejb/trunk/openejb/examples/webservice-handlers/src/test/java/
    openejb/trunk/openejb/examples/webservice-handlers/src/test/java/org/
    openejb/trunk/openejb/examples/webservice-handlers/src/test/java/org/superbiz/
    openejb/trunk/openejb/examples/webservice-handlers/src/test/java/org/superbiz/calculator/
    openejb/trunk/openejb/examples/webservice-handlers/src/test/java/org/superbiz/calculator/wsh/
    openejb/trunk/openejb/examples/webservice-handlers/src/test/java/org/superbiz/calculator/wsh/CalculatorTest.java   (with props)
    openejb/trunk/openejb/examples/webservice-handlers/src/test/resources/
    openejb/trunk/openejb/examples/webservice-handlers/src/test/resources/META-INF/
    openejb/trunk/openejb/examples/webservice-handlers/src/test/resources/META-INF/ejb-jar.xml   (with props)

Added: openejb/trunk/openejb/examples/webservice-handlers/README.md
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/webservice-handlers/README.md?rev=1245862&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/webservice-handlers/README.md (added)
+++ openejb/trunk/openejb/examples/webservice-handlers/README.md Sat Feb 18 05:15:28 2012
@@ -0,0 +1,202 @@
+Title: @WebService handlers with @HandlerChain
+
+In this example we see a basic JAX-WS `@WebService` component use a handler chain to alter incoming and outgoing SOAP messages.  SOAP Handlers are similar to Servlet Filters or EJB/CDI Interceptors.
+
+At high level, the steps involved are:
+
+ 1. Create handler(s) implementing `javax.xml.ws.handler.soap.SOAPHandler`
+ 1. Declare and order them in an xml file via `<handler-chain>`
+ 1. Associate the xml file with an `@WebService` component via `@HandlerChain`
+
+## The @HandlerChain
+
+First we'll start with our plain `@WebService` bean, called `Calculator`, which is annotated with `@HandlerChain`
+
+    @Singleton
+    @WebService(
+            portName = "CalculatorPort",
+            serviceName = "CalculatorService",
+            targetNamespace = "http://superbiz.org/wsdl",
+            endpointInterface = "org.superbiz.calculator.wsh.CalculatorWs")
+    @HandlerChain(file = "handlers.xml")
+    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;
+        }
+    }
+
+Here we see `@HandlerChain` pointing to a file called `handlers.xml`.  This file could be called anything, but it must be in the same jar and java package as our `Calculator` component.
+
+## The handlers.xml file
+
+Our `Calculator` service is in the package `org.superbiz.calculator.wsh`, which means our handler chain xml file must be at `org/superbiz/calculator/wsh/handlers.xml` in our application's classpath or the file will not be found and no handlers will be used.
+
+In maven we achieve this by putting our handlers.xml in `src/main/resources` like so:
+
+ - `src/main/resources/org/superbiz/calculator/wsh/handlers.xml`
+
+With this file we declare and **order** our handler chain.
+
+    <?xml version="1.0" encoding="UTF-8"?>
+    <handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
+      <handler-chain>
+        <handler>
+          <handler-name>org.superbiz.calculator.wsh.Inflate</handler-name>
+          <handler-class>org.superbiz.calculator.wsh.Inflate</handler-class>
+        </handler>
+        <handler>
+          <handler-name>org.superbiz.calculator.wsh.Increment</handler-name>
+          <handler-class>org.superbiz.calculator.wsh.Increment</handler-class>
+        </handler>
+      </handler-chain>
+    </handler-chains>
+
+The order as you might suspect is:
+
+ - `Inflate`
+ - `Increment`
+
+## The handler implementation
+
+Our `Inflate` handler has the job of monitoring *responses* to the `sum` and `multiply` operations and making them 1000 times better.  Manipulation of the message is done by walking the `SOAPBody` and editing the nodes.  The `handleMessage` method is invoked for both requests and responses, so it is important to check the `SOAPBody` before attempting to naviage the nodes.
+
+    import org.w3c.dom.Node;
+    import javax.xml.namespace.QName;
+    import javax.xml.soap.SOAPBody;
+    import javax.xml.soap.SOAPException;
+    import javax.xml.soap.SOAPMessage;
+    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 Inflate implements SOAPHandler<SOAPMessageContext> {
+
+        public boolean handleMessage(SOAPMessageContext mc) {
+            try {
+                final SOAPMessage message = mc.getMessage();
+                final SOAPBody body = message.getSOAPBody();
+                final String localName = body.getFirstChild().getLocalName();
+
+                if ("sumResponse".equals(localName) || "multiplyResponse".equals(localName)) {
+                    final Node responseNode = body.getFirstChild();
+                    final Node returnNode = responseNode.getFirstChild();
+                    final Node intNode = returnNode.getFirstChild();
+
+                    final int value = new Integer(intNode.getNodeValue());
+                    intNode.setNodeValue(Integer.toString(value * 1000));
+                }
+
+                return true;
+            } catch (SOAPException e) {
+                return false;
+            }
+        }
+
+        public Set<QName> getHeaders() {
+            return Collections.emptySet();
+        }
+
+        public void close(MessageContext mc) {
+        }
+
+        public boolean handleFault(SOAPMessageContext mc) {
+            return true;
+        }
+    }
+
+The `Increment` handler is identical in code and therefore not shown.  Instead of multiplying by 1000, it simply adds 1.
+
+## The TestCase
+
+We use the JAX-WS API to create a Java client for our `Calculator` web service and use it to invoke both the `sum` and `multiply` operations.  Note the clever use of math to assert both the existence and order of our handlers.  If `Inflate` and `Increment` were reversed, the responses would be 11000 and 13000 respectively.
+
+    public class CalculatorTest {
+
+        @BeforeClass
+        public static void setUp() throws Exception {
+            Properties properties = new Properties();
+            properties.setProperty("openejb.embedded.remotable", "true");
+            EJBContainer.createEJBContainer(properties);
+        }
+
+        @Test
+        public void testCalculatorViaWsInterface() throws Exception {
+            final Service calculatorService = Service.create(
+                    new URL("http://127.0.0.1:4204/Calculator?wsdl"),
+                    new QName("http://superbiz.org/wsdl", "CalculatorService"));
+
+            assertNotNull(calculatorService);
+
+            final CalculatorWs calculator = calculatorService.getPort(CalculatorWs.class);
+
+            // we expect our answers to come back 1000 times better, plus one!
+            assertEquals(10001, calculator.sum(4, 6));
+            assertEquals(12001, calculator.multiply(3, 4));
+        }
+    }
+
+## Running the example
+
+Simply run `mvn clean install` and you should see output similar to the following:
+
+    -------------------------------------------------------
+     T E S T S
+    -------------------------------------------------------
+    Running org.superbiz.calculator.wsh.CalculatorTest
+    INFO - openejb.home = /Users/dblevins/work/all/trunk/openejb/examples/webservice-handlers
+    INFO - openejb.base = /Users/dblevins/work/all/trunk/openejb/examples/webservice-handlers
+    INFO - Using 'javax.ejb.embeddable.EJBContainer=true'
+    INFO - Cannot find the configuration file [conf/openejb.xml].  Will attempt to create one for the beans deployed.
+    INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
+    INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
+    INFO - Creating TransactionManager(id=Default Transaction Manager)
+    INFO - Creating SecurityService(id=Default Security Service)
+    INFO - Beginning load: /Users/dblevins/work/all/trunk/openejb/examples/webservice-handlers/target/test-classes
+    INFO - Beginning load: /Users/dblevins/work/all/trunk/openejb/examples/webservice-handlers/target/classes
+    INFO - Configuring enterprise application: /Users/dblevins/work/all/trunk/openejb/examples/webservice-handlers
+    INFO - Auto-deploying ejb Calculator: EjbDeployment(deployment-id=Calculator)
+    INFO - Configuring Service(id=Default Singleton Container, type=Container, provider-id=Default Singleton Container)
+    INFO - Auto-creating a container for bean Calculator: Container(type=SINGLETON, id=Default Singleton Container)
+    INFO - Creating Container(id=Default Singleton 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.wsh.CalculatorTest: Container(type=MANAGED, id=Default Managed Container)
+    INFO - Creating Container(id=Default Managed Container)
+    INFO - Enterprise application "/Users/dblevins/work/all/trunk/openejb/examples/webservice-handlers" loaded.
+    INFO - Assembling app: /Users/dblevins/work/all/trunk/openejb/examples/webservice-handlers
+    INFO - Created Ejb(deployment-id=Calculator, ejb-name=Calculator, container=Default Singleton Container)
+    INFO - Started Ejb(deployment-id=Calculator, ejb-name=Calculator, container=Default Singleton Container)
+    INFO - Deployed Application(path=/Users/dblevins/work/all/trunk/openejb/examples/webservice-handlers)
+    INFO - Initializing network services
+    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
+    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.wsh.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
+    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.783 sec
+
+    Results :
+
+    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
+

Added: openejb/trunk/openejb/examples/webservice-handlers/build.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/webservice-handlers/build.xml?rev=1245862&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/webservice-handlers/build.xml (added)
+++ openejb/trunk/openejb/examples/webservice-handlers/build.xml Sat Feb 18 05:15:28 2012
@@ -0,0 +1,119 @@
+<?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: 1237516 $ $Date: 2012-01-29 16:48:17 -0800 (Sun, 29 Jan 2012) $ -->
+
+<project name="MyProject" default="dist" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">
+
+  <!-- ===============================================================
+
+  HOW TO RUN
+
+    Download http://archive.apache.org/dist/maven/binaries/maven-ant-tasks-2.0.9.jar
+    Then execute ant as follows:
+
+    ant -lib maven-ant-tasks-2.0.9.jar
+
+  NOTE
+
+    You do NOT need maven-ant-tasks-2.0.9.jar to use OpenEJB for embedded EJB
+    testing with Ant.  It is simply used in this example to make the build.xml
+    a bit simpler.  As long as OpenEJB and it's required libraries are in the
+    <junit> classpath, the tests will run with OpenEJB embedded.
+
+  ================================================================= -->
+
+  <artifact:remoteRepository id="apache.snapshot.repository" url="http://repository.apache.org/snapshots/"/>
+  <artifact:remoteRepository id="m2.repository" url="http://repo1.maven.org/maven2/"/>
+
+  <!-- Build Classpath -->
+  <artifact:dependencies pathId="classpath.main">
+    <dependency groupId="org.apache.openejb" artifactId="javaee-api-embedded" version="6.0-3"/>
+  </artifact:dependencies>
+
+  <!-- Test Build Classpath -->
+  <artifact:dependencies pathId="classpath.test.build">
+    <dependency groupId="junit" artifactId="junit" version="4.3.1"/>
+  </artifact:dependencies>
+
+  <!-- Test Run Classpath -->
+  <artifact:dependencies pathId="classpath.test.run">
+    <remoteRepository refid="apache.snapshot.repository"/>
+    <remoteRepository refid="m2.repository"/>
+
+    <dependency groupId="org.apache.openejb" artifactId="openejb-cxf" version="4.0.0-beta-1"/>
+    <dependency groupId="junit" artifactId="junit" version="4.3.1"/>
+  </artifact:dependencies>
+
+  <!-- Properties -->
+
+  <property name="src.main.java" location="src/main/java"/>
+  <property name="src.main.resources" location="src/main/resources"/>
+  <property name="src.test.java" location="src/test/java"/>
+  <property name="build.main" location="target/classes"/>
+  <property name="build.test" location="target/test-classes"/>
+  <property name="test.reports" location="target/test-reports"/>
+  <property name="dist" location="target"/>
+
+
+  <target name="init">
+    <mkdir dir="${build.main}"/>
+    <mkdir dir="${build.test}"/>
+    <mkdir dir="${test.reports}"/>
+  </target>
+
+  <target name="compile" depends="init">
+
+    <javac srcdir="${src.main.java}" destdir="${build.main}">
+      <classpath refid="classpath.main"/>
+    </javac>
+    <copy todir="${build.main}">
+      <fileset dir="${src.main.resources}"/>
+    </copy>
+
+    <javac srcdir="${src.test.java}" destdir="${build.test}">
+      <classpath location="${build.main}"/>
+      <classpath refid="classpath.main"/>
+      <classpath refid="classpath.test.build"/>
+    </javac>
+  </target>
+
+  <target name="test" depends="compile">
+    <junit fork="yes" printsummary="yes">
+      <classpath location="${build.main}"/>
+      <classpath location="${build.test}"/>
+      <classpath refid="classpath.main"/>
+      <classpath refid="classpath.test.build"/>
+      <classpath refid="classpath.test.run"/>
+
+      <formatter type="plain"/>
+
+      <batchtest fork="yes" todir="${test.reports}">
+        <fileset dir="${src.test.java}">
+          <include name="**/*Test.java"/>
+        </fileset>
+      </batchtest>
+    </junit>
+  </target>
+
+  <target name="dist" depends="test">
+    <jar jarfile="${dist}/myproject-1.0.jar" basedir="${build.main}"/>
+  </target>
+
+</project>

Propchange: openejb/trunk/openejb/examples/webservice-handlers/build.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openejb/trunk/openejb/examples/webservice-handlers/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/webservice-handlers/pom.xml?rev=1245862&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/webservice-handlers/pom.xml (added)
+++ openejb/trunk/openejb/examples/webservice-handlers/pom.xml Sat Feb 18 05:15:28 2012
@@ -0,0 +1,102 @@
+<?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: 1237516 $ $Date: 2012-01-29 16:48:17 -0800 (Sun, 29 Jan 2012) $ -->
+
+<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>webservice-handlers</artifactId>
+  <packaging>jar</packaging>
+  <version>1.1-SNAPSHOT</version>
+  <name>OpenEJB :: Examples :: Web Service Handlers</name>
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+  <build>
+    <defaultGoal>install</defaultGoal>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.3.2</version>
+        <configuration>
+          <source>1.6</source>
+          <target>1.6</target>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <repositories>
+    <repository>
+      <id>apache-m2-snapshot</id>
+      <name>Apache Snapshot Repository</name>
+      <url>http://repository.apache.org/snapshots</url>
+    </repository>
+  </repositories>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>javaee-api</artifactId>
+      <version>6.0-3</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <!--
+    The <scope>test</scope> guarantees that non of your runtime
+    code is dependent on any OpenEJB classes.
+    -->
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-cxf</artifactId>
+      <version>4.0.0-beta-3-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+    <!-- This is required on IBM JDKs (and potentially others) because saaj-impl depends
+         on Sun's internal copy of Xerces. See OPENEJB-1126. -->
+    <dependency>
+      <groupId>com.sun.xml.parsers</groupId>
+      <artifactId>jaxp-ri</artifactId>
+      <version>1.4.2</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>

Propchange: openejb/trunk/openejb/examples/webservice-handlers/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/Calculator.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/Calculator.java?rev=1245862&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/Calculator.java (added)
+++ openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/Calculator.java Sat Feb 18 05:15:28 2012
@@ -0,0 +1,39 @@
+/**
+ * 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.wsh;
+
+import javax.ejb.Singleton;
+import javax.jws.HandlerChain;
+import javax.jws.WebService;
+
+@Singleton
+@WebService(
+        portName = "CalculatorPort",
+        serviceName = "CalculatorService",
+        targetNamespace = "http://superbiz.org/wsdl",
+        endpointInterface = "org.superbiz.calculator.wsh.CalculatorWs")
+@HandlerChain(file = "handlers.xml")
+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;
+    }
+}

Propchange: openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/Calculator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/CalculatorWs.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/CalculatorWs.java?rev=1245862&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/CalculatorWs.java (added)
+++ openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/CalculatorWs.java Sat Feb 18 05:15:28 2012
@@ -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.calculator.wsh;
+
+import javax.jws.WebService;
+
+@WebService(targetNamespace = "http://superbiz.org/wsdl")
+public interface CalculatorWs {
+
+    public int sum(int add1, int add2);
+
+    public int multiply(int mul1, int mul2);
+}

Propchange: openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/CalculatorWs.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/Increment.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/Increment.java?rev=1245862&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/Increment.java (added)
+++ openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/Increment.java Sat Feb 18 05:15:28 2012
@@ -0,0 +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
+ *
+ *     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.wsh;
+
+import org.w3c.dom.Node;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
+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 Increment implements SOAPHandler<SOAPMessageContext> {
+
+    public boolean handleMessage(SOAPMessageContext mc) {
+        try {
+            final SOAPMessage message = mc.getMessage();
+            final SOAPBody body = message.getSOAPBody();
+            final String localName = body.getFirstChild().getLocalName();
+
+            if ("sumResponse".equals(localName) || "multiplyResponse".equals(localName)) {
+                final Node responseNode = body.getFirstChild();
+                final Node returnNode = responseNode.getFirstChild();
+                final Node intNode = returnNode.getFirstChild();
+
+                final int value = new Integer(intNode.getNodeValue());
+                intNode.setNodeValue(Integer.toString(value + 1));
+            }
+
+            return true;
+        } catch (SOAPException e) {
+            return false;
+        }
+    }
+
+    public Set<QName> getHeaders() {
+        return Collections.emptySet();
+    }
+
+    public void close(MessageContext mc) {
+    }
+
+    public boolean handleFault(SOAPMessageContext mc) {
+        return true;
+    }
+}
\ No newline at end of file

Propchange: openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/Increment.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/Inflate.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/Inflate.java?rev=1245862&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/Inflate.java (added)
+++ openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/Inflate.java Sat Feb 18 05:15:28 2012
@@ -0,0 +1,63 @@
+/**
+ * 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.wsh;
+
+import org.w3c.dom.Node;
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
+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 Inflate implements SOAPHandler<SOAPMessageContext> {
+
+    public boolean handleMessage(SOAPMessageContext mc) {
+        try {
+            final SOAPMessage message = mc.getMessage();
+            final SOAPBody body = message.getSOAPBody();
+            final String localName = body.getFirstChild().getLocalName();
+
+            if ("sumResponse".equals(localName) || "multiplyResponse".equals(localName)) {
+                final Node responseNode = body.getFirstChild();
+                final Node returnNode = responseNode.getFirstChild();
+                final Node intNode = returnNode.getFirstChild();
+
+                final int value = new Integer(intNode.getNodeValue());
+                intNode.setNodeValue(Integer.toString(value * 1000));
+            }
+
+            return true;
+        } catch (SOAPException e) {
+            return false;
+        }
+    }
+
+    public Set<QName> getHeaders() {
+        return Collections.emptySet();
+    }
+
+    public void close(MessageContext mc) {
+    }
+
+    public boolean handleFault(SOAPMessageContext mc) {
+        return true;
+    }
+}

Propchange: openejb/trunk/openejb/examples/webservice-handlers/src/main/java/org/superbiz/calculator/wsh/Inflate.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openejb/trunk/openejb/examples/webservice-handlers/src/main/resources/org/superbiz/calculator/wsh/handlers.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/webservice-handlers/src/main/resources/org/superbiz/calculator/wsh/handlers.xml?rev=1245862&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/webservice-handlers/src/main/resources/org/superbiz/calculator/wsh/handlers.xml (added)
+++ openejb/trunk/openejb/examples/webservice-handlers/src/main/resources/org/superbiz/calculator/wsh/handlers.xml Sat Feb 18 05:15:28 2012
@@ -0,0 +1,33 @@
+<?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: 773519 $ $Date: 2009-05-11 12:08:51 +0200 (Mon, 11 May 2009) $ -->
+
+<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
+  <handler-chain>
+    <handler>
+      <handler-name>org.superbiz.calculator.wsh.Inflate</handler-name>
+      <handler-class>org.superbiz.calculator.wsh.Inflate</handler-class>
+    </handler>
+    <handler>
+      <handler-name>org.superbiz.calculator.wsh.Increment</handler-name>
+      <handler-class>org.superbiz.calculator.wsh.Increment</handler-class>
+    </handler>
+  </handler-chain>
+</handler-chains>

Propchange: openejb/trunk/openejb/examples/webservice-handlers/src/main/resources/org/superbiz/calculator/wsh/handlers.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openejb/trunk/openejb/examples/webservice-handlers/src/test/java/org/superbiz/calculator/wsh/CalculatorTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/webservice-handlers/src/test/java/org/superbiz/calculator/wsh/CalculatorTest.java?rev=1245862&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/webservice-handlers/src/test/java/org/superbiz/calculator/wsh/CalculatorTest.java (added)
+++ openejb/trunk/openejb/examples/webservice-handlers/src/test/java/org/superbiz/calculator/wsh/CalculatorTest.java Sat Feb 18 05:15:28 2012
@@ -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.calculator.wsh;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.ejb.embeddable.EJBContainer;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+import java.net.URL;
+import java.util.Properties;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class CalculatorTest {
+
+    @BeforeClass
+    public static void setUp() throws Exception {
+        Properties properties = new Properties();
+        properties.setProperty("openejb.embedded.remotable", "true");
+        EJBContainer.createEJBContainer(properties);
+    }
+
+    @Test
+    public void testCalculatorViaWsInterface() throws Exception {
+        final Service calculatorService = Service.create(
+                new URL("http://127.0.0.1:4204/Calculator?wsdl"),
+                new QName("http://superbiz.org/wsdl", "CalculatorService"));
+
+        assertNotNull(calculatorService);
+
+        final CalculatorWs calculator = calculatorService.getPort(CalculatorWs.class);
+
+        // we expect our answers to come back 1000 times better, plus one!
+        assertEquals(10001, calculator.sum(4, 6));
+        assertEquals(12001, calculator.multiply(3, 4));
+    }
+}

Propchange: openejb/trunk/openejb/examples/webservice-handlers/src/test/java/org/superbiz/calculator/wsh/CalculatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openejb/trunk/openejb/examples/webservice-handlers/src/test/resources/META-INF/ejb-jar.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/webservice-handlers/src/test/resources/META-INF/ejb-jar.xml?rev=1245862&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/webservice-handlers/src/test/resources/META-INF/ejb-jar.xml (added)
+++ openejb/trunk/openejb/examples/webservice-handlers/src/test/resources/META-INF/ejb-jar.xml Sat Feb 18 05:15:28 2012
@@ -0,0 +1 @@
+<ejb-jar/>
\ No newline at end of file

Propchange: openejb/trunk/openejb/examples/webservice-handlers/src/test/resources/META-INF/ejb-jar.xml
------------------------------------------------------------------------------
    svn:eol-style = native