Skip to content

Commit 44df212

Browse files
committed
Merge pull request #203 from fegalo/jaxws_first_example
JAX-WS first example
2 parents 29b3bb3 + fe41ecf commit 44df212

File tree

11 files changed

+632
-0
lines changed

11 files changed

+632
-0
lines changed

jaxws/jaxws-client/pom.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>org.javaee7.jaxws</groupId>
6+
<artifactId>jaxws-samples</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<relativePath>../pom.xml</relativePath>
9+
</parent>
10+
<artifactId>jaxws-client</artifactId>
11+
<packaging>war</packaging>
12+
<build>
13+
<finalName>jaxws-client</finalName>
14+
<plugins>
15+
<plugin>
16+
<!-- wsimport for web service classes generation -->
17+
<groupId>org.codehaus.mojo</groupId>
18+
<artifactId>jaxws-maven-plugin</artifactId>
19+
<version>1.11</version>
20+
<executions>
21+
<execution>
22+
<phase>generate-sources</phase>
23+
<goals>
24+
<goal>wsimport</goal>
25+
</goals>
26+
<configuration>
27+
<packageName>org.javaee7.jaxws.client.gen</packageName>
28+
<wsdlFiles>
29+
<wsdlFile>../../../jaxws-endpoint/src/main/webapp/WEB-INF/wsdl/EBookStoreImplService.wsdl</wsdlFile>
30+
</wsdlFiles>
31+
<wsdlLocation>http://localhost:8080/jaxws-endpoint/EBookStoreImplService?wsdl</wsdlLocation>
32+
<verbose>true</verbose>
33+
<sourceDestDir>${basedir}/src/main/java</sourceDestDir>
34+
<target>2.1</target>
35+
</configuration>
36+
</execution>
37+
</executions>
38+
</plugin>
39+
</plugins>
40+
</build>
41+
</project>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package org.javaee7.jaxws.client;
2+
3+
import static org.junit.Assert.*;
4+
5+
import java.net.MalformedURLException;
6+
import java.net.URL;
7+
import java.util.Arrays;
8+
import java.util.List;
9+
10+
import javax.xml.namespace.QName;
11+
12+
import org.javaee7.jaxws.client.gen.EBook;
13+
import org.javaee7.jaxws.client.gen.EBookStore;
14+
import org.javaee7.jaxws.client.gen.EBookStoreImplService;
15+
16+
import org.jboss.arquillian.container.test.api.Deployment;
17+
import org.jboss.arquillian.junit.Arquillian;
18+
import org.jboss.arquillian.test.api.ArquillianResource;
19+
import org.jboss.shrinkwrap.resolver.api.maven.archive.importer.MavenImporter;
20+
import org.jboss.shrinkwrap.api.spec.WebArchive;
21+
import org.jboss.shrinkwrap.api.ArchivePaths;
22+
import org.jboss.shrinkwrap.api.ShrinkWrap;
23+
24+
import org.junit.Before;
25+
import org.junit.FixMethodOrder;
26+
import org.junit.Test;
27+
import org.junit.runner.RunWith;
28+
import org.junit.runners.MethodSorters;
29+
/**
30+
* @author Fermin Gallego
31+
*/
32+
@RunWith(Arquillian.class)
33+
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
34+
public class EBookStoreClientSampleTest {
35+
private static EBookStoreImplService eBookStoreService;
36+
37+
/**
38+
* Method for creating and deploying the war file from 'jaxws-endpoint' project,
39+
* which contains the web service to be tested.
40+
*
41+
* @return a war file
42+
*/
43+
@Deployment(testable = false)
44+
public static WebArchive createDeployment() {
45+
return ShrinkWrap.create(MavenImporter.class)
46+
.loadPomFromFile("../jaxws-endpoint/pom.xml")
47+
.importBuildOutput()
48+
.as(WebArchive.class);
49+
}
50+
51+
@ArquillianResource
52+
private URL url;
53+
54+
@Before
55+
public void setUp() throws Exception {
56+
eBookStoreService = new EBookStoreImplService(
57+
new URL(url, "EBookStoreImplService?wsdl"),
58+
new QName("http://endpoint.jaxws.javaee7.org/", "EBookStoreImplService"));
59+
}
60+
61+
@Test
62+
public void test1WelcomeMessage() throws MalformedURLException {
63+
EBookStore eBookStore = eBookStoreService.getEBookStoreImplPort();
64+
String response=eBookStore.welcomeMessage("Jackson");
65+
assertEquals("Welcome to EBookStore WebService, Mr/Mrs Jackson", response);
66+
}
67+
@Test
68+
public void test2SaveAndTakeBook() throws MalformedURLException {
69+
EBookStore eBookStore = eBookStoreService.getPort(EBookStore.class);
70+
71+
EBook eBook=new EBook();
72+
eBook.setTitle("The Jungle Book");
73+
eBook.setNumPages(225);
74+
eBook.setPrice(17.9);
75+
eBookStore.saveBook(eBook);
76+
eBook=new EBook();
77+
78+
eBook.setTitle("Animal Farm");
79+
eBook.setNumPages(113);
80+
eBook.setPrice(22.5);
81+
List<String> notes= Arrays.asList(new String[]{"Great book","Not too bad"});
82+
eBook.getNotes().addAll(notes);
83+
eBookStore.saveBook(eBook);
84+
85+
EBook response=eBookStore.takeBook("Animal Farm");
86+
assertEquals(eBook.getNumPages(),response.getNumPages());
87+
assertEquals(eBook.getPrice(),response.getPrice(),0);
88+
assertEquals(eBook.getTitle(),response.getTitle());
89+
assertEquals(notes,response.getNotes());
90+
91+
}
92+
93+
}

jaxws/jaxws-endpoint/pom.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>org.javaee7.jaxws</groupId>
6+
<artifactId>jaxws-samples</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<relativePath>../pom.xml</relativePath>
9+
</parent>
10+
<artifactId>jaxws-endpoint</artifactId>
11+
<packaging>war</packaging>
12+
<build>
13+
<finalName>jaxws-endpoint</finalName>
14+
<plugins>
15+
<plugin>
16+
<!-- wsgen for wsdl file generation -->
17+
<groupId>org.codehaus.mojo</groupId>
18+
<artifactId>jaxws-maven-plugin</artifactId>
19+
<version>1.11</version>
20+
<executions>
21+
<execution>
22+
<phase>process-classes</phase>
23+
<goals>
24+
<goal>wsgen</goal>
25+
</goals>
26+
<configuration>
27+
<sei>org.javaee7.jaxws.endpoint.EBookStoreImpl</sei>
28+
<genWsdl>true</genWsdl>
29+
<resourceDestDir>${basedir}/src/main/webapp/WEB-INF/wsdl</resourceDestDir>
30+
</configuration>
31+
</execution>
32+
</executions>
33+
</plugin>
34+
</plugins>
35+
</build>
36+
</project>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.javaee7.jaxws.endpoint;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
/**
7+
*
8+
* @author Fermin Gallego
9+
*
10+
*/
11+
public class EBook {
12+
private String title;
13+
private int numPages;
14+
private double price;
15+
private List<String> notes;
16+
17+
public EBook() {
18+
super();
19+
}
20+
public String getTitle() {
21+
return title;
22+
}
23+
public void setTitle(String title) {
24+
this.title = title;
25+
}
26+
public int getNumPages() {
27+
return numPages;
28+
}
29+
public void setNumPages(int numPages) {
30+
this.numPages = numPages;
31+
}
32+
public double getPrice() {
33+
return price;
34+
}
35+
public void setPrice(double price) {
36+
this.price = price;
37+
}
38+
public List<String> getNotes() {
39+
if (notes == null) {
40+
notes = new ArrayList<String>();
41+
}
42+
return notes;
43+
}
44+
public void setNotes(List<String> notes) {
45+
this.notes = notes;
46+
}
47+
48+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.javaee7.jaxws.endpoint;
2+
3+
import java.util.List;
4+
5+
import javax.jws.WebMethod;
6+
import javax.jws.WebService;
7+
8+
/**
9+
*
10+
* @author Fermin Gallego
11+
*
12+
*/
13+
@WebService
14+
public interface EBookStore {
15+
@WebMethod
16+
public String welcomeMessage(String name);
17+
@WebMethod
18+
public List<String> findEBooks(String text);
19+
@WebMethod
20+
public EBook takeBook(String title);
21+
@WebMethod
22+
public void saveBook(EBook eBook);
23+
@WebMethod
24+
public EBook addAppendix(EBook eBook,int appendixPages);
25+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.javaee7.jaxws.endpoint;
2+
3+
import java.util.ArrayList;
4+
import java.util.HashMap;
5+
import java.util.List;
6+
7+
import javax.jws.WebService;
8+
9+
/**
10+
*
11+
* @author Fermin Gallego
12+
*
13+
*/
14+
@WebService(endpointInterface = "org.javaee7.jaxws.endpoint.EBookStore",
15+
serviceName="EBookStoreImplService")
16+
public class EBookStoreImpl implements EBookStore{
17+
18+
private HashMap<String,EBook> eBookCollection=new HashMap<String,EBook>();
19+
20+
@Override
21+
public String welcomeMessage(String name) {
22+
return "Welcome to EBookStore WebService, Mr/Mrs "+name;
23+
}
24+
25+
@Override
26+
public List<String> findEBooks(String text) {
27+
List<String> foundTitles=new ArrayList<String>();
28+
for(String title:eBookCollection.keySet()){
29+
if(title.contains(text)){
30+
foundTitles.add(title);
31+
}
32+
}
33+
return foundTitles;
34+
}
35+
36+
@Override
37+
public EBook takeBook(String title) {
38+
return eBookCollection.get(title);
39+
}
40+
41+
@Override
42+
public void saveBook(EBook eBook) {
43+
eBookCollection.put(eBook.getTitle(), eBook);
44+
45+
}
46+
47+
@Override
48+
public EBook addAppendix(EBook eBook,int appendixPages) {
49+
eBook.setNumPages((eBook.getNumPages()+appendixPages));
50+
eBookCollection.put(eBook.getTitle(), eBook);
51+
return eBook;
52+
}
53+
54+
}

0 commit comments

Comments
 (0)