forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix quarkusio#4005
- Loading branch information
Showing
16 changed files
with
497 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,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> |
23 changes: 23 additions & 0 deletions
23
extensions/cxf/deployment/src/main/java/io/quarkus/cxf/deployment/CxfConfig.java
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,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; | ||
} |
105 changes: 105 additions & 0 deletions
105
extensions/cxf/deployment/src/main/java/io/quarkus/cxf/deployment/CxfProcessor.java
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,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; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...ions/cxf/deployment/src/main/java/io/quarkus/cxf/deployment/CxfServerConfigBuildItem.java
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,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; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
extensions/cxf/deployment/src/test/java/io/quarkus/cxf/deployment/test/CxfServiceTest.java
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,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); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
extensions/cxf/deployment/src/test/java/io/quarkus/cxf/deployment/test/HelloWebService.java
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,10 @@ | ||
package io.quarkus.cxf.deployment.test; | ||
|
||
import javax.jws.WebService; | ||
|
||
@WebService | ||
public interface HelloWebService { | ||
|
||
String sayHi(String name); | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...ions/cxf/deployment/src/test/java/io/quarkus/cxf/deployment/test/HelloWebServiceImpl.java
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,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; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
extensions/cxf/deployment/src/test/resources/application.properties
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,2 @@ | ||
quarkus.cxf.path=/ | ||
quarkus.cxf.webservice."/hello"=io.quarkus.cxf.deployment.test.HelloWebService |
Oops, something went wrong.