forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cxf server side extension Docs Unit tests fix quarkusio#4005
- Loading branch information
Showing
23 changed files
with
1,005 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,244 @@ | ||
//// | ||
This guide is maintained in the main Quarkus repository | ||
and pull requests should be submitted there: | ||
https://github.com/quarkusio/quarkus/tree/master/docs/src/main/asciidoc | ||
//// | ||
= Quarkus - Writing Soap Web Services | ||
|
||
include::./attributes.adoc[] | ||
|
||
SOAP (Simple Object Access Protocol) is an exchange protocole used by old web service before the developement of REST technology. | ||
|
||
In this guide, we see how you can get your web services to consume and produce SOAP payloads. | ||
|
||
== Prerequisites | ||
|
||
To complete this guide, you need: | ||
|
||
* less than 15 minutes | ||
* an IDE | ||
* JDK 1.8+ installed with `JAVA_HOME` configured appropriately | ||
* Apache Maven 3.5.3+ | ||
|
||
== Architecture | ||
|
||
The application built in this guide is quite simple: the user can add elements in a list using a form and the list is updated. | ||
|
||
All the information between the browser and the server are formatted as SOAP. | ||
|
||
== Solution | ||
|
||
We recommend that you follow the instructions in the next sections and create the application step by step. | ||
However, you can go right to the completed example. | ||
|
||
Clone the Git repository: `git clone {quickstarts-clone-url}`, or download an {quickstarts-archive-url}[archive]. | ||
|
||
The solution is located in the `cxf` {quickstarts-tree-url}/cxf[directory]. | ||
|
||
== Creating the Maven project | ||
|
||
First, we need a new project. Create a new project with the following command: | ||
|
||
[source,shell,subs=attributes+] | ||
---- | ||
mvn io.quarkus:quarkus-maven-plugin:{quarkus-version}:create \ | ||
-DprojectGroupId=org.acme \ | ||
-DprojectArtifactId=jaxws \ | ||
-Dextensions="cxf" | ||
---- | ||
|
||
This command generates a Maven structure importing the CXF/JAX-WS extensions. | ||
|
||
== Creating your first SOAP Web service | ||
|
||
In this example, we will create an application to manage a list of fruits. | ||
|
||
First, let's create the `Fruit` bean as follows: | ||
|
||
[source,java] | ||
---- | ||
package org.acme.cxf; | ||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; | ||
@XmlJavaTypeAdapter(FruitAdapter.class) | ||
public interface Fruit { | ||
String getName(); | ||
String getDescription(); | ||
} | ||
---- | ||
|
||
And it's implementation `FruitImpl`: | ||
|
||
[source,java] | ||
---- | ||
package org.acme.cxf.impl; | ||
import java.util.Objects; | ||
import org.acme.cxf.Fruit; | ||
import javax.xml.bind.annotation.XmlType; | ||
@XmlType(name = "Fruit") | ||
public class FruitImpl implements Fruit { | ||
private String name; | ||
private String description; | ||
public FruitImpl() { | ||
} | ||
public FruitImpl(String name, String description) { | ||
this.name = name; | ||
this.description = description; | ||
} | ||
public String getName() { | ||
return name; | ||
} | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
public String getDescription() { | ||
return description; | ||
} | ||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
@Override | ||
public boolean equals(Object obj) { | ||
if (!(obj instanceof Fruit)) { | ||
return false; | ||
} | ||
Fruit other = (Fruit) obj; | ||
return Objects.equals(other.getName(), this.getName()); | ||
} | ||
@Override | ||
public int hashCode() { | ||
return Objects.hash(this.getName()); | ||
} | ||
} | ||
---- | ||
|
||
To finish about the data the `FruitAdapter` | ||
|
||
[source,java] | ||
---- | ||
package org.acme.cxf; | ||
import javax.xml.bind.annotation.adapters.XmlAdapter; | ||
import org.acme.cxf.Fruit; | ||
import org.acme.cxf.impl.FruitImpl; | ||
public class FruitAdapter extends XmlAdapter<FruitImpl, Fruit> { | ||
public FruitImpl marshal(Fruit Fruit) throws Exception { | ||
if (Fruit instanceof FruitImpl) { | ||
return (FruitImpl) Fruit; | ||
} | ||
return new FruitImpl(Fruit.getName(), Fruit.getDescription()); | ||
} | ||
public Fruit unmarshal(FruitImpl Fruit) throws Exception { | ||
return Fruit; | ||
} | ||
} | ||
---- | ||
|
||
|
||
|
||
Now, create the `org.acme.cxf.soap.FruitWebService` class as follows: | ||
|
||
[source,java] | ||
---- | ||
package org.acme.cxf; | ||
import java.util.Set; | ||
import javax.jws.WebMethod; | ||
import javax.jws.WebParam; | ||
import javax.jws.WebService; | ||
@WebService | ||
public interface FruitWebService { | ||
@WebMethod | ||
Set<Fruit> list(); | ||
@WebMethod | ||
Set<Fruit> add(Fruit fruit); | ||
@WebMethod | ||
Set<Fruit> delete(Fruit fruit); | ||
} | ||
---- | ||
|
||
Then, create the `org.acme.cxf.soap.impl.FruitWebServiceImpl` class as follows: | ||
|
||
[source,java] | ||
---- | ||
package org.acme.cxf.impl; | ||
import java.util.Collections; | ||
import java.util.LinkedHashMap; | ||
import java.util.Set; | ||
import javax.jws.WebService; | ||
import org.acme.cxf.Fruit; | ||
import org.acme.cxf.FruitWebService; | ||
@WebService(endpointInterface = "org.acme.cxf.FruitWebService") | ||
public class FruitWebServiceImpl implements FruitWebService { | ||
private Set<Fruit> fruits = Collections.newSetFromMap(Collections.synchronizedMap(new LinkedHashMap<>())); | ||
public FruitWebServiceImpl() { | ||
fruits.add(new FruitImpl("Apple", "Winter fruit")); | ||
fruits.add(new FruitImpl("Pineapple", "Tropical fruit")); | ||
} | ||
@Override | ||
public Set<Fruit> list() { | ||
return fruits; | ||
} | ||
@Override | ||
public Set<Fruit> add(Fruit fruit) { | ||
fruits.add(fruit); | ||
return fruits; | ||
} | ||
@Override | ||
public Set<Fruit> delete(Fruit fruit) { | ||
fruits.remove(fruit); | ||
return fruits; | ||
} | ||
} | ||
---- | ||
|
||
The implementation is pretty straightforward and you just need to define your endpoints using the application.properties`. | ||
|
||
[source,properties] | ||
---- | ||
quarkus.cxf.path=/cxf | ||
quarkus.cxf.webservice."/fruit"=org.acme.cxf.impl.FruitWebServiceImpl | ||
---- | ||
|
||
|
||
== Conclusion | ||
|
||
Creating SOAP Web services with Quarkus is easy as it relies on proven and well known technologies. | ||
|
||
As usual, Quarkus further simplifies things under the hood when running your application as a native executable. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>quarkus-cxf-parent</artifactId> | ||
<groupId>io.quarkus</groupId> | ||
<version>999-SNAPSHOT</version> | ||
<relativePath>../</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>quarkus-cxf-deployment</artifactId> | ||
<name>Quarkus - CXF - Deployment</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-core-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-cxf</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-undertow-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.spec.javax.xml.ws</groupId> | ||
<artifactId>jboss-jaxws-api_2.3_spec</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5-internal</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-processor</artifactId> | ||
<version>${project.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
Oops, something went wrong.