Skip to content

Commit

Permalink
Init CXF extension
Browse files Browse the repository at this point in the history
Add cxf server side extension
Docs
Unit tests

fix quarkusio#4005
  • Loading branch information
Dufgui authored and olivier dufour committed Nov 18, 2019
1 parent 0a35334 commit f15523b
Show file tree
Hide file tree
Showing 23 changed files with 1,005 additions and 0 deletions.
5 changes: 5 additions & 0 deletions bom/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@
<artifactId>quarkus-resteasy-jaxb-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-cxf-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-jwt-deployment</artifactId>
Expand Down
23 changes: 23 additions & 0 deletions bom/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@
<antlr.version>4.7.2</antlr.version>
<quarkus-security.version>1.0.0.Final</quarkus-security.version>
<keycloak.version>7.0.1</keycloak.version>
<javax.interceptor-api.version>1.2</javax.interceptor-api.version>
<cxf.version>3.3.3</cxf.version>
<jaxws.version>2.0.0.Final</jaxws.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -531,6 +534,11 @@
<artifactId>quarkus-resteasy-server-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-cxf</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-narayana-jta</artifactId>
Expand Down Expand Up @@ -1240,6 +1248,16 @@
<artifactId>artemis-jms-client</artifactId>
<version>${artemis.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand Down Expand Up @@ -1556,6 +1574,11 @@
<artifactId>stm</artifactId>
<version>${narayana.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.xml.ws</groupId>
<artifactId>jboss-jaxws-api_2.3_spec</artifactId>
<version>${jaxws.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public final class FeatureBuildItem extends MultiBuildItem {
public static final String ARTEMIS_CORE = "artemis-core";
public static final String ARTEMIS_JMS = "artemis-jms";
public static final String CDI = "cdi";
public static final String CXF = "cxf";
public static final String DYNAMODB = "dynamodb";
public static final String ELASTICSEARCH_REST_CLIENT = "elasticsearch-rest-client";
public static final String FLYWAY = "flyway";
Expand Down
1 change: 1 addition & 0 deletions docs/src/main/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ include::quarkus-intro.adoc[tag=intro]
* link:jms.html[Using Artemis JMS Client]
* link:reactive-routes.adoc[Using Reactive Routes]
* link:camel.adoc[Apache Camel]
* link:soap-web-service-guide.html[Writing SOAP Web Services]

* link:faq.html[FAQs]

Expand Down
244 changes: 244 additions & 0 deletions docs/src/main/asciidoc/soap-web-service-guide.adoc
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.

63 changes: 63 additions & 0 deletions extensions/cxf/deployment/pom.xml
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>
Loading

0 comments on commit f15523b

Please sign in to comment.