Skip to content

Commit

Permalink
Init CXF extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Dufgui committed Sep 21, 2019
1 parent 8456e60 commit 6051b4f
Show file tree
Hide file tree
Showing 16 changed files with 497 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 @@ -226,6 +226,11 @@
<artifactId>quarkus-resteasy-jsonb-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
22 changes: 22 additions & 0 deletions bom/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@
<spring-data.version>2.1.9.RELEASE</spring-data.version>
<mvel2.version>2.4.4.Final</mvel2.version>
<mockito.version>3.0.0</mockito.version>
<cxf.version>3.3.3</cxf.version>
<jaxws.version>2.0.0.Final</jaxws.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -463,6 +465,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 @@ -1116,6 +1123,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 @@ -1441,6 +1458,11 @@
<artifactId>narayana-jts-integration</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 @@ -13,6 +13,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
13 changes: 13 additions & 0 deletions devtools/common/src/main/filtered/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -658,5 +658,18 @@
"groupId": "io.quarkus",
"artifactId": "quarkus-vertx",
"guide": "https://quarkus.io/guides/using-vertx"
},
{
"name": "CXF",
"shortName": "jax-ws",
"labels": [
"cxf",
"jaxws",
"web",
"soap"
],
"groupId": "io.quarkus",
"artifactId": "quarkus-cxf",
"guide": "https://quarkus.io/guides/cxf-guide"
}
]
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.cxf.deployment;

import java.util.Map;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigRoot;

@ConfigRoot
final class CxfConfig {

/**
* Set this to override the default path for JAX-RS resources if there are no
* annotated application classes.
*/
@ConfigItem(defaultValue = "/")
String path;

/**
* Choose the path of each web services.
*/
@ConfigItem(name = "webservice")
Map<String, String> webServicesPaths;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package io.quarkus.cxf.deployment;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;

import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.DotName;
import org.jboss.jandex.IndexView;

import io.quarkus.arc.deployment.BeanArchiveIndexBuildItem;
import io.quarkus.arc.deployment.UnremovableBeanBuildItem;
import io.quarkus.cxf.runtime.CXFQuarkusServlet;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.BytecodeTransformerBuildItem;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.substrate.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.substrate.ReflectiveHierarchyBuildItem;
import io.quarkus.deployment.builditem.substrate.RuntimeInitializedClassBuildItem;
import io.quarkus.deployment.builditem.substrate.SubstrateProxyDefinitionBuildItem;
import io.quarkus.deployment.builditem.substrate.SubstrateResourceBuildItem;
import io.quarkus.undertow.deployment.ServletBuildItem;
import io.quarkus.undertow.deployment.ServletInitParamBuildItem;

/**
* Processor that finds JAX-RS classes in the deployment
*/
public class CxfProcessor {

private static final String JAX_WS_CXF_SERVLET = "org.apache.cxf.transport.servlet.CXFNonSpringServlet";

private static final DotName WEBSERVICE_ANNOTATION = DotName.createSimple("javax.jws.WebService");

/**
* JAX-RS configuration.
*/
CxfConfig cxfConfig;

@BuildStep
public void build(
BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchy,
BuildProducer<SubstrateProxyDefinitionBuildItem> proxyDefinition,
BuildProducer<SubstrateResourceBuildItem> resource,
BuildProducer<RuntimeInitializedClassBuildItem> runtimeClasses,
BuildProducer<BytecodeTransformerBuildItem> transformers,
BuildProducer<CxfServerConfigBuildItem> cxfServerConfig,
BuildProducer<UnremovableBeanBuildItem> unremovableBeans,
CombinedIndexBuildItem combinedIndexBuildItem,
BeanArchiveIndexBuildItem beanArchiveIndexBuildItem) throws Exception {
IndexView index = combinedIndexBuildItem.getIndex();

for (AnnotationInstance annotation : index.getAnnotations(WEBSERVICE_ANNOTATION)) {
if (annotation.target().kind() == AnnotationTarget.Kind.CLASS) {
reflectiveClass
.produce(new ReflectiveClassBuildItem(true, true, annotation.target().asClass().name().toString()));
}
}

Map<String, String> cxfInitParameters = new HashMap<>();

cxfServerConfig.produce(new CxfServerConfigBuildItem(cxfConfig.path, cxfInitParameters));
}

@BuildStep
public void build(
Optional<CxfServerConfigBuildItem> cxfServerConfig,
BuildProducer<FeatureBuildItem> feature,
BuildProducer<ServletBuildItem> servlet,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
BuildProducer<ServletInitParamBuildItem> servletInitParameters) throws Exception {
feature.produce(new FeatureBuildItem(FeatureBuildItem.CXF));

if (cxfServerConfig.isPresent()) {
String path = cxfServerConfig.get().getPath();

String mappingPath = getMappingPath(path);
servlet.produce(ServletBuildItem.builder(JAX_WS_CXF_SERVLET, CXFQuarkusServlet.class.getName())
.setLoadOnStartup(1).addMapping(mappingPath).setAsyncSupported(true).build());
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, CXFQuarkusServlet.class.getName()));

for (Entry<String, String> initParameter : cxfServerConfig.get().getInitParameters().entrySet()) {
servletInitParameters.produce(new ServletInitParamBuildItem(initParameter.getKey(), initParameter.getValue()));
}

for (Entry<String, String> webServicesByPath : cxfConfig.webServicesPaths.entrySet()) {
CXFQuarkusServlet.publish(webServicesByPath.getKey(), webServicesByPath.getValue());
}
}
}

private String getMappingPath(String path) {
String mappingPath;
if (path.endsWith("/")) {
mappingPath = path + "*";
} else {
mappingPath = path + "/*";
}
return mappingPath;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkus.cxf.deployment;

import java.util.Map;

import io.quarkus.builder.item.SimpleBuildItem;

/**
* A build item that represents the configuration of the RESTEasy server.
*/
public final class CxfServerConfigBuildItem extends SimpleBuildItem {

private final String path;

private final Map<String, String> initParameters;

public CxfServerConfigBuildItem(String path, Map<String, String> initParameters) {
this.path = path;
this.initParameters = initParameters;
}

public String getPath() {
return path;
}

public Map<String, String> getInitParameters() {
return initParameters;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package io.quarkus.cxf.deployment.test;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.function.Supplier;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.soap.SOAPBinding;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusDevModeTest;

public class CxfServiceTest {

@RegisterExtension
public static final QuarkusDevModeTest test = new QuarkusDevModeTest()
.setArchiveProducer(new Supplier<JavaArchive>() {
@Override
public JavaArchive get() {
return ShrinkWrap.create(JavaArchive.class)
.addClass(HelloWebServiceImpl.class)
.addClass(HelloWebService.class)
.addAsResource("application.properties");
}
});

private static QName SERVICE_NAME = new QName("http://test.deployment.cxf.quarkus.io/", "HelloWebService");
private static QName PORT_NAME = new QName("http://test.deployment.cxf.quarkus.io/", "HelloWebServicePort");

private Service service;
private HelloWebService helloProxy;
private HelloWebServiceImpl helloImpl;

{
service = Service.create(SERVICE_NAME);
final String endpointAddress = "http://localhost:8080/hello";
service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
}

@BeforeEach
public void reinstantiateBaeldungInstances() {
helloImpl = new HelloWebServiceImpl();
helloProxy = service.getPort(PORT_NAME, HelloWebService.class);
}

@Test
public void whenUsingHelloMethod_thenCorrect() {
final String endpointResponse = helloProxy.sayHi("Quarkus");
final String localResponse = helloImpl.sayHi("Quarkus");
assertEquals(localResponse, endpointResponse);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.quarkus.cxf.deployment.test;

import javax.jws.WebService;

@WebService
public interface HelloWebService {

String sayHi(String name);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.quarkus.cxf.deployment.test;

import javax.jws.WebService;

@WebService(endpointInterface = "io.quarkus.cxf.deployment.test.HelloWebService")
public class HelloWebServiceImpl implements HelloWebService {

@Override
public String sayHi(String name) {
return "Hello " + name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
quarkus.cxf.path=/
quarkus.cxf.webservice."/hello"=io.quarkus.cxf.deployment.test.HelloWebService
Loading

0 comments on commit 6051b4f

Please sign in to comment.