You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by bu...@apache.org on 2012/02/18 03:43:15 UTC
svn commit: r805232 - in /websites/staging/openejb/trunk: ./
content/examples-trunk/simple-webservice/
content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/
content/examples-trunk/simple-webservice/src/main/java/org/superbiz/c...
Author: buildbot
Date: Sat Feb 18 02:43:14 2012
New Revision: 805232
Log:
Staging update by buildbot for openejb
Added:
websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/ws/
websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorImpl.java
websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorLocal.java
websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorWs.java
websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/ws/handler/
websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/ws/handler/DummyInterceptor.java
websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/resources/org/superbiz/calculator/ws/
websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/resources/org/superbiz/calculator/ws/handler.xml
websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/test/java/org/superbiz/calculator/ws/
websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/test/java/org/superbiz/calculator/ws/CalculatorTest.java
Removed:
websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/CalculatorImpl.java
websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/CalculatorLocal.java
websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/CalculatorWs.java
websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/handler/
websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/resources/META-INF/
websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/resources/org/superbiz/calculator/handler.xml
websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/test/java/org/superbiz/calculator/CalculatorTest.java
Modified:
websites/staging/openejb/trunk/ (props changed)
websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/README.html
Propchange: websites/staging/openejb/trunk/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Sat Feb 18 02:43:14 2012
@@ -1 +1 @@
-1245808
+1245850
Modified: websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/README.html
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/README.html (original)
+++ websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/README.html Sat Feb 18 02:43:14 2012
@@ -453,6 +453,7 @@ Tests run: 3, Failures: 0, Errors: 0, Sk
<h4>APIs Used</h4>
<ul><li><a href="http://docs.oracle.com/javaee/6/api/javax/ejb/Local.html">javax.ejb.Local</a></li>
<li><a href="http://docs.oracle.com/javaee/6/api/javax/ejb/Stateless.html">javax.ejb.Stateless</a></li>
+<li><a href="http://docs.oracle.com/javaee/6/api/javax/ejb/embeddable/EJBContainer.html">javax.ejb.embeddable.EJBContainer</a></li>
<li><a href="http://docs.oracle.com/javaee/6/api/javax/jws/HandlerChain.html">javax.jws.HandlerChain</a></li>
<li><a href="http://docs.oracle.com/javaee/6/api/javax/jws/WebParam.html">javax.jws.WebParam</a></li>
<li><a href="http://docs.oracle.com/javaee/6/api/javax/jws/WebService.html">javax.jws.WebService</a></li>
@@ -461,7 +462,6 @@ Tests run: 3, Failures: 0, Errors: 0, Sk
<li><a href="http://docs.oracle.com/javaee/6/api/javax/jws/soap/SOAPBinding/Style.html">javax.jws.soap.SOAPBinding.Style</a></li>
<li><a href="http://docs.oracle.com/javaee/6/api/javax/jws/soap/SOAPBinding/Use.html">javax.jws.soap.SOAPBinding.Use</a></li>
<li><a href="http://docs.oracle.com/javaee/6/api/javax/naming/Context.html">javax.naming.Context</a></li>
-<li><a href="http://docs.oracle.com/javaee/6/api/javax/naming/InitialContext.html">javax.naming.InitialContext</a></li>
<li><a href="http://docs.oracle.com/javaee/6/api/javax/xml/namespace/QName.html">javax.xml.namespace.QName</a></li>
<li><a href="http://docs.oracle.com/javaee/6/api/javax/xml/ws/Holder.html">javax.xml.ws.Holder</a></li>
<li><a href="http://docs.oracle.com/javaee/6/api/javax/xml/ws/Service.html">javax.xml.ws.Service</a></li>
Added: websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorImpl.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorImpl.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorImpl.java Sat Feb 18 02:43:14 2012
@@ -0,0 +1,79 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.superbiz.calculator.ws;
+
+import javax.ejb.Stateless;
+import javax.jws.HandlerChain;
+import javax.jws.WebService;
+import javax.xml.ws.Holder;
+import java.util.Date;
+
+/**
+ * This is an EJB 3 style pojo stateless session bean
+ * Every stateless session bean implementation must be annotated
+ * using the annotation @Stateless
+ * This EJB has a 2 interfaces:
+ * <ul>
+ * <li>CalculatorWs a webservice interface</li>
+ * <li>CalculatorLocal a local interface</li>
+ * </ul>
+ */
+//START SNIPPET: code
+@Stateless
+@WebService(
+ portName = "CalculatorPort",
+ serviceName = "CalculatorWsService",
+ targetNamespace = "http://superbiz.org/wsdl",
+ endpointInterface = "org.superbiz.calculator.ws.CalculatorWs")
+@HandlerChain(file = "handler.xml")
+public class CalculatorImpl implements CalculatorWs, CalculatorLocal {
+
+ public int sum(int add1, int add2) {
+ return add1 + add2;
+ }
+
+ public int multiply(int mul1, int mul2) {
+ return mul1 * mul2;
+ }
+
+ public int factorial(
+ int number,
+ Holder<String> userId,
+ Holder<String> returnCode,
+ Holder<Date> datetime) {
+
+ if (number == 0) {
+ returnCode.value = "Can not calculate factorial for zero.";
+ return -1;
+ }
+
+ returnCode.value = userId.value;
+ datetime.value = new Date();
+ return (int) factorial(number);
+ }
+
+ // return n!
+ // precondition: n >= 0 and n <= 20
+
+ private static long factorial(long n) {
+ if (n < 0) throw new RuntimeException("Underflow error in factorial");
+ else if (n > 20) throw new RuntimeException("Overflow error in factorial");
+ else if (n == 0) return 1;
+ else return n * factorial(n - 1);
+ }
+}
+//END SNIPPET: code
Added: websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorLocal.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorLocal.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorLocal.java Sat Feb 18 02:43:14 2012
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.superbiz.calculator.ws;
+
+import javax.ejb.Local;
+
+@Local
+public interface CalculatorLocal extends CalculatorWs {
+
+}
\ No newline at end of file
Added: websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorWs.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorWs.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/ws/CalculatorWs.java Sat Feb 18 02:43:14 2012
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.superbiz.calculator.ws;
+
+import javax.jws.WebParam;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+import javax.jws.soap.SOAPBinding.ParameterStyle;
+import javax.jws.soap.SOAPBinding.Style;
+import javax.jws.soap.SOAPBinding.Use;
+import javax.xml.ws.Holder;
+import java.util.Date;
+
+//END SNIPPET: code
+
+/**
+ * This is an EJB 3 webservice interface
+ * A webservice interface must be annotated with the @WebService
+ * annotation.
+ */
+//START SNIPPET: code
+@WebService(
+ name = "CalculatorWs",
+ targetNamespace = "http://superbiz.org/wsdl")
+public interface CalculatorWs {
+
+ public int sum(int add1, int add2);
+
+ public int multiply(int mul1, int mul2);
+
+ // because of CXF bug, BARE must be used instead of default WRAPPED
+
+ @SOAPBinding(use = Use.LITERAL, parameterStyle = ParameterStyle.BARE, style = Style.DOCUMENT)
+ public int factorial(
+ int number,
+ @WebParam(name = "userid", header = true, mode = WebParam.Mode.IN) Holder<String> userId,
+ @WebParam(name = "returncode", header = true, mode = WebParam.Mode.OUT) Holder<String> returnCode,
+ @WebParam(name = "datetime", header = true, mode = WebParam.Mode.INOUT) Holder<Date> datetime);
+
+}
+//END SNIPPET: code
\ No newline at end of file
Added: websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/ws/handler/DummyInterceptor.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/ws/handler/DummyInterceptor.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/java/org/superbiz/calculator/ws/handler/DummyInterceptor.java Sat Feb 18 02:43:14 2012
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.superbiz.calculator.ws.handler;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPHandler;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+import java.util.Collections;
+import java.util.Set;
+
+public class DummyInterceptor implements SOAPHandler<SOAPMessageContext> {
+ public DummyInterceptor() {
+ super();
+ }
+
+ public Set<QName> getHeaders() {
+ return Collections.emptySet();
+ }
+
+ public void close(MessageContext mc) {
+ }
+
+ public boolean handleFault(SOAPMessageContext mc) {
+ return true;
+ }
+
+ public boolean handleMessage(SOAPMessageContext mc) {
+ return true;
+ }
+}
\ No newline at end of file
Added: websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/resources/org/superbiz/calculator/ws/handler.xml
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/resources/org/superbiz/calculator/ws/handler.xml (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/main/resources/org/superbiz/calculator/ws/handler.xml Sat Feb 18 02:43:14 2012
@@ -0,0 +1,29 @@
+<?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.ws.handler.DummyInterceptor</handler-name>
+ <handler-class>org.superbiz.calculator.ws.handler.DummyInterceptor</handler-class>
+ </handler>
+ </handler-chain>
+</handler-chains>
Added: websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/test/java/org/superbiz/calculator/ws/CalculatorTest.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/test/java/org/superbiz/calculator/ws/CalculatorTest.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/simple-webservice/src/test/java/org/superbiz/calculator/ws/CalculatorTest.java Sat Feb 18 02:43:14 2012
@@ -0,0 +1,108 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.superbiz.calculator.ws;
+
+import junit.framework.TestCase;
+import org.apache.openejb.api.LocalClient;
+import org.superbiz.calculator.ws.CalculatorLocal;
+import org.superbiz.calculator.ws.CalculatorWs;
+
+import javax.ejb.embeddable.EJBContainer;
+import javax.naming.Context;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Holder;
+import javax.xml.ws.Service;
+import javax.xml.ws.WebServiceRef;
+import java.net.URL;
+import java.util.Date;
+import java.util.Properties;
+
+@LocalClient
+public class CalculatorTest extends TestCase {
+
+ @WebServiceRef(
+ wsdlLocation = "http://127.0.0.1:4204/CalculatorImpl?wsdl"
+ )
+ private CalculatorWs calculatorWs;
+
+ // date used to invoke a web service with INOUT parameters
+ private static final Date date = new Date();
+ private Context context;
+
+ protected void setUp() throws Exception {
+
+ Properties properties = new Properties();
+ properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
+ properties.setProperty("openejb.embedded.remotable", "true");
+
+ context = EJBContainer.createEJBContainer(properties).getContext();
+ context.bind("inject", this);
+
+ }
+ //END SNIPPET: setup
+
+ /**
+ * Create a webservice client using wsdl url
+ *
+ * @throws Exception
+ */
+ //START SNIPPET: webservice
+ public void testCalculatorViaWsInterface() throws Exception {
+ Service calcService = Service.create(
+ new URL("http://127.0.0.1:4204/CalculatorImpl?wsdl"),
+ new QName("http://superbiz.org/wsdl", "CalculatorWsService"));
+ assertNotNull(calcService);
+
+ CalculatorWs calc = calcService.getPort(CalculatorWs.class);
+ assertEquals(10, calc.sum(4, 6));
+ assertEquals(12, calc.multiply(3, 4));
+
+ Holder<String> userIdHolder = new Holder<String>("jane");
+ Holder<String> returnCodeHolder = new Holder<String>();
+ Holder<Date> datetimeHolder = new Holder<Date>(date);
+ assertEquals(6, calc.factorial(3, userIdHolder, returnCodeHolder, datetimeHolder));
+ assertEquals(userIdHolder.value, returnCodeHolder.value);
+ assertTrue(date.before(datetimeHolder.value));
+ }
+
+ public void testWebServiceRefInjection() throws Exception {
+ assertEquals(10, calculatorWs.sum(4, 6));
+ assertEquals(12, calculatorWs.multiply(3, 4));
+
+ Holder<String> userIdHolder = new Holder<String>("jane");
+ Holder<String> returnCodeHolder = new Holder<String>();
+ Holder<Date> datetimeHolder = new Holder<Date>(date);
+ assertEquals(6, calculatorWs.factorial(3, userIdHolder, returnCodeHolder, datetimeHolder));
+ assertEquals(userIdHolder.value, returnCodeHolder.value);
+ assertTrue(date.before(datetimeHolder.value));
+ }
+
+ public void testCalculatorViaRemoteInterface() throws Exception {
+ CalculatorLocal calc = (CalculatorLocal) context.lookup("java:global/simple-webservice/CalculatorImpl");
+ assertEquals(10, calc.sum(4, 6));
+ assertEquals(12, calc.multiply(3, 4));
+
+ Holder<String> userIdHolder = new Holder<String>("jane");
+ Holder<String> returnCodeHolder = new Holder<String>();
+ Holder<Date> datetimeHolder = new Holder<Date>(date);
+ assertEquals(6, calc.factorial(3, userIdHolder, returnCodeHolder, datetimeHolder));
+ assertEquals(userIdHolder.value, returnCodeHolder.value);
+ assertTrue(date.before(datetimeHolder.value));
+ }
+ //END SNIPPET: webservice
+
+}