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 2011/10/29 06:54:42 UTC
svn commit: r1190757 [15/15] - in /openejb/trunk/openejb/examples:
access-timeout-meta/src/main/java/org/superbiz/accesstimeout/
alternate-descriptors/ application-composer/ applicationexception/
applicationexception/src/test/java/org/superbiz/appexcep...
Added: openejb/trunk/openejb/examples/webservice-inheritance/README.md
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/webservice-inheritance/README.md?rev=1190757&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/webservice-inheritance/README.md (added)
+++ openejb/trunk/openejb/examples/webservice-inheritance/README.md Sat Oct 29 04:54:40 2011
@@ -0,0 +1,523 @@
+[INFO] Scanning for projects...
+[INFO]
+[INFO] ------------------------------------------------------------------------
+[INFO] Building OpenEJB :: Examples :: Webservice Inheritance 1.0
+[INFO] ------------------------------------------------------------------------
+[INFO]
+[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ webservice-inheritance ---
+[INFO] Deleting /Users/dblevins/examples/webservice-inheritance/target
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ webservice-inheritance ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] Copying 3 resources
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ webservice-inheritance ---
+[INFO] Compiling 7 source files to /Users/dblevins/examples/webservice-inheritance/target/classes
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ webservice-inheritance ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] Copying 0 resource
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ webservice-inheritance ---
+[INFO] Compiling 1 source file to /Users/dblevins/examples/webservice-inheritance/target/test-classes
+[INFO]
+[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ webservice-inheritance ---
+[INFO] Surefire report directory: /Users/dblevins/examples/webservice-inheritance/target/surefire-reports
+
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+Running org.superbiz.inheritance.InheritanceTest
+Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06
+http://openejb.apache.org/
+INFO - openejb.home = /Users/dblevins/examples/webservice-inheritance
+INFO - openejb.base = /Users/dblevins/examples/webservice-inheritance
+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 - Configuring Service(id=wakeBoardDatabaseUnmanaged, type=Resource, provider-id=Default JDBC Database)
+INFO - Configuring Service(id=wakeBoardDatabase, type=Resource, provider-id=Default JDBC Database)
+INFO - Found EjbModule in classpath: /Users/dblevins/examples/webservice-inheritance/target/classes
+INFO - Beginning load: /Users/dblevins/examples/webservice-inheritance/target/classes
+INFO - Configuring enterprise application: /Users/dblevins/examples/webservice-inheritance/classpath.ear
+INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container)
+INFO - Auto-creating a container for bean WakeRiderImpl: Container(type=STATELESS, id=Default Stateless Container)
+INFO - Configuring PersistenceUnit(name=wakeboard-unit)
+INFO - Enterprise application "/Users/dblevins/examples/webservice-inheritance/classpath.ear" loaded.
+INFO - Assembling app: /Users/dblevins/examples/webservice-inheritance/classpath.ear
+INFO - PersistenceUnit(name=wakeboard-unit, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 412ms
+INFO - Created Ejb(deployment-id=WakeRiderImpl, ejb-name=WakeRiderImpl, container=Default Stateless Container)
+INFO - Started Ejb(deployment-id=WakeRiderImpl, ejb-name=WakeRiderImpl, container=Default Stateless Container)
+INFO - Deployed Application(path=/Users/dblevins/examples/webservice-inheritance/classpath.ear)
+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
+ ** 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!
+WARN - Found no persistent property in "org.superbiz.inheritance.WakeboardBinding"
+WARN - Found no persistent property in "org.superbiz.inheritance.Wakeboard"
+WARN - Found no persistent property in "org.superbiz.inheritance.WakeboardBinding"
+WARN - Found no persistent property in "org.superbiz.inheritance.Wakeboard"
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.46 sec
+
+Results :
+
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
+
+[INFO]
+[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ webservice-inheritance ---
+[INFO] Building jar: /Users/dblevins/examples/webservice-inheritance/target/webservice-inheritance-1.0.jar
+[INFO]
+[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ webservice-inheritance ---
+[INFO] Installing /Users/dblevins/examples/webservice-inheritance/target/webservice-inheritance-1.0.jar to /Users/dblevins/.m2/repository/org/superbiz/webservice-inheritance/1.0/webservice-inheritance-1.0.jar
+[INFO] Installing /Users/dblevins/examples/webservice-inheritance/pom.xml to /Users/dblevins/.m2/repository/org/superbiz/webservice-inheritance/1.0/webservice-inheritance-1.0.pom
+[INFO] ------------------------------------------------------------------------
+[INFO] BUILD SUCCESS
+[INFO] ------------------------------------------------------------------------
+[INFO] Total time: 7.979s
+[INFO] Finished at: Fri Oct 28 17:10:11 PDT 2011
+[INFO] Final Memory: 17M/81M
+[INFO] ------------------------------------------------------------------------
+ /**
+ * 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.inheritance;
+
+ import javax.persistence.Entity;
+ import javax.persistence.GeneratedValue;
+ import javax.persistence.GenerationType;
+ import javax.persistence.Id;
+ import javax.persistence.Inheritance;
+ import javax.persistence.InheritanceType;
+ import java.io.Serializable;
+
+ @Entity
+ @Inheritance(strategy = InheritanceType.JOINED)
+ public class Item implements Serializable {
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long id;
+ private String brand;
+ private String itemName;
+ private double price;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getBrand() {
+ return brand;
+ }
+
+ public void setBrand(String brand) {
+ this.brand = brand;
+ }
+
+ public String getItemName() {
+ return itemName;
+ }
+
+ public void setItemName(String itemName) {
+ this.itemName = itemName;
+ }
+
+ public double getPrice() {
+ return price;
+ }
+
+ public void setPrice(double price) {
+ this.price = price;
+ }
+ }
+ /**
+ * 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.inheritance;
+
+ import javax.persistence.Entity;
+
+ @Entity
+ public class Tower extends Item {
+ private Fit fit;
+ private String tubing;
+
+ public static enum Fit {
+ Custom, Exact, Universal
+ }
+
+ public Fit getFit() {
+ return fit;
+ }
+
+ public void setFit(Fit fit) {
+ this.fit = fit;
+ }
+
+ public String getTubing() {
+ return tubing;
+ }
+
+ public void setTubing(String tubing) {
+ this.tubing = tubing;
+ }
+
+ ;
+ }/**
+ * 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.inheritance;
+
+ import javax.persistence.Entity;
+
+ @Entity
+ public class Wakeboard extends Wearable {
+ }
+ /**
+ * 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.inheritance;
+
+ import javax.persistence.Entity;
+
+ @Entity
+ public class WakeboardBinding extends Wearable {
+ }
+ /**
+ * 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.inheritance;
+
+ import javax.ejb.Stateless;
+ import javax.jws.WebService;
+ import javax.persistence.EntityManager;
+ import javax.persistence.PersistenceContext;
+ import javax.persistence.PersistenceContextType;
+ import javax.persistence.Query;
+ import java.util.List;
+
+ /**
+ * 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 single interface: {@link WakeRiderWs} a webservice interface.
+ */
+ @Stateless
+ @WebService(
+ portName = "InheritancePort",
+ serviceName = "InheritanceWsService",
+ targetNamespace = "http://superbiz.org/wsdl",
+ endpointInterface = "org.superbiz.inheritance.WakeRiderWs")
+ public class WakeRiderImpl implements WakeRiderWs {
+
+ @PersistenceContext(unitName = "wakeboard-unit", type = PersistenceContextType.TRANSACTION)
+ private EntityManager entityManager;
+
+ public void addItem(Item item) throws Exception {
+ entityManager.persist(item);
+ }
+
+ public void deleteMovie(Item item) throws Exception {
+ entityManager.remove(item);
+ }
+
+ public List<Item> getItems() throws Exception {
+ Query query = entityManager.createQuery("SELECT i FROM Item i");
+ List<Item> items = query.getResultList();
+ return items;
+ }
+ }
+ /**
+ * 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.inheritance;
+
+ import javax.jws.WebService;
+ import javax.xml.bind.annotation.XmlSeeAlso;
+ import java.util.List;
+
+ /**
+ * This is an EJB 3 webservice interface that uses inheritance.
+ */
+ @WebService(targetNamespace = "http://superbiz.org/wsdl")
+ @XmlSeeAlso({Wakeboard.class, WakeboardBinding.class, Tower.class})
+ public interface WakeRiderWs {
+ public void addItem(Item item) throws Exception;
+
+ public void deleteMovie(Item item) throws Exception;
+
+ public List<Item> getItems() throws Exception;
+ }
+ /**
+ * 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.inheritance;
+
+ import javax.persistence.MappedSuperclass;
+
+ @MappedSuperclass
+ public abstract class Wearable extends Item {
+ protected String size;
+
+ public String getSize() {
+ return size;
+ }
+
+ public void setSize(String size) {
+ this.size = size;
+ }
+ }
+ /**
+ * 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.inheritance;
+
+ import junit.framework.TestCase;
+ import org.superbiz.inheritance.Tower.Fit;
+
+ import javax.naming.Context;
+ import javax.naming.InitialContext;
+ import javax.xml.namespace.QName;
+ import javax.xml.ws.Service;
+ import java.net.URL;
+ import java.util.List;
+ import java.util.Properties;
+
+ public class InheritanceTest extends TestCase {
+
+ //START SNIPPET: setup
+ private InitialContext initialContext;
+
+ protected void setUp() throws Exception {
+
+ Properties p = new Properties();
+ p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
+ p.put("wakeBoardDatabase", "new://Resource?type=DataSource");
+ p.put("wakeBoardDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
+ p.put("wakeBoardDatabase.JdbcUrl", "jdbc:hsqldb:mem:wakeBoarddb");
+
+ p.put("wakeBoardDatabaseUnmanaged", "new://Resource?type=DataSource");
+ p.put("wakeBoardDatabaseUnmanaged.JdbcDriver", "org.hsqldb.jdbcDriver");
+ p.put("wakeBoardDatabaseUnmanaged.JdbcUrl", "jdbc:hsqldb:mem:wakeBoarddb");
+ p.put("wakeBoardDatabaseUnmanaged.JtaManaged", "false");
+
+ p.put("openejb.embedded.remotable", "true");
+
+ initialContext = new InitialContext(p);
+ }
+ //END SNIPPET: setup
+
+ /**
+ * Create a webservice client using wsdl url
+ *
+ * @throws Exception
+ */
+ //START SNIPPET: webservice
+ public void testInheritanceViaWsInterface() throws Exception {
+ Service service = Service.create(
+ new URL("http://127.0.0.1:4204/WakeRiderImpl?wsdl"),
+ new QName("http://superbiz.org/wsdl", "InheritanceWsService"));
+ assertNotNull(service);
+
+ WakeRiderWs ws = service.getPort(WakeRiderWs.class);
+
+ Tower tower = createTower();
+ Item item = createItem();
+ Wakeboard wakeBoard = createWakeBoard();
+ WakeboardBinding wakeBoardbinding = createWakeboardBinding();
+
+ ws.addItem(tower);
+ ws.addItem(item);
+ ws.addItem(wakeBoard);
+ ws.addItem(wakeBoardbinding);
+
+
+ List<Item> returnedItems = ws.getItems();
+
+ assertEquals("testInheritanceViaWsInterface, nb Items", 4, returnedItems.size());
+
+ //check tower
+ assertEquals("testInheritanceViaWsInterface, first Item", returnedItems.get(0).getClass(), Tower.class);
+ tower = (Tower) returnedItems.get(0);
+ assertEquals("testInheritanceViaWsInterface, first Item", tower.getBrand(), "Tower brand");
+ assertEquals("testInheritanceViaWsInterface, first Item", tower.getFit().ordinal(), Fit.Custom.ordinal());
+ assertEquals("testInheritanceViaWsInterface, first Item", tower.getItemName(), "Tower item name");
+ assertEquals("testInheritanceViaWsInterface, first Item", tower.getPrice(), 1.0d);
+ assertEquals("testInheritanceViaWsInterface, first Item", tower.getTubing(), "Tower tubing");
+
+ //check item
+ assertEquals("testInheritanceViaWsInterface, second Item", returnedItems.get(1).getClass(), Item.class);
+ item = (Item) returnedItems.get(1);
+ assertEquals("testInheritanceViaWsInterface, second Item", item.getBrand(), "Item brand");
+ assertEquals("testInheritanceViaWsInterface, second Item", item.getItemName(), "Item name");
+ assertEquals("testInheritanceViaWsInterface, second Item", item.getPrice(), 2.0d);
+
+ //check wakeboard
+ assertEquals("testInheritanceViaWsInterface, third Item", returnedItems.get(2).getClass(), Wakeboard.class);
+ wakeBoard = (Wakeboard) returnedItems.get(2);
+ assertEquals("testInheritanceViaWsInterface, third Item", wakeBoard.getBrand(), "Wakeboard brand");
+ assertEquals("testInheritanceViaWsInterface, third Item", wakeBoard.getItemName(), "Wakeboard item name");
+ assertEquals("testInheritanceViaWsInterface, third Item", wakeBoard.getPrice(), 3.0d);
+ assertEquals("testInheritanceViaWsInterface, third Item", wakeBoard.getSize(), "WakeBoard size");
+
+ //check wakeboardbinding
+ assertEquals("testInheritanceViaWsInterface, fourth Item", returnedItems.get(3).getClass(), WakeboardBinding.class);
+ wakeBoardbinding = (WakeboardBinding) returnedItems.get(3);
+ assertEquals("testInheritanceViaWsInterface, fourth Item", wakeBoardbinding.getBrand(), "Wakeboardbinding brand");
+ assertEquals("testInheritanceViaWsInterface, fourth Item", wakeBoardbinding.getItemName(), "Wakeboardbinding item name");
+ assertEquals("testInheritanceViaWsInterface, fourth Item", wakeBoardbinding.getPrice(), 4.0d);
+ assertEquals("testInheritanceViaWsInterface, fourth Item", wakeBoardbinding.getSize(), "WakeBoardbinding size");
+ }
+ //END SNIPPET: webservice
+
+ private Tower createTower() {
+ Tower tower = new Tower();
+ tower.setBrand("Tower brand");
+ tower.setFit(Fit.Custom);
+ tower.setItemName("Tower item name");
+ tower.setPrice(1.0f);
+ tower.setTubing("Tower tubing");
+ return tower;
+ }
+
+ private Item createItem() {
+ Item item = new Item();
+ item.setBrand("Item brand");
+ item.setItemName("Item name");
+ item.setPrice(2.0f);
+ return item;
+ }
+
+ private Wakeboard createWakeBoard() {
+ Wakeboard wakeBoard = new Wakeboard();
+ wakeBoard.setBrand("Wakeboard brand");
+ wakeBoard.setItemName("Wakeboard item name");
+ wakeBoard.setPrice(3.0f);
+ wakeBoard.setSize("WakeBoard size");
+ return wakeBoard;
+ }
+
+ private WakeboardBinding createWakeboardBinding() {
+ WakeboardBinding wakeBoardBinding = new WakeboardBinding();
+ wakeBoardBinding.setBrand("Wakeboardbinding brand");
+ wakeBoardBinding.setItemName("Wakeboardbinding item name");
+ wakeBoardBinding.setPrice(4.0f);
+ wakeBoardBinding.setSize("WakeBoardbinding size");
+ return wakeBoardBinding;
+ }
+ }
Added: openejb/trunk/openejb/examples/webservice-security/README.md
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/webservice-security/README.md?rev=1190757&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/webservice-security/README.md (added)
+++ openejb/trunk/openejb/examples/webservice-security/README.md Sat Oct 29 04:54:40 2011
@@ -0,0 +1,260 @@
+[INFO] Scanning for projects...
+[INFO]
+[INFO] ------------------------------------------------------------------------
+[INFO] Building OpenEJB :: Web Examples :: EJB WebService with Security 1.0
+[INFO] ------------------------------------------------------------------------
+[INFO]
+[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ webservice-security ---
+[INFO] Deleting /Users/dblevins/examples/webservice-security/target
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ webservice-security ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] Copying 3 resources
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ webservice-security ---
+[INFO] Compiling 3 source files to /Users/dblevins/examples/webservice-security/target/classes
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ webservice-security ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] Copying 2 resources
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ webservice-security ---
+[INFO] Compiling 1 source file to /Users/dblevins/examples/webservice-security/target/test-classes
+[INFO]
+[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ webservice-security ---
+[INFO] Surefire report directory: /Users/dblevins/examples/webservice-security/target/surefire-reports
+
+-------------------------------------------------------
+ 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/webservice-security
+INFO - openejb.base = /Users/dblevins/examples/webservice-security
+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/webservice-security/target/classes
+INFO - Beginning load: /Users/dblevins/examples/webservice-security/target/classes
+INFO - Configuring enterprise application: /Users/dblevins/examples/webservice-security/classpath.ear
+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/webservice-security/classpath.ear" loaded.
+INFO - Assembling app: /Users/dblevins/examples/webservice-security/classpath.ear
+INFO - Jndi(name=CalculatorImplRemote) --> Ejb(deployment-id=CalculatorImpl)
+INFO - Jndi(name=global/classpath.ear/webservice-security/CalculatorImpl!org.superbiz.calculator.CalculatorRemote) --> Ejb(deployment-id=CalculatorImpl)
+INFO - Jndi(name=global/classpath.ear/webservice-security/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 - Deployed Application(path=/Users/dblevins/examples/webservice-security/classpath.ear)
+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
+ ** 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: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.415 sec
+
+Results :
+
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
+
+[INFO]
+[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ webservice-security ---
+[INFO] Building jar: /Users/dblevins/examples/webservice-security/target/webservice-security-1.0.jar
+[INFO]
+[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ webservice-security ---
+[INFO] Installing /Users/dblevins/examples/webservice-security/target/webservice-security-1.0.jar to /Users/dblevins/.m2/repository/org/superbiz/webservice-security/1.0/webservice-security-1.0.jar
+[INFO] Installing /Users/dblevins/examples/webservice-security/pom.xml to /Users/dblevins/.m2/repository/org/superbiz/webservice-security/1.0/webservice-security-1.0.pom
+[INFO] ------------------------------------------------------------------------
+[INFO] BUILD SUCCESS
+[INFO] ------------------------------------------------------------------------
+[INFO] Total time: 7.169s
+[INFO] Finished at: Fri Oct 28 17:08:39 PDT 2011
+[INFO] Final Memory: 17M/81M
+[INFO] ------------------------------------------------------------------------
+ /**
+ * 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;
+
+ import javax.annotation.security.DeclareRoles;
+ import javax.annotation.security.RolesAllowed;
+ import javax.ejb.Stateless;
+ import javax.jws.WebService;
+
+ /**
+ * 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 single interface: CalculatorWs a webservice interface.
+ */
+ //START SNIPPET: code
+ @DeclareRoles(value = {"Administrator"})
+ @Stateless
+ @WebService(
+ portName = "CalculatorPort",
+ serviceName = "CalculatorWsService",
+ targetNamespace = "http://superbiz.org/wsdl",
+ endpointInterface = "org.superbiz.calculator.CalculatorWs")
+ public class CalculatorImpl implements CalculatorWs, CalculatorRemote {
+
+ @RolesAllowed(value = {"Administrator"})
+ public int sum(int add1, int add2) {
+ return add1 + add2;
+ }
+
+ @RolesAllowed(value = {"Administrator"})
+ public int multiply(int mul1, int mul2) {
+ return mul1 * mul2;
+ }
+
+ }
+ //END SNIPPET: code/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * 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;
+
+ import javax.ejb.Remote;
+
+ @Remote
+ public interface CalculatorRemote {
+
+ public int sum(int add1, int add2);
+
+ public int multiply(int mul1, int mul2);
+
+ }
+ /**
+ * 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;
+
+ import javax.jws.WebService;
+
+ //END SNIPPET: code
+
+ /**
+ * This is an EJB 3 webservice interface
+ * A webservice interface must be annotated with the @Local
+ * annotation.
+ */
+ //START SNIPPET: code
+ @WebService(targetNamespace = "http://superbiz.org/wsdl")
+ public interface CalculatorWs {
+
+ public int sum(int add1, int add2);
+
+ public int multiply(int mul1, int mul2);
+ }
+ //END SNIPPET: code/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * 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;
+
+ import junit.framework.TestCase;
+
+ import javax.naming.Context;
+ import javax.naming.InitialContext;
+ import javax.xml.namespace.QName;
+ import javax.xml.ws.BindingProvider;
+ import javax.xml.ws.Service;
+ import java.net.URL;
+ import java.util.Properties;
+
+ public class CalculatorTest extends TestCase {
+
+ //START SNIPPET: setup
+ private InitialContext initialContext;
+
+ protected void setUp() throws Exception {
+ Properties properties = new Properties();
+ properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
+ properties.setProperty("openejb.embedded.remotable", "true");
+
+ initialContext = new InitialContext(properties);
+ }
+ //END SNIPPET: setup
+
+ /**
+ * Create a webservice client using wsdl url
+ *
+ * @throws Exception
+ */
+ //START SNIPPET: webservice
+ public void testCalculatorViaWsInterface() throws Exception {
+ URL url = new URL("http://127.0.0.1:4204/CalculatorImpl?wsdl");
+ QName calcServiceQName = new QName("http://superbiz.org/wsdl", "CalculatorWsService");
+ Service calcService = Service.create(url, calcServiceQName);
+ assertNotNull(calcService);
+
+ CalculatorWs calc = calcService.getPort(CalculatorWs.class);
+ ((BindingProvider) calc).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "jane");
+ ((BindingProvider) calc).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "waterfall");
+ assertEquals(10, calc.sum(4, 6));
+ assertEquals(12, calc.multiply(3, 4));
+ }
+ //END SNIPPET: webservice
+
+ }
Added: openejb/trunk/openejb/examples/webservice-ws-security/README.md
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/webservice-ws-security/README.md?rev=1190757&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/webservice-ws-security/README.md (added)
+++ openejb/trunk/openejb/examples/webservice-ws-security/README.md Sat Oct 29 04:54:40 2011
@@ -0,0 +1,614 @@
+[INFO] Scanning for projects...
+[INFO]
+[INFO] ------------------------------------------------------------------------
+[INFO] Building OpenEJB :: Web Examples :: EJB WebService with WS-Security 1.0
+[INFO] ------------------------------------------------------------------------
+[INFO]
+[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ webservice-ws-security ---
+[INFO] Deleting /Users/dblevins/examples/webservice-ws-security/target
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ webservice-ws-security ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] Copying 6 resources
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ webservice-ws-security ---
+[INFO] Compiling 3 source files to /Users/dblevins/examples/webservice-ws-security/target/classes
+[INFO]
+[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ webservice-ws-security ---
+[INFO] Using 'UTF-8' encoding to copy filtered resources.
+[INFO] Copying 4 resources
+[INFO]
+[INFO] --- maven-antrun-plugin:1.5:run (generate-keys) @ webservice-ws-security ---
+[INFO] Executing tasks
+
+generate keys:
+
+do.sun.jdk:
+ [echo] *** Running on a Sun JDK ***
+ [echo] generate server keys
+ [java] Certificate stored in file </Users/dblevins/examples/webservice-ws-security/target/classes/META-INF/serverKey.rsa>
+ [echo] generate client keys
+ [java] Certificate stored in file </Users/dblevins/examples/webservice-ws-security/target/test-classes/META-INF/clientKey.rsa>
+ [echo] import client/server public keys in client/server keystores
+ [java] Certificate was added to keystore
+ [java] Certificate was added to keystore
+
+do.ibm.jdk:
+
+run:
+ [echo] Running JDK specific keystore creation target
+[INFO] Executed tasks
+[INFO]
+[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ webservice-ws-security ---
+[INFO] Compiling 2 source files to /Users/dblevins/examples/webservice-ws-security/target/test-classes
+[INFO]
+[INFO] --- maven-surefire-plugin:2.6:test (default-test) @ webservice-ws-security ---
+[INFO] Surefire report directory: /Users/dblevins/examples/webservice-ws-security/target/surefire-reports
+
+-------------------------------------------------------
+ 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/webservice-ws-security
+INFO - openejb.base = /Users/dblevins/examples/webservice-ws-security
+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/webservice-ws-security/target/classes
+INFO - Beginning load: /Users/dblevins/examples/webservice-ws-security/target/classes
+INFO - Configuring enterprise application: /Users/dblevins/examples/webservice-ws-security/classpath.ear
+INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container)
+INFO - Auto-creating a container for bean CalculatorImplTimestamp1way: Container(type=STATELESS, id=Default Stateless Container)
+INFO - Enterprise application "/Users/dblevins/examples/webservice-ws-security/classpath.ear" loaded.
+INFO - Assembling app: /Users/dblevins/examples/webservice-ws-security/classpath.ear
+INFO - Jndi(name=CalculatorImplTimestamp1wayRemote) --> Ejb(deployment-id=CalculatorImplTimestamp1way)
+INFO - Jndi(name=global/classpath.ear/simple/CalculatorImplTimestamp1way!org.superbiz.calculator.CalculatorRemote) --> Ejb(deployment-id=CalculatorImplTimestamp1way)
+INFO - Jndi(name=global/classpath.ear/simple/CalculatorImplTimestamp1way) --> Ejb(deployment-id=CalculatorImplTimestamp1way)
+INFO - Jndi(name=CalculatorImplTimestamp2waysRemote) --> Ejb(deployment-id=CalculatorImplTimestamp2ways)
+INFO - Jndi(name=global/classpath.ear/simple/CalculatorImplTimestamp2ways!org.superbiz.calculator.CalculatorRemote) --> Ejb(deployment-id=CalculatorImplTimestamp2ways)
+INFO - Jndi(name=global/classpath.ear/simple/CalculatorImplTimestamp2ways) --> Ejb(deployment-id=CalculatorImplTimestamp2ways)
+INFO - Jndi(name=CalculatorImplUsernameTokenPlainPasswordRemote) --> Ejb(deployment-id=CalculatorImplUsernameTokenPlainPassword)
+INFO - Jndi(name=global/classpath.ear/simple/CalculatorImplUsernameTokenPlainPassword!org.superbiz.calculator.CalculatorRemote) --> Ejb(deployment-id=CalculatorImplUsernameTokenPlainPassword)
+INFO - Jndi(name=global/classpath.ear/simple/CalculatorImplUsernameTokenPlainPassword) --> Ejb(deployment-id=CalculatorImplUsernameTokenPlainPassword)
+INFO - Jndi(name=CalculatorImplUsernameTokenHashedPasswordRemote) --> Ejb(deployment-id=CalculatorImplUsernameTokenHashedPassword)
+INFO - Jndi(name=global/classpath.ear/simple/CalculatorImplUsernameTokenHashedPassword!org.superbiz.calculator.CalculatorRemote) --> Ejb(deployment-id=CalculatorImplUsernameTokenHashedPassword)
+INFO - Jndi(name=global/classpath.ear/simple/CalculatorImplUsernameTokenHashedPassword) --> Ejb(deployment-id=CalculatorImplUsernameTokenHashedPassword)
+INFO - Jndi(name=CalculatorImplUsernameTokenPlainPasswordEncryptRemote) --> Ejb(deployment-id=CalculatorImplUsernameTokenPlainPasswordEncrypt)
+INFO - Jndi(name=global/classpath.ear/simple/CalculatorImplUsernameTokenPlainPasswordEncrypt!org.superbiz.calculator.CalculatorRemote) --> Ejb(deployment-id=CalculatorImplUsernameTokenPlainPasswordEncrypt)
+INFO - Jndi(name=global/classpath.ear/simple/CalculatorImplUsernameTokenPlainPasswordEncrypt) --> Ejb(deployment-id=CalculatorImplUsernameTokenPlainPasswordEncrypt)
+INFO - Jndi(name=CalculatorImplSignRemote) --> Ejb(deployment-id=CalculatorImplSign)
+INFO - Jndi(name=global/classpath.ear/simple/CalculatorImplSign!org.superbiz.calculator.CalculatorRemote) --> Ejb(deployment-id=CalculatorImplSign)
+INFO - Jndi(name=global/classpath.ear/simple/CalculatorImplSign) --> Ejb(deployment-id=CalculatorImplSign)
+INFO - Jndi(name=CalculatorImplEncrypt2waysRemote) --> Ejb(deployment-id=CalculatorImplEncrypt2ways)
+INFO - Jndi(name=global/classpath.ear/simple/CalculatorImplEncrypt2ways!org.superbiz.calculator.CalculatorRemote) --> Ejb(deployment-id=CalculatorImplEncrypt2ways)
+INFO - Jndi(name=global/classpath.ear/simple/CalculatorImplEncrypt2ways) --> Ejb(deployment-id=CalculatorImplEncrypt2ways)
+INFO - Jndi(name=CalculatorImplSign2waysRemote) --> Ejb(deployment-id=CalculatorImplSign2ways)
+INFO - Jndi(name=global/classpath.ear/simple/CalculatorImplSign2ways!org.superbiz.calculator.CalculatorRemote) --> Ejb(deployment-id=CalculatorImplSign2ways)
+INFO - Jndi(name=global/classpath.ear/simple/CalculatorImplSign2ways) --> Ejb(deployment-id=CalculatorImplSign2ways)
+INFO - Jndi(name=CalculatorImplEncryptAndSign2waysRemote) --> Ejb(deployment-id=CalculatorImplEncryptAndSign2ways)
+INFO - Jndi(name=global/classpath.ear/simple/CalculatorImplEncryptAndSign2ways!org.superbiz.calculator.CalculatorRemote) --> Ejb(deployment-id=CalculatorImplEncryptAndSign2ways)
+INFO - Jndi(name=global/classpath.ear/simple/CalculatorImplEncryptAndSign2ways) --> Ejb(deployment-id=CalculatorImplEncryptAndSign2ways)
+INFO - Jndi(name=CalculatorImplRemote) --> Ejb(deployment-id=CalculatorImpl)
+INFO - Jndi(name=global/classpath.ear/simple/CalculatorImpl!org.superbiz.calculator.CalculatorRemote) --> Ejb(deployment-id=CalculatorImpl)
+INFO - Jndi(name=global/classpath.ear/simple/CalculatorImpl) --> Ejb(deployment-id=CalculatorImpl)
+INFO - Created Ejb(deployment-id=CalculatorImplUsernameTokenHashedPassword, ejb-name=CalculatorImplUsernameTokenHashedPassword, container=Default Stateless Container)
+INFO - Created Ejb(deployment-id=CalculatorImpl, ejb-name=CalculatorImpl, container=Default Stateless Container)
+INFO - Created Ejb(deployment-id=CalculatorImplSign, ejb-name=CalculatorImplSign, container=Default Stateless Container)
+INFO - Created Ejb(deployment-id=CalculatorImplEncryptAndSign2ways, ejb-name=CalculatorImplEncryptAndSign2ways, container=Default Stateless Container)
+INFO - Created Ejb(deployment-id=CalculatorImplTimestamp1way, ejb-name=CalculatorImplTimestamp1way, container=Default Stateless Container)
+INFO - Created Ejb(deployment-id=CalculatorImplSign2ways, ejb-name=CalculatorImplSign2ways, container=Default Stateless Container)
+INFO - Created Ejb(deployment-id=CalculatorImplEncrypt2ways, ejb-name=CalculatorImplEncrypt2ways, container=Default Stateless Container)
+INFO - Created Ejb(deployment-id=CalculatorImplUsernameTokenPlainPassword, ejb-name=CalculatorImplUsernameTokenPlainPassword, container=Default Stateless Container)
+INFO - Created Ejb(deployment-id=CalculatorImplTimestamp2ways, ejb-name=CalculatorImplTimestamp2ways, container=Default Stateless Container)
+INFO - Created Ejb(deployment-id=CalculatorImplUsernameTokenPlainPasswordEncrypt, ejb-name=CalculatorImplUsernameTokenPlainPasswordEncrypt, container=Default Stateless Container)
+INFO - Started Ejb(deployment-id=CalculatorImplUsernameTokenHashedPassword, ejb-name=CalculatorImplUsernameTokenHashedPassword, container=Default Stateless Container)
+INFO - Started Ejb(deployment-id=CalculatorImpl, ejb-name=CalculatorImpl, container=Default Stateless Container)
+INFO - Started Ejb(deployment-id=CalculatorImplSign, ejb-name=CalculatorImplSign, container=Default Stateless Container)
+INFO - Started Ejb(deployment-id=CalculatorImplEncryptAndSign2ways, ejb-name=CalculatorImplEncryptAndSign2ways, container=Default Stateless Container)
+INFO - Started Ejb(deployment-id=CalculatorImplTimestamp1way, ejb-name=CalculatorImplTimestamp1way, container=Default Stateless Container)
+INFO - Started Ejb(deployment-id=CalculatorImplSign2ways, ejb-name=CalculatorImplSign2ways, container=Default Stateless Container)
+INFO - Started Ejb(deployment-id=CalculatorImplEncrypt2ways, ejb-name=CalculatorImplEncrypt2ways, container=Default Stateless Container)
+INFO - Started Ejb(deployment-id=CalculatorImplUsernameTokenPlainPassword, ejb-name=CalculatorImplUsernameTokenPlainPassword, container=Default Stateless Container)
+INFO - Started Ejb(deployment-id=CalculatorImplTimestamp2ways, ejb-name=CalculatorImplTimestamp2ways, container=Default Stateless Container)
+INFO - Started Ejb(deployment-id=CalculatorImplUsernameTokenPlainPasswordEncrypt, ejb-name=CalculatorImplUsernameTokenPlainPasswordEncrypt, container=Default Stateless Container)
+INFO - Deployed Application(path=/Users/dblevins/examples/webservice-ws-security/classpath.ear)
+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
+ ** 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: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.65 sec
+
+Results :
+
+Tests run: 7, Failures: 0, Errors: 0, Skipped: 0
+
+[INFO]
+[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ webservice-ws-security ---
+[INFO] Building jar: /Users/dblevins/examples/webservice-ws-security/target/webservice-ws-security-1.0.jar
+[INFO]
+[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ webservice-ws-security ---
+[INFO] Installing /Users/dblevins/examples/webservice-ws-security/target/webservice-ws-security-1.0.jar to /Users/dblevins/.m2/repository/org/superbiz/webservice-ws-security/1.0/webservice-ws-security-1.0.jar
+[INFO] Installing /Users/dblevins/examples/webservice-ws-security/pom.xml to /Users/dblevins/.m2/repository/org/superbiz/webservice-ws-security/1.0/webservice-ws-security-1.0.pom
+[INFO] ------------------------------------------------------------------------
+[INFO] BUILD SUCCESS
+[INFO] ------------------------------------------------------------------------
+[INFO] Total time: 14.451s
+[INFO] Finished at: Fri Oct 28 17:00:57 PDT 2011
+[INFO] Final Memory: 18M/81M
+[INFO] ------------------------------------------------------------------------
+ /**
+ * 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;
+
+ import javax.annotation.security.DeclareRoles;
+ import javax.annotation.security.RolesAllowed;
+ import javax.ejb.Stateless;
+ import javax.jws.WebService;
+
+ /**
+ * 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 single interface: CalculatorWs a webservice interface.
+ */
+ //START SNIPPET: code
+ @DeclareRoles(value = {"Administrator"})
+ @Stateless
+ @WebService(
+ portName = "CalculatorPort",
+ serviceName = "CalculatorWsService",
+ targetNamespace = "http://superbiz.org/wsdl",
+ endpointInterface = "org.superbiz.calculator.CalculatorWs")
+ public class CalculatorImpl implements CalculatorWs, CalculatorRemote {
+
+ @RolesAllowed(value = {"Administrator"})
+ public int sum(int add1, int add2) {
+ return add1 + add2;
+ }
+
+ public int multiply(int mul1, int mul2) {
+ return mul1 * mul2;
+ }
+
+ }
+ //END SNIPPET: code
+ /**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * 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;
+
+ import javax.ejb.Remote;
+
+ @Remote
+ public interface CalculatorRemote {
+
+ public int sum(int add1, int add2);
+
+ public int multiply(int mul1, int mul2);
+
+ }
+ /**
+ * 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;
+
+ import javax.jws.WebService;
+
+ //END SNIPPET: code
+
+ /**
+ * This is an EJB 3 webservice interface
+ * A webservice interface must be annotated with the @Local
+ * annotation.
+ */
+ //START SNIPPET: code
+ @WebService(targetNamespace = "http://superbiz.org/wsdl")
+ public interface CalculatorWs {
+
+ public int sum(int add1, int add2);
+
+ public int multiply(int mul1, int mul2);
+ }
+ //END SNIPPET: code/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * 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;
+
+ import junit.framework.TestCase;
+ import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor;
+ import org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor;
+ import org.apache.cxf.endpoint.Client;
+ import org.apache.cxf.endpoint.Endpoint;
+ import org.apache.cxf.frontend.ClientProxy;
+ import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
+ import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
+ import org.apache.ws.security.WSConstants;
+ import org.apache.ws.security.WSPasswordCallback;
+ import org.apache.ws.security.handler.WSHandlerConstants;
+
+ import javax.naming.Context;
+ import javax.naming.InitialContext;
+ import javax.security.auth.callback.Callback;
+ import javax.security.auth.callback.CallbackHandler;
+ import javax.security.auth.callback.UnsupportedCallbackException;
+ import javax.xml.namespace.QName;
+ import javax.xml.ws.Service;
+ import javax.xml.ws.soap.SOAPBinding;
+ import java.io.IOException;
+ import java.net.URL;
+ import java.util.HashMap;
+ import java.util.Map;
+ import java.util.Properties;
+
+ public class CalculatorTest extends TestCase {
+
+ //START SNIPPET: setup
+ protected void setUp() throws Exception {
+ Properties properties = new Properties();
+ properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
+ properties.setProperty("openejb.embedded.remotable", "true");
+
+ new InitialContext(properties);
+ }
+ //END SNIPPET: setup
+
+ //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);
+
+ Client client = ClientProxy.getClient(calc);
+ Endpoint endpoint = client.getEndpoint();
+ endpoint.getOutInterceptors().add(new SAAJOutInterceptor());
+
+ Map<String, Object> outProps = new HashMap<String, Object>();
+ outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
+ outProps.put(WSHandlerConstants.USER, "jane");
+ outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
+ outProps.put(WSHandlerConstants.PW_CALLBACK_REF, new CallbackHandler() {
+
+ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
+ WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
+ pc.setPassword("waterfall");
+ }
+ });
+
+ WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
+ endpoint.getOutInterceptors().add(wssOut);
+
+ assertEquals(10, calc.sum(4, 6));
+ }
+
+ public void testCalculatorViaWsInterfaceWithTimestamp1way() throws Exception {
+ Service calcService = Service.create(new URL("http://127.0.0.1:4204/CalculatorImplTimestamp1way?wsdl"),
+ new QName("http://superbiz.org/wsdl", "CalculatorWsService"));
+ assertNotNull(calcService);
+
+ // for debugging (ie. TCPMon)
+ calcService.addPort(new QName("http://superbiz.org/wsdl",
+ "CalculatorWsService2"), SOAPBinding.SOAP12HTTP_BINDING,
+ "http://127.0.0.1:8204/CalculatorImplTimestamp1way");
+
+ // CalculatorWs calc = calcService.getPort(
+ // new QName("http://superbiz.org/wsdl", "CalculatorWsService2"),
+ // CalculatorWs.class);
+
+ CalculatorWs calc = calcService.getPort(CalculatorWs.class);
+
+ Client client = ClientProxy.getClient(calc);
+ Endpoint endpoint = client.getEndpoint();
+ endpoint.getOutInterceptors().add(new SAAJOutInterceptor());
+
+ Map<String, Object> outProps = new HashMap<String, Object>();
+ outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.TIMESTAMP);
+ WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
+ endpoint.getOutInterceptors().add(wssOut);
+
+ assertEquals(12, calc.multiply(3, 4));
+ }
+
+ public void testCalculatorViaWsInterfaceWithTimestamp2ways() throws Exception {
+ Service calcService = Service.create(new URL("http://127.0.0.1:4204/CalculatorImplTimestamp2ways?wsdl"),
+ new QName("http://superbiz.org/wsdl", "CalculatorWsService"));
+ assertNotNull(calcService);
+
+ // for debugging (ie. TCPMon)
+ calcService.addPort(new QName("http://superbiz.org/wsdl",
+ "CalculatorWsService2"), SOAPBinding.SOAP12HTTP_BINDING,
+ "http://127.0.0.1:8204/CalculatorImplTimestamp2ways");
+
+ // CalculatorWs calc = calcService.getPort(
+ // new QName("http://superbiz.org/wsdl", "CalculatorWsService2"),
+ // CalculatorWs.class);
+
+ CalculatorWs calc = calcService.getPort(CalculatorWs.class);
+
+ Client client = ClientProxy.getClient(calc);
+ Endpoint endpoint = client.getEndpoint();
+ endpoint.getOutInterceptors().add(new SAAJOutInterceptor());
+ endpoint.getInInterceptors().add(new SAAJInInterceptor());
+
+ Map<String, Object> outProps = new HashMap<String, Object>();
+ outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.TIMESTAMP);
+ WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
+ endpoint.getOutInterceptors().add(wssOut);
+
+ Map<String, Object> inProps = new HashMap<String, Object>();
+ inProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.TIMESTAMP);
+ WSS4JInInterceptor wssIn = new WSS4JInInterceptor(inProps);
+ endpoint.getInInterceptors().add(wssIn);
+
+ assertEquals(12, calc.multiply(3, 4));
+ }
+
+ public void testCalculatorViaWsInterfaceWithUsernameTokenPlainPassword() throws Exception {
+ Service calcService = Service.create(new URL("http://127.0.0.1:4204/CalculatorImplUsernameTokenPlainPassword?wsdl"),
+ new QName("http://superbiz.org/wsdl", "CalculatorWsService"));
+ assertNotNull(calcService);
+
+ // for debugging (ie. TCPMon)
+ calcService.addPort(new QName("http://superbiz.org/wsdl",
+ "CalculatorWsService2"), SOAPBinding.SOAP12HTTP_BINDING,
+ "http://127.0.0.1:8204/CalculatorImplUsernameTokenPlainPassword");
+
+ // CalculatorWs calc = calcService.getPort(
+ // new QName("http://superbiz.org/wsdl", "CalculatorWsService2"),
+ // CalculatorWs.class);
+
+ CalculatorWs calc = calcService.getPort(CalculatorWs.class);
+
+ Client client = ClientProxy.getClient(calc);
+ Endpoint endpoint = client.getEndpoint();
+ endpoint.getOutInterceptors().add(new SAAJOutInterceptor());
+
+ Map<String, Object> outProps = new HashMap<String, Object>();
+ outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
+ outProps.put(WSHandlerConstants.USER, "jane");
+ outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
+ outProps.put(WSHandlerConstants.PW_CALLBACK_REF, new CallbackHandler() {
+
+ @Override
+ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
+ WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
+ pc.setPassword("waterfall");
+ }
+ });
+
+ WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
+ endpoint.getOutInterceptors().add(wssOut);
+
+ assertEquals(10, calc.sum(4, 6));
+ }
+
+ public void testCalculatorViaWsInterfaceWithUsernameTokenHashedPassword() throws Exception {
+ Service calcService = Service.create(new URL("http://127.0.0.1:4204/CalculatorImplUsernameTokenHashedPassword?wsdl"),
+ new QName("http://superbiz.org/wsdl", "CalculatorWsService"));
+ assertNotNull(calcService);
+
+ // for debugging (ie. TCPMon)
+ calcService.addPort(new QName("http://superbiz.org/wsdl",
+ "CalculatorWsService2"), SOAPBinding.SOAP12HTTP_BINDING,
+ "http://127.0.0.1:8204/CalculatorImplUsernameTokenHashedPassword");
+
+ // CalculatorWs calc = calcService.getPort(
+ // new QName("http://superbiz.org/wsdl", "CalculatorWsService2"),
+ // CalculatorWs.class);
+
+ CalculatorWs calc = calcService.getPort(CalculatorWs.class);
+
+ Client client = ClientProxy.getClient(calc);
+ Endpoint endpoint = client.getEndpoint();
+ endpoint.getOutInterceptors().add(new SAAJOutInterceptor());
+
+ Map<String, Object> outProps = new HashMap<String, Object>();
+ outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
+ outProps.put(WSHandlerConstants.USER, "jane");
+ outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
+ outProps.put(WSHandlerConstants.PW_CALLBACK_REF, new CallbackHandler() {
+
+ @Override
+ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
+ WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
+ pc.setPassword("waterfall");
+ }
+ });
+
+ WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
+ endpoint.getOutInterceptors().add(wssOut);
+
+ assertEquals(10, calc.sum(4, 6));
+ }
+
+ public void testCalculatorViaWsInterfaceWithUsernameTokenPlainPasswordEncrypt() throws Exception {
+ Service calcService = Service.create(new URL("http://127.0.0.1:4204/CalculatorImplUsernameTokenPlainPasswordEncrypt?wsdl"),
+ new QName("http://superbiz.org/wsdl", "CalculatorWsService"));
+ assertNotNull(calcService);
+
+ // for debugging (ie. TCPMon)
+ calcService.addPort(new QName("http://superbiz.org/wsdl",
+ "CalculatorWsService2"), SOAPBinding.SOAP12HTTP_BINDING,
+ "http://127.0.0.1:8204/CalculatorImplUsernameTokenPlainPasswordEncrypt");
+
+ // CalculatorWs calc = calcService.getPort(
+ // new QName("http://superbiz.org/wsdl", "CalculatorWsService2"),
+ // CalculatorWs.class);
+
+ CalculatorWs calc = calcService.getPort(CalculatorWs.class);
+
+ Client client = ClientProxy.getClient(calc);
+ Endpoint endpoint = client.getEndpoint();
+ endpoint.getOutInterceptors().add(new SAAJOutInterceptor());
+
+ Map<String, Object> outProps = new HashMap<String, Object>();
+ outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN
+ + " " + WSHandlerConstants.ENCRYPT);
+ outProps.put(WSHandlerConstants.USER, "jane");
+ outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
+ outProps.put(WSHandlerConstants.PW_CALLBACK_REF, new CallbackHandler() {
+
+ @Override
+ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
+ WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
+ pc.setPassword("waterfall");
+ }
+ });
+ outProps.put(WSHandlerConstants.ENC_PROP_FILE, "META-INF/CalculatorImplUsernameTokenPlainPasswordEncrypt-client.properties");
+ outProps.put(WSHandlerConstants.ENCRYPTION_USER, "serveralias");
+
+ WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
+ endpoint.getOutInterceptors().add(wssOut);
+
+ assertEquals(10, calc.sum(4, 6));
+ }
+
+ public void testCalculatorViaWsInterfaceWithSign() throws Exception {
+ Service calcService = Service.create(new URL("http://127.0.0.1:4204/CalculatorImplSign?wsdl"),
+ new QName("http://superbiz.org/wsdl", "CalculatorWsService"));
+ assertNotNull(calcService);
+
+ // for debugging (ie. TCPMon)
+ calcService.addPort(new QName("http://superbiz.org/wsdl",
+ "CalculatorWsService2"), SOAPBinding.SOAP12HTTP_BINDING,
+ "http://127.0.0.1:8204/CalculatorImplSign");
+
+ // CalculatorWs calc = calcService.getPort(
+ // new QName("http://superbiz.org/wsdl", "CalculatorWsService2"),
+ // CalculatorWs.class);
+
+ CalculatorWs calc = calcService.getPort(CalculatorWs.class);
+
+ Client client = ClientProxy.getClient(calc);
+ Endpoint endpoint = client.getEndpoint();
+ endpoint.getOutInterceptors().add(new SAAJOutInterceptor());
+
+ Map<String, Object> outProps = new HashMap<String, Object>();
+ outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.SIGNATURE);
+ outProps.put(WSHandlerConstants.USER, "clientalias");
+ outProps.put(WSHandlerConstants.PW_CALLBACK_REF, new CallbackHandler() {
+
+ @Override
+ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
+ WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
+ pc.setPassword("clientPassword");
+ }
+ });
+ outProps.put(WSHandlerConstants.SIG_PROP_FILE, "META-INF/CalculatorImplSign-client.properties");
+ outProps.put(WSHandlerConstants.SIG_KEY_ID, "IssuerSerial");
+
+ WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
+ endpoint.getOutInterceptors().add(wssOut);
+
+ assertEquals(24, calc.multiply(4, 6));
+ }
+ //END SNIPPET: webservice
+ }
+ /**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * 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;
+
+ import org.apache.ws.security.WSPasswordCallback;
+
+ import javax.security.auth.callback.Callback;
+ import javax.security.auth.callback.CallbackHandler;
+ import javax.security.auth.callback.UnsupportedCallbackException;
+ import java.io.IOException;
+
+ public class CustomPasswordHandler implements CallbackHandler {
+ @Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
+ WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
+
+ if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN) {
+ // TODO get the password from the users.properties if possible
+ pc.setPassword("waterfall");
+
+ } else if (pc.getUsage() == WSPasswordCallback.DECRYPT) {
+ pc.setPassword("serverPassword");
+
+ } else if (pc.getUsage() == WSPasswordCallback.SIGNATURE) {
+ pc.setPassword("serverPassword");
+
+ }
+ }
+ }