You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2008/04/04 15:54:37 UTC
svn commit: r644715 - in
/webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up: ./ src/
src/org/ src/org/apache/ src/org/apache/axis2/ src/org/apache/axis2/jaxws/
src/org/apache/axis2/jaxws/addressbook/
Author: dims
Date: Fri Apr 4 06:54:32 2008
New Revision: 644715
URL: http://svn.apache.org/viewvc?rev=644715&view=rev
Log:
initial checkin of sample from Jeff Barrett. Needs an m2 pom.xml
Added:
webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/
webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/README.txt
webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/
webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/AddressBookEntry.xsd
webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/org/
webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/org/apache/
webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/org/apache/axis2/
webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/org/apache/axis2/jaxws/
webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/org/apache/axis2/jaxws/addressbook/
webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/org/apache/axis2/jaxws/addressbook/AddressBook.java
webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/org/apache/axis2/jaxws/addressbook/AddressBookClient.java
webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/org/apache/axis2/jaxws/addressbook/AddressBookImpl.java
Added: webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/README.txt
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/README.txt?rev=644715&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/README.txt (added)
+++ webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/README.txt Fri Apr 4 06:54:32 2008
@@ -0,0 +1,113 @@
+Axis2 JAX-WS start-from-java (also known as bottoms-up) sample.
+
+ 1. Given a simple schema, generate the JAXB artifacts using xjc.
+ 2. With the generated JAXB beans in hand, write the service implementation
+ and add annotations to make a Web Service.
+ 3. Write a Dispatch client to interact with the service
+ 4. Run the Dispatch client against the service implementation deployed in the Axis2 server
+
+This will be an address book sample based on one of the jaxws-integration tests:
+modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/addressbook
+
+Note that this is a very simple example, and does not persist any data. The intent is
+to illustrate the use of JAXB objects with JAX-WS, not to actually implement and address book.
+
+The directory structure and environment setup in this example is as follows. You should modify
+the example directories based on your environment.
+- Axis2 binary distribution: AXIS2_HOME=C:\temp\Axis2\axis2-SNAPSHOT
+- Java5 JDK: JAVA_HOME=c:\java\java5
+- This example source is in: C:\blddir\eclipse\axis2\jaxws-bottoms-up
+
+Note that JAVA_HOME is assumed to be on PATH.
+
+The following source is included with this example:
+src\AddressBookEntry.xsd: Schema used to generate JAXB artifacts
+src\org\apache\axis2\jaxws\addressbook\AddressBook.java: JAXWS Service Endpoint Interface (SEI)
+ Note that this SEI is NOT CURRENTLY USED in this example.
+src\org\apache\axis2\jaxws\addressbook\AddressBookClient.java: JAXWS Dispatch Client
+src\org\apache\axis2\jaxws\addressbook\AddressBookImpl.java: JAXWS service implementation
+
+Note that this ReadMe was created with the example in an Eclipse project with the following
+structure:
+- 'src' source folder containing the example source
+- 'jaxb' source folder containing the generated JAXB artifacts from Step 1
+- 'bin' directory containing all of the output (including the compiled classes)
+
+Step 1: Generate JAXB artifacts from simple schema
+==================================================
+The file src/AddressBookEntry.xsd describes a simple AddressBookEntry object with the
+following fields:
+ String firstName;
+ String lastName;
+ String phone;
+ String street;
+ String city;
+ String state;
+
+To generate the JAXB beans for this schema, run the following command in the 'src' directory:
+java -Djava.ext.dirs=C:\temp\Axis2\axis2-SNAPSHOT\lib;C:\java\java5\jre\lib\ext com.sun.tools.xjc.Driver -d jaxb src\AddressBookEntry.xsd
+
+This will generate the following JAXB artifacts:
+org\apache\axis2\jaxws\addressbook\AddressBookEntry.java
+org\apache\axis2\jaxws\addressbook\ObjectFactory.java
+org\apache\axis2\jaxws\addressbook\package-info.java
+
+You can compile these files now or later in Step 3 with the rest of the java files. See Step 3
+for the 'javac' command.
+
+Step 2: Write a JAX-WS service implementation using the JAXB artifacts
+======================================================================
+The simple service implementation will have two methods on it:
+ public String addEntry(String firstName, String lastName, String phone, String street, String city, String state)
+ public AddressBookEntry findByLastName(String lastName)
+
+The service implentation does not explicitly specify a JAX-WS SEI. The public methods on the
+implementation are an implicit SEI. Simply by adding an @WebService annotation to the implementation
+it becomes a JAX-WS web service.
+
+See src\org\apache\axis2\jaxws\addressbook\AddressBookImpl.java
+
+You can compile these files now or later in Step 3 with the rest of the java files. See Step 3
+for the 'javac' command.
+
+Step 3: Write a JAX-WS Dispatch client to interact with the service
+===================================================================
+The extremely simple Dispatch client will use be a Payload mode String Dispatch client meaning that
+it will provide the exact SOAP body to send in the request (Payload mode) as a String, and expect
+the response to be a SOAP body returned as a String. It will invoke both methods on the
+service implenetation's implicit SEI.
+
+Step 4: Run the Dispatch client against the service implementation deployed in the Axis2 server
+===============================================================================================
+(a) First compile the generated JAXB artifacts, the service implementation, and the dispatch client.
+Note that if you are using Eclipse, this step will not be necessary; Eclipse will have compiled the
+classes into the 'bin' directory.
+javac -Djava.ext.dirs=C:\temp\Axis2\axis2-SNAPSHOT\lib;C:\java\java5\jre\lib\ext -classpath C:\blddir\eclipse\axis2\jaxws-bottoms-up\bin *.java
+
+(b) Then create a JAR file containg the service implementation and copy it to
+the axis2 repository/servicejars directory. This will cause it to be deployed when the axis2
+server is started. Note that in this example, the service implementation jar will also contain
+the client classes; this is not necessary; it is done to simplify the example. From the directory
+above 'org' which contains the compiled classes from (a):
+jar -cvf AddressBook.jar org
+mkdir C:\temp\Axis2\axis2-SNAPSHOT\repository\servicejars
+copy AddressBook.jar C:\temp\Axis2\axis2-SNAPSHOT\repository\servicejars
+
+(c) Start the axis2 server. This will deploy the JAX-WS service implementation.
+set AXIS2_HOME=C:\temp\Axis2\axis2-SNAPSHOT
+bin\axis2server.bat
+
+You should see a message such as:
+[INFO] Deploying artifact : AddressBook.jar
+[INFO] Deploying JAXWS annotated class org.apache.axis2.jaxws.addressbook.AddressBookImpl as a service - AddressBookImplService.AddressBookImplPort
+
+(d) From another window with the environment setup, run the Dispatch client:
+java -Djava.ext.dirs=C:\temp\Axis2\axis2-SNAPSHOT\lib;C:\java\java5\jre\lib\ext -cp C:\blddir\eclipse\axis2\jaxws-bottoms-up\bin org.apache.axis2.jaxws.addressbook.AddressBookClient.class
+
+Thoughts on improvmenets
+========================
+1. Extend the simple schema to include the request and response messages, generate those beans
+ with xjc, and then use them in the Dispatch client instead of the String messages
+
+2. Make use of the JAXWS SEI by specifying an @WebService annotation on it and
+ and @WebService.endpointInterface on the serivice implementation
\ No newline at end of file
Added: webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/AddressBookEntry.xsd
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/AddressBookEntry.xsd?rev=644715&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/AddressBookEntry.xsd (added)
+++ webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/AddressBookEntry.xsd Fri Apr 4 06:54:32 2008
@@ -0,0 +1,19 @@
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://addressbook.jaxws.axis2.apache.org"
+ xmlns:tns="http://addressbook.jaxws.axis2.apache.org">
+ <xsd:element name="AddressBookEntry" type="tns:AddressBookEntry"/>
+ <xsd:complexType name="AddressBookEntry">
+ <xsd:complexContent>
+ <xsd:restriction base="xsd:anyType">
+ <xsd:sequence>
+ <xsd:element name="firstName" type="xsd:string"/>
+ <xsd:element name="lastName" type="xsd:string"/>
+ <xsd:element name="phone" type="xsd:string"/>
+ <xsd:element name="street" type="xsd:string"/>
+ <xsd:element name="city" type="xsd:string"/>
+ <xsd:element name="state" type="xsd:string"/>
+ </xsd:sequence>
+ </xsd:restriction>
+ </xsd:complexContent>
+ </xsd:complexType>
+</xsd:schema>
\ No newline at end of file
Added: webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/org/apache/axis2/jaxws/addressbook/AddressBook.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/org/apache/axis2/jaxws/addressbook/AddressBook.java?rev=644715&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/org/apache/axis2/jaxws/addressbook/AddressBook.java (added)
+++ webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/org/apache/axis2/jaxws/addressbook/AddressBook.java Fri Apr 4 06:54:32 2008
@@ -0,0 +1,10 @@
+package org.apache.axis2.jaxws.addressbook;
+
+// NOTE: This Service Endpoint Interface (SEI) is NOT CURRENTLY USED in this example
+
+public interface AddressBook {
+
+ public void addEntry(String firstName, String lastName, String phone, String street, String city, String state);
+
+ public AddressBookEntry findByLastName(String lastName);
+}
Added: webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/org/apache/axis2/jaxws/addressbook/AddressBookClient.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/org/apache/axis2/jaxws/addressbook/AddressBookClient.java?rev=644715&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/org/apache/axis2/jaxws/addressbook/AddressBookClient.java (added)
+++ webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/org/apache/axis2/jaxws/addressbook/AddressBookClient.java Fri Apr 4 06:54:32 2008
@@ -0,0 +1,51 @@
+package org.apache.axis2.jaxws.addressbook;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+
+import java.util.Map;
+
+public class AddressBookClient {
+ private static String NAMESPACE = "http://addressbook.jaxws.axis2.apache.org";
+ private static QName QNAME_SERVICE = new QName(NAMESPACE, "service");
+ private static QName QNAME_PORT = new QName(NAMESPACE, "port");
+ private static String ENDPOINT_URL = "http://localhost:8080/axis2/services/AddressBookImplService.AddressBookImplPort";
+
+ private static String ADD_ENTRY_BODY_CONTENTS =
+ "<ns1:addEntry xmlns:ns1=\"http://addressbook.jaxws.axis2.apache.org\">" +
+ "<ns1:firstName xmlns=\"http://addressbook.jaxws.axis2.apache.org\">myFirstName</ns1:firstName>" +
+ "<ns1:lastName xmlns=\"http://addressbook.jaxws.axis2.apache.org\">myLastName</ns1:lastName>" +
+ "<ns1:phone xmlns=\"http://addressbook.jaxws.axis2.apache.org\">myPhone</ns1:phone>" +
+ "<ns1:street xmlns=\"http://addressbook.jaxws.axis2.apache.org\">myStreet</ns1:street>" +
+ "<ns1:city xmlns=\"http://addressbook.jaxws.axis2.apache.org\">myCity</ns1:city>" +
+ "<ns1:state xmlns=\"http://addressbook.jaxws.axis2.apache.org\">myState</ns1:state>" +
+ "</ns1:addEntry>";
+
+ private static String FIND_BODY_CONTENTS =
+ "<ns1:findByLastName xmlns:ns1=\"http://addressbook.jaxws.axis2.apache.org\">" +
+ "<ns1:lastName xmlns=\"http://addressbook.jaxws.axis2.apache.org\">myLastName</ns1:lastName>" +
+ "</ns1:findByLastName>";
+
+ public static void main(String[] args) {
+ try {
+ Service svc = Service.create(QNAME_SERVICE);
+ svc.addPort(QNAME_PORT, null, ENDPOINT_URL);
+ Dispatch<String> dispatch = svc.createDispatch(QNAME_PORT,
+ String.class, Service.Mode.PAYLOAD);
+
+ // Invoke the Dispatch
+ System.out.println(">> Invoking sync Dispatch for AddEntry");
+ String response = dispatch.invoke(ADD_ENTRY_BODY_CONTENTS);
+ System.out.println("Add Entry (void) Response: " + response);
+
+ System.out.println(">> Invoking Dispatch for findByLastName");
+ String response2 = dispatch.invoke(FIND_BODY_CONTENTS);
+ System.out.println("Find response: " + response2);
+ } catch (Exception e) {
+ System.out.println("Caught exception: " + e);
+ e.printStackTrace();
+ }
+ }
+}
Added: webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/org/apache/axis2/jaxws/addressbook/AddressBookImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/org/apache/axis2/jaxws/addressbook/AddressBookImpl.java?rev=644715&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/org/apache/axis2/jaxws/addressbook/AddressBookImpl.java (added)
+++ webservices/axis2/trunk/java/modules/samples/jaxws-bottoms-up/src/org/apache/axis2/jaxws/addressbook/AddressBookImpl.java Fri Apr 4 06:54:32 2008
@@ -0,0 +1,40 @@
+package org.apache.axis2.jaxws.addressbook;
+
+import javax.jws.WebService;
+
+/**
+ * JAX-WS service implementation that uses and implicit SEI rather than an explicit SEI. An
+ * implicit SEI means that there is no @WebService.endpointInterface element specified. This means
+ * that all public methods on the service implementation comprise an implicit SEI.
+ */
+
+// Simply adding the @WebService annotation makes this a JAX-WS service implementation.
+@WebService
+public class AddressBookImpl {
+
+ public String addEntry(String firstName, String lastName, String phone, String street, String city, String state) {
+ System.out.println("AddressBookImpl.addEntry");
+ AddressBookEntry entry = new AddressBookEntry();
+ entry.setFirstName(firstName);
+ entry.setLastName(lastName);
+ entry.setPhone(phone);
+ entry.setStreet(street);
+ entry.setCity(city);
+ entry.setState(state);
+ return "AddEntry Completed!";
+ }
+
+ public AddressBookEntry findByLastName(String lastName) {
+ System.out.println("AddressBookImpl.findByLastName");
+ AddressBookEntry entry = new AddressBookEntry();
+ entry.setFirstName("firstName");
+ entry.setLastName("lastName");
+ entry.setPhone("phone");
+ entry.setStreet("street");
+ entry.setCity("city");
+ entry.setState("state");
+ System.out.println("AddressBookImpl.findByLastName returning " + entry);
+ return entry;
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org