Project

General

Profile

« Previous | Next » 

Revision 827783b1

Added by Markus Döring over 16 years ago

demo only

View differences:

.gitattributes
448 448
cdmlibrary/src/test/resources/settings.xml -text
449 449
cdmlibrary/src/test/resources/test.cdm.datasource.xml -text
450 450
cdmlibrary/updateAnnotatedClasses.py -text
451
dictionaryService-CxfTest/client/pom.xml -text
452
dictionaryService-CxfTest/client/src/main/java/com/mycompany/webservice/client/WSClient.java -text
453
dictionaryService-CxfTest/client/src/wsdl/WordLookup.wsdl -text
454
dictionaryService-CxfTest/jaxws/pom.xml -text
455
dictionaryService-CxfTest/jaxws/src/wsdl/WordLookup.wsdl -text
456
dictionaryService-CxfTest/pom.xml -text
457
dictionaryService-CxfTest/service/pom.xml -text
458
dictionaryService-CxfTest/service/src/main/java/com/mycompany/webservice/service/WordLookupPortTypeImpl.java -text
459
dictionaryService-CxfTest/service/src/main/webapp/WEB-INF/cxf-servlet.xml -text
460
dictionaryService-CxfTest/service/src/main/webapp/WEB-INF/sun-jaxws.xml -text
461
dictionaryService-CxfTest/service/src/main/webapp/WEB-INF/web.xml -text
462
dictionaryService-CxfTest/service/src/main/webapp/WEB-INF/wsdl/WordLookup.wsdl -text
463 451
docs/layers.graffle -text
464 452
docs/layers.png -text
465 453
libraryTesterApplication/.classpath -text
dictionaryService-CxfTest/client/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0"
3
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5

  
6
   <modelVersion>4.0.0</modelVersion>
7
   <parent>
8
      <groupId>com.mycompany.webservice</groupId>
9
      <artifactId>DictionaryServiceSample</artifactId>
10
      <version>1.0-SNAPSHOT</version>
11
      <relativePath>../dictionaryService-CxfTest/pom.xml</relativePath>
12
   </parent>
13
   <artifactId>client</artifactId>
14
   <name>SOAP Client for Dictionary Service</name>
15
   <packaging>jar</packaging>
16

  
17
   <dependencies>
18
      <dependency>
19
         <groupId>com.mycompany.webservice</groupId>
20
         <artifactId>jaxws</artifactId>
21
         <version>1.0-SNAPSHOT</version>
22
      </dependency>
23
   </dependencies>
24

  
25
   <build>
26
      <plugins>
27
         <plugin>
28
            <groupId>org.codehaus.mojo</groupId>
29
            <artifactId>exec-maven-plugin</artifactId>
30
            <executions>
31
               <execution>
32
                  <phase>test</phase>
33
                  <goals>
34
                     <goal>exec</goal>
35
                  </goals>
36
               </execution>
37
            </executions>
38
            <configuration>
39
               <executable>java</executable>
40
               <arguments>
41
                  <argument>-classpath</argument>
42
                  <classpath/>
43
                  <argument> <!-- remove if using CXF -->
44
                     -Dcom.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true
45
                  </argument>
46
                  <argument> <!-- remove if using Metro -->
47
                     -Djava.util.logging.config.file=${env.CXF_HOME}/etc/logging.properties
48
                  </argument>
49
                  <argument>com.mycompany.webservice.client.WSClient</argument>
50
               </arguments>
51
            </configuration>
52
         </plugin>
53
      </plugins>
54
   </build>
55
</project>
dictionaryService-CxfTest/client/src/main/java/com/mycompany/webservice/client/WSClient.java
1
package com.mycompany.webservice.client;
2

  
3
import org.example.wordlookup.BasicFault;
4
import org.example.wordlookup.EntryAlreadyExistsFault;
5
import org.example.wordlookup.EntryNotFoundFault;
6
import org.example.wordlookup.LookupEJ;
7
import org.example.wordlookup.LookupJE;
8
import org.example.wordlookup.LookupResponse;
9
import org.example.wordlookup.WordLookupPortType;
10
import org.example.wordlookup.WordLookupService;
11

  
12
public class WSClient {
13
    public static void main (String[] args) {
14
        WordLookupService ss = new WordLookupService();
15
        WordLookupPortType port = ss.getWordLookupPort();
16
        
17
        // lookup features for words already in DB
18
        dictionaryLookup(port, "elephant", "JA");
19
        dictionaryLookup(port, "rakuda", "EN");
20
        
21
        // lookup words not yet in DB
22
        dictionaryLookup(port, "fox", "JA");
23
        dictionaryLookup(port, "kitsune", "EN");
24

  
25
        // adding word pair to dictionary
26
        addWordEntry(port, "fox", "kitsune");
27
        
28
        // words should be found now
29
        dictionaryLookup(port, "fox", "JA");
30
        dictionaryLookup(port, "kitsune", "EN");
31
        
32
    }  
33
    
34
    public static void dictionaryLookup (WordLookupPortType port, 
35
            String inWord, String target) {
36
        try {
37
            if ("EN".equals(target)) {
38
                LookupJE lookup = new LookupJE();
39
                lookup.setWordToTranslate(inWord);
40
                LookupResponse resp = port.jaToEnLookup(lookup);
41
                System.out.println("Japanese \"" + lookup.getWordToTranslate()
42
                   + "\" is English \"" 
43
                   + resp.getTranslatedWord().toLowerCase() + "\"");
44
            } else {
45
                LookupEJ lookup = new LookupEJ();
46
                lookup.setWordToTranslate(inWord);
47
                LookupResponse resp = port.enToJaLookup(lookup);
48
                System.out.println("English \"" + lookup.getWordToTranslate()
49
                   + "\" is Japanese \"" 
50
                   + resp.getTranslatedWord().toLowerCase() + "\"");
51
            }
52
        } catch (EntryNotFoundFault e) {
53
            System.out.println("Exception: " +  e.getMessage());
54
            BasicFault bf = e.getFaultInfo();
55
            System.out.println(bf.getErrorMessage());
56
        }        
57
    }
58
    
59
    public static void addWordEntry (WordLookupPortType port, 
60
            String enWord, String jaWord) {
61
        try {
62
            String result = port.addWordEntry(enWord, jaWord);
63
            System.out.println("Result of adding {" + enWord + ", " + jaWord +
64
                    "} to dictionary is: " + result);
65
        } catch (EntryAlreadyExistsFault e) {
66
            System.out.println("Exception: " +  e.getMessage());
67
            BasicFault bf = e.getFaultInfo();
68
            System.out.println(bf.getErrorMessage());
69
            System.out.println(bf.getErrorDetails());
70
        }        
71
    }
72
}
dictionaryService-CxfTest/client/src/wsdl/WordLookup.wsdl
1
<?xml version="1.0" encoding="UTF-8"?>
2
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
3
   xmlns:tns="http://www.example.org/WordLookup"
4
   xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
5
   xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="WordLookup"
6
   targetNamespace="http://www.example.org/WordLookup">
7
   <wsdl:types>
8
      <xsd:schema targetNamespace="http://www.example.org/WordLookup">
9
         <xsd:element name="LookupEJ">
10
            <xsd:complexType>
11
               <xsd:sequence>
12
                  <xsd:element name="wordToTranslate" type="xsd:string"/>
13
               </xsd:sequence>
14
            </xsd:complexType>
15
         </xsd:element>
16
         <xsd:element name="LookupJE">
17
            <xsd:complexType>
18
               <xsd:sequence>
19
                  <xsd:element name="wordToTranslate" type="xsd:string"/>
20
               </xsd:sequence>
21
            </xsd:complexType>
22
         </xsd:element>
23
         <xsd:element name="LookupResponse">
24
            <xsd:complexType>
25
               <xsd:sequence>
26
                  <xsd:element name="translatedWord" type="xsd:string" />
27
               </xsd:sequence>
28
            </xsd:complexType>
29
         </xsd:element>
30
         <xsd:element name="AddWordEntry">
31
            <xsd:complexType>
32
               <xsd:sequence>
33
                  <xsd:element name="englishWord" type="xsd:string" />
34
                  <xsd:element name="japaneseWord" type="xsd:string" />
35
               </xsd:sequence>
36
            </xsd:complexType>
37
         </xsd:element>
38
         <xsd:element name="AddWordEntryResponse">
39
            <xsd:complexType>
40
               <xsd:sequence>
41
                  <xsd:element name="results" type="xsd:string" />
42
               </xsd:sequence>
43
            </xsd:complexType>
44
         </xsd:element>
45
         <xsd:element name="BasicFault">
46
            <xsd:complexType>
47
               <xsd:sequence>
48
                  <xsd:element name="errorMessage" type="xsd:string"/>
49
                  <xsd:element name="errorDetails" type="xsd:string"/>
50
               </xsd:sequence>
51
            </xsd:complexType>
52
         </xsd:element>         
53
      </xsd:schema>
54
   </wsdl:types>
55
   <wsdl:message name="LookupEJRequest">
56
      <wsdl:part element="tns:LookupEJ" name="parameters" />
57
   </wsdl:message>
58
   <wsdl:message name="LookupJERequest">
59
      <wsdl:part element="tns:LookupJE" name="parameters" />
60
   </wsdl:message>
61
   <wsdl:message name="LookupResponse">
62
      <wsdl:part element="tns:LookupResponse" name="parameters" />
63
   </wsdl:message>
64
   <wsdl:message name="EntryNotFoundFault">
65
      <wsdl:part element="tns:BasicFault" name="BasicFault"/>
66
   </wsdl:message>
67
   <wsdl:message name="EntryAlreadyExistsFault">
68
      <wsdl:part element="tns:BasicFault" name="BasicFault"/>
69
   </wsdl:message>
70
   <wsdl:message name="AddWordEntryRequest">
71
      <wsdl:part element="tns:AddWordEntry" name="parameters" />
72
   </wsdl:message>
73
   <wsdl:message name="AddWordEntryResponse">
74
      <wsdl:part element="tns:AddWordEntryResponse" name="parameters" />
75
   </wsdl:message>
76
   <wsdl:portType name="WordLookupPortType">
77
      <wsdl:operation name="JaToEnLookup">
78
         <wsdl:input message="tns:LookupJERequest" />
79
         <wsdl:output message="tns:LookupResponse" />
80
         <wsdl:fault message="tns:EntryNotFoundFault" 
81
            name="EntryNotFoundFault"/>
82
      </wsdl:operation>
83
      <wsdl:operation name="EnToJaLookup">
84
         <wsdl:input message="tns:LookupEJRequest" />
85
         <wsdl:output message="tns:LookupResponse" />
86
         <wsdl:fault message="tns:EntryNotFoundFault" 
87
            name="EntryNotFoundFault"/>
88
      </wsdl:operation>
89
      <wsdl:operation name="AddWordEntry">
90
         <wsdl:input message="tns:AddWordEntryRequest" />
91
         <wsdl:output message="tns:AddWordEntryResponse" />
92
         <wsdl:fault message="tns:EntryAlreadyExistsFault" 
93
            name="EntryAlreadyExistsFault"/>
94
      </wsdl:operation>
95
   </wsdl:portType>
96
   <wsdl:binding name="WordLookupBinding" type="tns:WordLookupPortType">
97
      <soap:binding style="document"
98
         transport="http://schemas.xmlsoap.org/soap/http" />
99
      <wsdl:operation name="JaToEnLookup">
100
         <soap:operation soapAction=""/>
101
         <wsdl:input><soap:body use="literal"/></wsdl:input>
102
         <wsdl:output><soap:body use="literal"/></wsdl:output>
103
         <wsdl:fault name="EntryNotFoundFault">
104
             <soap:fault name="EntryNotFoundFault" use="literal" />
105
         </wsdl:fault>
106
      </wsdl:operation>
107
      <wsdl:operation name="EnToJaLookup">
108
         <soap:operation soapAction=""/>
109
         <wsdl:input><soap:body use="literal"/></wsdl:input>
110
         <wsdl:output><soap:body use="literal"/></wsdl:output>
111
         <wsdl:fault name="EntryNotFoundFault">
112
             <soap:fault name="EntryNotFoundFault" use="literal" />
113
         </wsdl:fault>
114
      </wsdl:operation>
115
      <wsdl:operation name="AddWordEntry">
116
         <soap:operation soapAction=""/>
117
         <wsdl:input><soap:body use="literal"/></wsdl:input>
118
         <wsdl:output><soap:body use="literal"/></wsdl:output>
119
         <wsdl:fault name="EntryAlreadyExistsFault">
120
             <soap:fault name="EntryAlreadyExistsFault" use="literal" />
121
         </wsdl:fault>
122
      </wsdl:operation>
123
   </wsdl:binding>
124
   <wsdl:service name="WordLookupService">
125
      <wsdl:port name="WordLookupPort" binding="tns:WordLookupBinding">
126
         <soap:address 
127
            location="http://localhost:8080/wordlookup/services/wordlookup"/>
128
      </wsdl:port>
129
   </wsdl:service>
130
</wsdl:definitions>
dictionaryService-CxfTest/jaxws/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0"
3
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5

  
6
  <modelVersion>4.0.0</modelVersion>
7
  <parent>
8
    <groupId>com.mycompany.webservice</groupId>
9
    <artifactId>DictionaryServiceSample</artifactId>
10
    <version>1.0-SNAPSHOT</version>
11
     <relativePath>../dictionaryService-CxfTest/pom.xml</relativePath>
12
  </parent>
13
  <artifactId>jaxws</artifactId>
14
  <name>JAX-WS artifacts (Apache CXF Version)</name>
15
  <packaging>jar</packaging>
16

  
17
   <build>
18
      <plugins>
19
         <plugin>
20
            <groupId>org.apache.cxf</groupId>
21
            <artifactId>cxf-codegen-plugin</artifactId>
22
            <version>${cxf.version}</version>
23
            <executions>
24
               <execution>
25
                  <phase>generate-sources</phase>
26
                  <configuration>
27
                     <sourceRoot>
28
                        ${basedir}/target/generated/src/main/java
29
                     </sourceRoot>
30
                     <wsdlOptions>
31
                        <wsdlOption>
32
                           <wsdl>
33
                              ${basedir}/src/wsdl/WordLookup.wsdl
34
                           </wsdl>
35
                        </wsdlOption>
36
                     </wsdlOptions>
37
                  </configuration>
38
                  <goals>
39
                     <goal>wsdl2java</goal>
40
                  </goals>
41
               </execution>
42
            </executions>
43
         </plugin>
44
      </plugins>
45
   </build>
46
</project>
dictionaryService-CxfTest/jaxws/src/wsdl/WordLookup.wsdl
1
<?xml version="1.0" encoding="UTF-8"?>
2
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
3
   xmlns:tns="http://www.example.org/WordLookup"
4
   xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
5
   xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="WordLookup"
6
   targetNamespace="http://www.example.org/WordLookup">
7
   <wsdl:types>
8
      <xsd:schema targetNamespace="http://www.example.org/WordLookup">
9
         <xsd:element name="LookupEJ">
10
            <xsd:complexType>
11
               <xsd:sequence>
12
                  <xsd:element name="wordToTranslate" type="xsd:string"/>
13
               </xsd:sequence>
14
            </xsd:complexType>
15
         </xsd:element>
16
         <xsd:element name="LookupJE">
17
            <xsd:complexType>
18
               <xsd:sequence>
19
                  <xsd:element name="wordToTranslate" type="xsd:string"/>
20
               </xsd:sequence>
21
            </xsd:complexType>
22
         </xsd:element>
23
         <xsd:element name="LookupResponse">
24
            <xsd:complexType>
25
               <xsd:sequence>
26
                  <xsd:element name="translatedWord" type="xsd:string" />
27
               </xsd:sequence>
28
            </xsd:complexType>
29
         </xsd:element>
30
         <xsd:element name="AddWordEntry">
31
            <xsd:complexType>
32
               <xsd:sequence>
33
                  <xsd:element name="englishWord" type="xsd:string" />
34
                  <xsd:element name="japaneseWord" type="xsd:string" />
35
               </xsd:sequence>
36
            </xsd:complexType>
37
         </xsd:element>
38
         <xsd:element name="AddWordEntryResponse">
39
            <xsd:complexType>
40
               <xsd:sequence>
41
                  <xsd:element name="results" type="xsd:string" />
42
               </xsd:sequence>
43
            </xsd:complexType>
44
         </xsd:element>
45
         <xsd:element name="BasicFault">
46
            <xsd:complexType>
47
               <xsd:sequence>
48
                  <xsd:element name="errorMessage" type="xsd:string"/>
49
                  <xsd:element name="errorDetails" type="xsd:string"/>
50
               </xsd:sequence>
51
            </xsd:complexType>
52
         </xsd:element>         
53
      </xsd:schema>
54
   </wsdl:types>
55
   <wsdl:message name="LookupEJRequest">
56
      <wsdl:part element="tns:LookupEJ" name="parameters" />
57
   </wsdl:message>
58
   <wsdl:message name="LookupJERequest">
59
      <wsdl:part element="tns:LookupJE" name="parameters" />
60
   </wsdl:message>
61
   <wsdl:message name="LookupResponse">
62
      <wsdl:part element="tns:LookupResponse" name="parameters" />
63
   </wsdl:message>
64
   <wsdl:message name="EntryNotFoundFault">
65
      <wsdl:part element="tns:BasicFault" name="BasicFault"/>
66
   </wsdl:message>
67
   <wsdl:message name="EntryAlreadyExistsFault">
68
      <wsdl:part element="tns:BasicFault" name="BasicFault"/>
69
   </wsdl:message>
70
   <wsdl:message name="AddWordEntryRequest">
71
      <wsdl:part element="tns:AddWordEntry" name="parameters" />
72
   </wsdl:message>
73
   <wsdl:message name="AddWordEntryResponse">
74
      <wsdl:part element="tns:AddWordEntryResponse" name="parameters" />
75
   </wsdl:message>
76
   <wsdl:portType name="WordLookupPortType">
77
      <wsdl:operation name="JaToEnLookup">
78
         <wsdl:input message="tns:LookupJERequest" />
79
         <wsdl:output message="tns:LookupResponse" />
80
         <wsdl:fault message="tns:EntryNotFoundFault" 
81
            name="EntryNotFoundFault"/>
82
      </wsdl:operation>
83
      <wsdl:operation name="EnToJaLookup">
84
         <wsdl:input message="tns:LookupEJRequest" />
85
         <wsdl:output message="tns:LookupResponse" />
86
         <wsdl:fault message="tns:EntryNotFoundFault" 
87
            name="EntryNotFoundFault"/>
88
      </wsdl:operation>
89
      <wsdl:operation name="AddWordEntry">
90
         <wsdl:input message="tns:AddWordEntryRequest" />
91
         <wsdl:output message="tns:AddWordEntryResponse" />
92
         <wsdl:fault message="tns:EntryAlreadyExistsFault" 
93
            name="EntryAlreadyExistsFault"/>
94
      </wsdl:operation>
95
   </wsdl:portType>
96
   <wsdl:binding name="WordLookupBinding" type="tns:WordLookupPortType">
97
      <soap:binding style="document"
98
         transport="http://schemas.xmlsoap.org/soap/http" />
99
      <wsdl:operation name="JaToEnLookup">
100
         <soap:operation soapAction=""/>
101
         <wsdl:input><soap:body use="literal"/></wsdl:input>
102
         <wsdl:output><soap:body use="literal"/></wsdl:output>
103
         <wsdl:fault name="EntryNotFoundFault">
104
             <soap:fault name="EntryNotFoundFault" use="literal" />
105
         </wsdl:fault>
106
      </wsdl:operation>
107
      <wsdl:operation name="EnToJaLookup">
108
         <soap:operation soapAction=""/>
109
         <wsdl:input><soap:body use="literal"/></wsdl:input>
110
         <wsdl:output><soap:body use="literal"/></wsdl:output>
111
         <wsdl:fault name="EntryNotFoundFault">
112
             <soap:fault name="EntryNotFoundFault" use="literal" />
113
         </wsdl:fault>
114
      </wsdl:operation>
115
      <wsdl:operation name="AddWordEntry">
116
         <soap:operation soapAction=""/>
117
         <wsdl:input><soap:body use="literal"/></wsdl:input>
118
         <wsdl:output><soap:body use="literal"/></wsdl:output>
119
         <wsdl:fault name="EntryAlreadyExistsFault">
120
             <soap:fault name="EntryAlreadyExistsFault" use="literal" />
121
         </wsdl:fault>
122
      </wsdl:operation>
123
   </wsdl:binding>
124
   <wsdl:service name="WordLookupService">
125
      <wsdl:port name="WordLookupPort" binding="tns:WordLookupBinding">
126
         <soap:address 
127
            location="http://localhost:8080/wordlookup/services/wordlookup"/>
128
      </wsdl:port>
129
   </wsdl:service>
130
</wsdl:definitions>
dictionaryService-CxfTest/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3

  
4
  <modelVersion>4.0.0</modelVersion>
5
  <groupId>com.mycompany.webservice</groupId>
6
  <artifactId>DictionaryServiceSample</artifactId>
7
  <version>1.0-SNAPSHOT</version>
8
  <name>Dictionary Web Service (Apache CXF Version)</name>
9
  <url>http://maven.apache.org</url>
10
  <packaging>pom</packaging>
11
  
12
   <repositories>
13
      <repository>
14
         <id>apache.incubating.releases</id>
15
         <name>Apache Incubating Release Distribution Repository</name>
16
         <url>
17
            http://people.apache.org/repo/m2-incubating-repository
18
         </url>
19
      </repository>
20
      <repository>
21
         <id>java.net</id>
22
         <url>http://download.java.net/maven/1/</url>
23
         <layout>legacy</layout>
24
      </repository>
25
   </repositories>
26

  
27
   <pluginRepositories>
28
      <pluginRepository>
29
         <id>apache-plugin-snapshots</id>
30
         <name>Apache Maven Plugin Snapshots</name>
31
         <url>http://people.apache.org/repo/m2-snapshot-repository</url>
32
         <releases>
33
            <enabled>false</enabled>
34
         </releases>
35
         <snapshots>
36
            <enabled>true</enabled>
37
         </snapshots>
38
      </pluginRepository>
39
      <pluginRepository>
40
         <id>apache-plugin-incubating</id>
41
         <name>Apache Plugin Incubating Repository</name>
42
         <url>
43
            http://people.apache.org/repo/m2-incubating-repository/
44
         </url>
45
      </pluginRepository>
46
   </pluginRepositories>
47

  
48
   <properties>
49
      <cxf.version>2.0.3-incubator</cxf.version>
50
   </properties>
51
   <dependencies>
52
      <!-- Depending on your requirements you may need more or less modules from cxf -->
53
      <dependency>
54
         <groupId>org.apache.cxf</groupId>
55
         <artifactId>cxf-rt-frontend-jaxws</artifactId>
56
         <version>${cxf.version}</version>
57
      </dependency>
58
        <dependency>
59
         <groupId>org.apache.cxf</groupId>
60
         <artifactId>cxf-rt-transports-http</artifactId>
61
         <version>${cxf.version}</version>
62
      </dependency>
63
    <dependency>
64
      <groupId>junit</groupId>
65
      <artifactId>junit</artifactId>
66
      <version>3.8.1</version>
67
      <scope>test</scope>
68
    </dependency>
69
   </dependencies>
70

  
71
    <modules>
72
        <module>jaxws</module>
73
        <module>client</module>
74
        <module>service</module>
75
    </modules>
76

  
77
  <build>
78
    <plugins>
79
         <plugin>
80
            <artifactId>maven-compiler-plugin</artifactId>
81
            <configuration>
82
               <source>1.5</source>
83
               <target>1.5</target>
84
            </configuration>
85
         </plugin>
86
    </plugins>
87
    <finalName>service</finalName>
88
  </build>
89
</project>
dictionaryService-CxfTest/service/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0"
2
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4

  
5
   <modelVersion>4.0.0</modelVersion>
6
   <parent>
7
      <groupId>com.mycompany.webservice</groupId>
8
      <artifactId>DictionaryServiceSample</artifactId>
9
      <version>1.0-SNAPSHOT</version>
10
      <relativePath>../dictionaryService-CxfTest/pom.xml</relativePath>
11
   </parent>
12
   
13
   <artifactId>service</artifactId>
14
   <name>Web Application for Dictionary Service</name>
15
   <packaging>war</packaging>
16
   <url>http://maven.apache.org</url>
17

  
18
   <dependencies>
19
      <dependency>
20
         <groupId>mysql</groupId>
21
         <artifactId>mysql-connector-java</artifactId>
22
         <version>5.0.5</version>
23
      </dependency>
24
      <dependency>
25
         <groupId>com.mycompany.webservice</groupId>
26
         <artifactId>jaxws</artifactId>
27
         <version>1.0-SNAPSHOT</version>
28
      </dependency>
29
   </dependencies>
30

  
31
   <build>
32
      <plugins>
33
         <plugin><!--use mvn tomcat:deploy -->
34
            <groupId>org.codehaus.mojo</groupId>
35
            <artifactId>tomcat-maven-plugin</artifactId>
36
            <configuration>
37
               <server>tomcat-local</server>
38
               <!--url>Place URL if different from http://localhost:8080/manager</url-->
39
            </configuration>
40
         </plugin>
41
      </plugins>
42
      <finalName>wordlookup</finalName>
43
   </build>
44
</project>
dictionaryService-CxfTest/service/src/main/java/com/mycompany/webservice/service/WordLookupPortTypeImpl.java
1
package com.mycompany.webservice.service;
2

  
3
import java.sql.Connection;
4
import java.sql.DriverManager;
5
import java.sql.PreparedStatement;
6
import java.sql.ResultSet;
7
import java.sql.SQLException;
8
import java.sql.Statement;
9

  
10
import org.example.wordlookup.BasicFault;
11
import org.example.wordlookup.EntryAlreadyExistsFault;
12
import org.example.wordlookup.EntryNotFoundFault;
13
import org.example.wordlookup.LookupEJ;
14
import org.example.wordlookup.LookupJE;
15
import org.example.wordlookup.LookupResponse;
16
import org.example.wordlookup.WordLookupPortType;
17

  
18
@javax.jws.WebService(portName = "WordLookupPort", serviceName = "WordLookupService", 
19
        targetNamespace = "http://www.example.org/WordLookup", 
20
        endpointInterface="org.example.wordlookup.WordLookupPortType")
21
public class WordLookupPortTypeImpl implements WordLookupPortType {
22

  
23
    private static Connection dbConn;    
24
    
25
    static {
26
        try {
27
            DriverManager.registerDriver(
28
                    new com.mysql.jdbc.Driver());
29

  
30
            dbConn = DriverManager.getConnection( 
31
                "jdbc:mysql://localhost/LangLookup",    
32
                "root", ""); 
33
        } catch (SQLException e) {
34
            e.printStackTrace();
35
            throw new IllegalStateException(
36
                "Database connection cannot be made: " +
37
                "Code: " + e.getErrorCode() + "; Message: " + e.getMessage());
38
        }
39
    }
40
    
41
    public String addWordEntry(String enWord, String jaWord)
42
            throws EntryAlreadyExistsFault {
43
        
44
        try {
45
            Statement stmt = dbConn.createStatement();
46
            stmt.execute("insert into wordlookup(en_word, ja_word) values " +
47
                    "('" + enWord.toUpperCase() + "', '" 
48
                    + jaWord.toUpperCase() + "')");
49
            dbConn.commit();
50
        } catch (SQLException e) {
51
            BasicFault bf = new BasicFault();
52
            bf.setErrorMessage("Cannot add to dictionary: " +
53
            		"one or both words already exist");
54
            bf.setErrorDetails("Attempted to add: (" + enWord +
55
                    ", " + jaWord + ")");
56
            
57
            throw new EntryAlreadyExistsFault("SQL Error -- Code: " 
58
               + e.getErrorCode(), bf);
59
        }
60
        return "Successful!";
61
    }
62

  
63
    public LookupResponse enToJaLookup(LookupEJ parameters)
64
            throws EntryNotFoundFault {
65
        return dictionaryLookup(parameters.getWordToTranslate(),
66
                "JA");
67
    }
68

  
69
    public LookupResponse jaToEnLookup(LookupJE parameters)
70
            throws EntryNotFoundFault {
71
        return dictionaryLookup(parameters.getWordToTranslate(),
72
                "EN");
73
    }
74
    
75
    private LookupResponse dictionaryLookup(String inWord,
76
            String toLang) throws EntryNotFoundFault {
77

  
78
        String outWord = null;
79

  
80
        String sqlStr = ("JA".equals(toLang)) ?
81
            "SELECT ja_word as out_word " +
82
            "from APP.wordlookup where en_word = UPPER(?)"
83
        :
84
            "SELECT en_word as out_word " +
85
            "from APP.wordlookup where ja_word = UPPER(?)";
86
        
87
        String notFoundMsg = ("JA".equals(toLang) ? "Japanese" : "English") +
88
            " word for \"" + inWord + "\" could not be found";
89
        
90
        try {
91
            PreparedStatement pstmt = dbConn.prepareStatement(sqlStr);
92
            pstmt.setString(1, inWord);
93
            ResultSet rs = pstmt.executeQuery();
94

  
95
            if (rs.next()) {
96
                outWord = rs.getString("out_word");
97
            } else {
98
                BasicFault bf = new BasicFault();
99
                bf.setErrorMessage(notFoundMsg);
100
                bf.setErrorDetails(inWord);
101
                throw new EntryNotFoundFault("Entry Not Found", bf);
102
            }
103
            rs.close();
104
            pstmt.close();
105

  
106
        } catch (SQLException e) {
107
            BasicFault bf = new BasicFault();
108
            bf.setErrorMessage(notFoundMsg);
109
            bf.setErrorDetails(inWord);
110
            throw new EntryNotFoundFault(e.getMessage(), bf);
111
        }
112
        LookupResponse lr = new LookupResponse();
113
        lr.setTranslatedWord(outWord);
114
        return lr;
115
    }
116
}
dictionaryService-CxfTest/service/src/main/webapp/WEB-INF/cxf-servlet.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns="http://www.springframework.org/schema/beans"
3
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
      xmlns:jaxws="http://cxf.apache.org/jaxws"
5
      xmlns:soap="http://cxf.apache.org/bindings/soap"
6
      xsi:schemaLocation="
7
http://www.springframework.org/schema/beans 
8
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
9
http://cxf.apache.org/bindings/soap
10
http://cxf.apache.org/schemas/configuration/soap.xsd
11
http://cxf.apache.org/jaxws
12
http://cxf.apache.org/schemas/jaxws.xsd">
13

  
14
    <jaxws:endpoint 
15
        id="wordlookup"
16
        implementor="com.mycompany.webservice.service.WordLookupPortTypeImpl"
17
        wsdlLocation="WEB-INF/wsdl/WordLookup.wsdl"
18
        address="/wordlookup">
19
        <!--jaxws:features>
20
 		   <bean class="org.apache.cxf.feature.LoggingFeature"/>
21
        </jaxws:features-->
22
    </jaxws:endpoint>
23
</beans>
dictionaryService-CxfTest/service/src/main/webapp/WEB-INF/sun-jaxws.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"
3
    version="2.0">
4

  
5
    <endpoint
6
        name="Endpoint_for_WordLookup"
7
        interface="org.example.wordlookup.WordLookupPortType"
8
        implementation="com.mycompany.webservice.service.WordLookupPortTypeImpl"
9
        wsdl="WEB-INF/wsdl/WordLookup.wsdl"
10
        service="{http://www.example.org/WordLookup}WordLookupService"
11
        port="{http://www.example.org/WordLookup}WordLookupPort"
12
        url-pattern="/services/wordlookup" />       
13
</endpoints>
dictionaryService-CxfTest/service/src/main/webapp/WEB-INF/web.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<web-app version="2.4" mlns="http://java.sun.com/xml/ns/j2ee"
3
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
5
         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
6
    <description>Word Lookup Web Service</description>
7
    <display-name>word lookup</display-name>
8
    <!-- Uncomment below listener if using Metro 
9
    <listener>
10
        <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
11
    </listener-->
12
    <servlet>
13
        <description>Word Lookup</description>
14
        <display-name>wordlookup</display-name>
15
        <servlet-name>WebServicePort</servlet-name>
16
        <!-- Switch to WSServlet below if using Metro -->
17
        <servlet-class>
18
            org.apache.cxf.transport.servlet.CXFServlet 
19
           <!-- com.sun.xml.ws.transport.http.servlet.WSServlet -->
20
        </servlet-class>
21
        <load-on-startup>1</load-on-startup>
22
    </servlet>
23
    <servlet-mapping>
24
        <servlet-name>WebServicePort</servlet-name>
25
        <url-pattern>/services/*</url-pattern>
26
    </servlet-mapping>
27
    <session-config>
28
        <session-timeout>60</session-timeout>
29
    </session-config>
30
</web-app>
dictionaryService-CxfTest/service/src/main/webapp/WEB-INF/wsdl/WordLookup.wsdl
1
<?xml version="1.0" encoding="UTF-8"?>
2
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
3
   xmlns:tns="http://www.example.org/WordLookup"
4
   xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
5
   xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="WordLookup"
6
   targetNamespace="http://www.example.org/WordLookup">
7
   <wsdl:types>
8
      <xsd:schema targetNamespace="http://www.example.org/WordLookup">
9
         <xsd:element name="LookupEJ">
10
            <xsd:complexType>
11
               <xsd:sequence>
12
                  <xsd:element name="wordToTranslate" type="xsd:string"/>
13
               </xsd:sequence>
14
            </xsd:complexType>
15
         </xsd:element>
16
         <xsd:element name="LookupJE">
17
            <xsd:complexType>
18
               <xsd:sequence>
19
                  <xsd:element name="wordToTranslate" type="xsd:string"/>
20
               </xsd:sequence>
21
            </xsd:complexType>
22
         </xsd:element>
23
         <xsd:element name="LookupResponse">
24
            <xsd:complexType>
25
               <xsd:sequence>
26
                  <xsd:element name="translatedWord" type="xsd:string" />
27
               </xsd:sequence>
28
            </xsd:complexType>
29
         </xsd:element>
30
         <xsd:element name="AddWordEntry">
31
            <xsd:complexType>
32
               <xsd:sequence>
33
                  <xsd:element name="englishWord" type="xsd:string" />
34
                  <xsd:element name="japaneseWord" type="xsd:string" />
35
               </xsd:sequence>
36
            </xsd:complexType>
37
         </xsd:element>
38
         <xsd:element name="AddWordEntryResponse">
39
            <xsd:complexType>
40
               <xsd:sequence>
41
                  <xsd:element name="results" type="xsd:string" />
42
               </xsd:sequence>
43
            </xsd:complexType>
44
         </xsd:element>
45
         <xsd:element name="BasicFault">
46
            <xsd:complexType>
47
               <xsd:sequence>
48
                  <xsd:element name="errorMessage" type="xsd:string"/>
49
                  <xsd:element name="errorDetails" type="xsd:string"/>
50
               </xsd:sequence>
51
            </xsd:complexType>
52
         </xsd:element>         
53
      </xsd:schema>
54
   </wsdl:types>
55
   <wsdl:message name="LookupEJRequest">
56
      <wsdl:part element="tns:LookupEJ" name="parameters" />
57
   </wsdl:message>
58
   <wsdl:message name="LookupJERequest">
59
      <wsdl:part element="tns:LookupJE" name="parameters" />
60
   </wsdl:message>
61
   <wsdl:message name="LookupResponse">
62
      <wsdl:part element="tns:LookupResponse" name="parameters" />
63
   </wsdl:message>
64
   <wsdl:message name="EntryNotFoundFault">
65
      <wsdl:part element="tns:BasicFault" name="BasicFault"/>
66
   </wsdl:message>
67
   <wsdl:message name="EntryAlreadyExistsFault">
68
      <wsdl:part element="tns:BasicFault" name="BasicFault"/>
69
   </wsdl:message>
70
   <wsdl:message name="AddWordEntryRequest">
71
      <wsdl:part element="tns:AddWordEntry" name="parameters" />
72
   </wsdl:message>
73
   <wsdl:message name="AddWordEntryResponse">
74
      <wsdl:part element="tns:AddWordEntryResponse" name="parameters" />
75
   </wsdl:message>
76
   <wsdl:portType name="WordLookupPortType">
77
      <wsdl:operation name="JaToEnLookup">
78
         <wsdl:input message="tns:LookupJERequest" />
79
         <wsdl:output message="tns:LookupResponse" />
80
         <wsdl:fault message="tns:EntryNotFoundFault" 
81
            name="EntryNotFoundFault"/>
82
      </wsdl:operation>
83
      <wsdl:operation name="EnToJaLookup">
84
         <wsdl:input message="tns:LookupEJRequest" />
85
         <wsdl:output message="tns:LookupResponse" />
86
         <wsdl:fault message="tns:EntryNotFoundFault" 
87
            name="EntryNotFoundFault"/>
88
      </wsdl:operation>
89
      <wsdl:operation name="AddWordEntry">
90
         <wsdl:input message="tns:AddWordEntryRequest" />
91
         <wsdl:output message="tns:AddWordEntryResponse" />
92
         <wsdl:fault message="tns:EntryAlreadyExistsFault" 
93
            name="EntryAlreadyExistsFault"/>
94
      </wsdl:operation>
95
   </wsdl:portType>
96
   <wsdl:binding name="WordLookupBinding" type="tns:WordLookupPortType">
97
      <soap:binding style="document"
98
         transport="http://schemas.xmlsoap.org/soap/http" />
99
      <wsdl:operation name="JaToEnLookup">
100
         <soap:operation soapAction=""/>
101
         <wsdl:input><soap:body use="literal"/></wsdl:input>
102
         <wsdl:output><soap:body use="literal"/></wsdl:output>
103
         <wsdl:fault name="EntryNotFoundFault">
104
             <soap:fault name="EntryNotFoundFault" use="literal" />
105
         </wsdl:fault>
106
      </wsdl:operation>
107
      <wsdl:operation name="EnToJaLookup">
108
         <soap:operation soapAction=""/>
109
         <wsdl:input><soap:body use="literal"/></wsdl:input>
110
         <wsdl:output><soap:body use="literal"/></wsdl:output>
111
         <wsdl:fault name="EntryNotFoundFault">
112
             <soap:fault name="EntryNotFoundFault" use="literal" />
113
         </wsdl:fault>
114
      </wsdl:operation>
115
      <wsdl:operation name="AddWordEntry">
116
         <soap:operation soapAction=""/>
117
         <wsdl:input><soap:body use="literal"/></wsdl:input>
118
         <wsdl:output><soap:body use="literal"/></wsdl:output>
119
         <wsdl:fault name="EntryAlreadyExistsFault">
120
             <soap:fault name="EntryAlreadyExistsFault" use="literal" />
121
         </wsdl:fault>
122
      </wsdl:operation>
123
   </wsdl:binding>
124
   <wsdl:service name="WordLookupService">
125
      <wsdl:port name="WordLookupPort" binding="tns:WordLookupBinding">
126
         <soap:address 
127
            location="http://localhost:8080/wordlookup/services/wordlookup"/>
128
      </wsdl:port>
129
   </wsdl:service>
130
</wsdl:definitions>

Also available in: Unified diff