|
From: <fug...@us...> - 2007-11-02 02:05:49
|
Revision: 1817
http://cogkit.svn.sourceforge.net/cogkit/?rev=1817&view=rev
Author: fugangwang
Date: 2007-11-01 19:05:47 -0700 (Thu, 01 Nov 2007)
Log Message:
-----------
add a usable test example, which deployed a web service and invoke the service using a java client
Added Paths:
-----------
trunk/cyberaide/src/jaxws/testCircleService/
trunk/cyberaide/src/jaxws/testCircleService/CircleFunctions.java
trunk/cyberaide/src/jaxws/testCircleService/Makefile
trunk/cyberaide/src/jaxws/testCircleService/TestCircleFunctions.java
trunk/cyberaide/src/jaxws/testCircleService/stop.sh
Added: trunk/cyberaide/src/jaxws/testCircleService/CircleFunctions.java
===================================================================
--- trunk/cyberaide/src/jaxws/testCircleService/CircleFunctions.java (rev 0)
+++ trunk/cyberaide/src/jaxws/testCircleService/CircleFunctions.java 2007-11-02 02:05:47 UTC (rev 1817)
@@ -0,0 +1,46 @@
+/*
+ * CircleFunctions.java
+ *
+ * @version:
+ * $Id v1.0$
+ *
+ * @author:
+ * Fugang Wang
+ *
+ * Revisions:
+ * 10/28/2007 Initial version
+ * 11/01/2007 modify package name
+ *
+ */
+package testjaxws.service;
+
+import javax.jws.WebService;
+import javax.xml.ws.Endpoint;
+
+@WebService
+public class CircleFunctions {
+
+ /*
+ * return area of a circle
+ */
+ public double getArea(double r) {
+ return java.lang.Math.PI * (r * r);
+ }
+
+ /*
+ * return circumference of a circle
+ */
+ public double getCircumference(double r) {
+ return 2 * java.lang.Math.PI * r;
+ }
+
+ /*
+ * publish the service
+ */
+ public static void main(String[] args) {
+
+ Endpoint.publish(
+ "http://localhost:8080/jaxws/circlefunctions",
+ new CircleFunctions());
+ }
+}
Added: trunk/cyberaide/src/jaxws/testCircleService/Makefile
===================================================================
--- trunk/cyberaide/src/jaxws/testCircleService/Makefile (rev 0)
+++ trunk/cyberaide/src/jaxws/testCircleService/Makefile 2007-11-02 02:05:47 UTC (rev 1817)
@@ -0,0 +1,27 @@
+all: compile service client stop
+ @echo done
+
+init:
+ mkdir -p testjaxws
+
+compile: init
+ javac -d . CircleFunctions.java
+
+service:
+ @echo "Starting service..."
+ wsgen -cp . -r testjaxws -wsdl testjaxws.service.CircleFunctions
+ java testjaxws.service.CircleFunctions &
+ sleep 2
+
+client:
+ @echo "Generating and running client..."
+ wsimport -keep -p testjaxws.clientstub http://localhost:8080/jaxws/circlefunctions?WSDL
+ javac -d . TestCircleFunctions.java
+ java testjaxws.client.TestCircleFunctions
+
+stop:
+ @echo "Stopping service..."
+ sh stop.sh
+
+clean:
+ rm -fr testjaxws
Added: trunk/cyberaide/src/jaxws/testCircleService/TestCircleFunctions.java
===================================================================
--- trunk/cyberaide/src/jaxws/testCircleService/TestCircleFunctions.java (rev 0)
+++ trunk/cyberaide/src/jaxws/testCircleService/TestCircleFunctions.java 2007-11-02 02:05:47 UTC (rev 1817)
@@ -0,0 +1,68 @@
+/*
+ * TestCircleFunctions.java
+ *
+ * @version:
+ * $Id v1.0$
+ *
+ * @author:
+ * Fugang Wang
+ *
+ * Revisions:
+ * 10/28/2007 Initial version
+ * 11/01/2007 modify package name
+ *
+ */
+package testjaxws.client;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+import javax.xml.ws.WebEndpoint;
+import javax.xml.ws.WebServiceRef;
+//import javax.jws.WebService;
+import testjaxws.clientstub.CircleFunctionsService;
+
+//@WebServiceRef(wsdlLocation = "http://localhost:8080/jaxws/circlefunctions?WSDL")
+
+public class TestCircleFunctions {
+ static CircleFunctionsService service = new CircleFunctionsService();
+
+ public static void main(String[] args) {
+ try {
+ TestCircleFunctions client = new TestCircleFunctions();
+ client.doTest(args);
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void doTest(String[] args) {
+ try {
+ System.out.println("----------from Client running----------");
+ System.out.println("Retrieving the port from the following service:\n\t " + service);
+ testjaxws.clientstub.CircleFunctions port = service.getCircleFunctionsPort();
+ double radius,area,circumference;
+
+ System.out.println("Invoking the getCircumference operation on the port...");
+ System.out.print("Response from server:\n\tThe circumference of a circle with radius 5:");
+ radius = 5;
+ circumference = port.getCircumference(radius);
+ System.out.println( circumference );
+
+ System.out.println("Invoking the getArea operation on the port...");
+ System.out.print("Response from server:\n\tThe area of a circle with radius 10:");
+ radius = 10;
+ area = port.getArea(radius);
+ System.out.println( area );
+
+ System.out.println("Invoking the getCircumference operation on the port...");
+ System.out.print("Response from server:\n\tThe circumference of a circle with radius 10:");
+ circumference = port.getCircumference(radius);
+ System.out.println( circumference );
+
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
Added: trunk/cyberaide/src/jaxws/testCircleService/stop.sh
===================================================================
--- trunk/cyberaide/src/jaxws/testCircleService/stop.sh (rev 0)
+++ trunk/cyberaide/src/jaxws/testCircleService/stop.sh 2007-11-02 02:05:47 UTC (rev 1817)
@@ -0,0 +1 @@
+kill -9 `ps -a|grep java|awk '{print $1}'`
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|