Skip to content
This repository has been archived by the owner on Jun 7, 2021. It is now read-only.

SWARM-1471: Do not auto-generate the JAX-RS application if the application-path has not been defined in YAML. #847

Merged
merged 1 commit into from Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,24 @@
/*
* Copyright 2015-2018 Red Hat, Inc, and individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wildfly.swarm.howto.autodetect;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/")
public class MyRestApplication extends Application {
}
@@ -0,0 +1,24 @@
/*
* Copyright 2015-2018 Red Hat, Inc, and individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wildfly.swarm.howto.datasources;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/")
public class MyRestApplication extends Application {
}
@@ -0,0 +1,24 @@
/*
* Copyright 2015-2018 Red Hat, Inc, and individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wildfly.swarm.howto.hollowjar;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/")
public class MyRestApplication extends Application {
}

This file was deleted.

@@ -0,0 +1,24 @@
/*
* Copyright 2015-2018 Red Hat, Inc, and individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wildfly.swarm.howto.uberjar;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/")
public class MyRestApplication extends Application {
}
@@ -0,0 +1,24 @@
/*
* Copyright 2015-2018 Red Hat, Inc, and individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wildfly.swarm.howto.explicit;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/")
public class MyRestApplication extends Application {
}
@@ -0,0 +1,24 @@
/*
* Copyright 2015-2018 Red Hat, Inc, and individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wildfly.swarm.howto.datasources;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/")
public class MyRestApplication extends Application {
}
Expand Up @@ -48,7 +48,8 @@ public class DefaultApplicationDeploymentProcessor implements DeploymentProcesso
*/
static final ArchivePath PATH_WEB_XML = ArchivePaths.create(ArchivePaths.create("WEB-INF"), "web.xml");

@AttributeDocumentation("Set the JAX-RS application path, if the JAX-RS application class is autogenerated by Swarm")
@AttributeDocumentation("Set the JAX-RS application path. If set, WildFly Swarm will automatically generate a JAX-RS" +
" Application class and use this value as the @ApplicationPath")
@Configurable("swarm.deployment.*.jaxrs.application-path")
Defaultable<String> applicationPath = Defaultable.string("/");

Expand Down Expand Up @@ -76,7 +77,9 @@ public void process() throws Exception {
return;
}

addGeneratedApplication(archive.as(JAXRSArchive.class));
if (applicationPath.isExplicit()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably change a bit the @AttributeDocumentation of applicationPath, to reflect the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me take a stab at providing some useful documentation for the annotation. Will need a customer focussed doc-review of that line though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a single sentence, not an overly big deal. My suggestion: If set, WildFly Swarm will automatically generate a JAX-RS Application class and use this value as the @ApplicationPath

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I haven't looked at the existing documentation that much, I wasn't aware of the tone / technical details that are included in the documentation. Will use the above sentence and update.

addGeneratedApplication(archive.as(JAXRSArchive.class));
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only change that was required. All the other changes pertain to the test cases.


private void addGeneratedApplication(JAXRSArchive archive) {
Expand Down
Expand Up @@ -39,10 +39,10 @@ public class DefaultApplicationDeploymentProcessorTest {
private static final String PATH = "WEB-INF/classes/org/wildfly/swarm/generated/WildFlySwarmDefaultJAXRSApplication.class";

@Test
public void testApplicationPathAnnotation_None() throws Exception {
JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class);
public void testApplicationPathAnnotation_SpecifiedInProjectDefaults() throws Exception {
JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class, "app.war");
DefaultApplicationDeploymentProcessor processor = new DefaultApplicationDeploymentProcessor(archive);

processor.applicationPath.set("/api-test"); // Simulate the behavior of loading the project defaults.
processor.process();

Node generated = archive.get(PATH);
Expand Down Expand Up @@ -121,6 +121,7 @@ public void testWebXmlApplicationServletMappingAbsent() throws Exception {
archive.addClass(MyResource.class);
archive.setWebXML(new StringAsset("<web-app><display-name>Foo</display-name></web-app>"));
DefaultApplicationDeploymentProcessor processor = new DefaultApplicationDeploymentProcessor(archive);
processor.applicationPath.set("/api-test"); // Simulate the behavior of loading the project defaults.

processor.process();

Expand All @@ -134,11 +135,12 @@ public void testMalformedWebXmlApplicationServletMappingAbsent() throws Exceptio
archive.addClass(MyResource.class);
archive.setWebXML(new StringAsset("blablabla"));
DefaultApplicationDeploymentProcessor processor = new DefaultApplicationDeploymentProcessor(archive);
processor.applicationPath.set("/api-test"); // Simulate the behavior of loading the project defaults.

processor.process();

Node generated = archive.get(PATH);
assertThat(generated).isNotNull();
}

}
}
@@ -0,0 +1,5 @@
swarm:
deployment:
endpoint.war:
jaxrs:
application-path: /
@@ -0,0 +1,5 @@
swarm:
deployment:
JAXRSApiTest.war:
jaxrs:
application-path: /
@@ -0,0 +1,5 @@
swarm:
deployment:
ClassLoaderTest.war:
jaxrs:
application-path: /
@@ -0,0 +1,5 @@
swarm:
deployment:
ArquillianModulesTest.war:
jaxrs:
application-path: /
@@ -0,0 +1,5 @@
swarm:
deployment:
Swarm551Test.war:
jaxrs:
application-path: /
Expand Up @@ -16,6 +16,7 @@
package org.wildfly.swarm.jaxrs;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
Expand All @@ -38,12 +39,16 @@ public class ArqJAXRSExceptionMapperTest {

@Deployment(testable = false)
public static Archive createDeployment() throws Exception {
URL url = Thread.currentThread().getContextClassLoader().getResource("project-test-defaults-path.yml");
assertThat(url).isNotNull();
File projectDefaults = new File(url.toURI());
JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class, "myapp.war");
deployment.addClass(JsonProcessingExceptionMapper.class);
deployment.addClass(CustomExceptionMapper.class);
deployment.addClass(CustomException.class);
deployment.addResource(JsonParsingExceptionResource.class);
deployment.addResource(CustomExceptionResource.class);
deployment.addAsResource(projectDefaults, "/project-defaults.yml");
deployment.addAllDependencies();
return deployment;
}
Expand Down
Expand Up @@ -15,7 +15,9 @@
*/
package org.wildfly.swarm.jaxrs;

import java.io.File;
import java.io.IOException;
import java.net.URL;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
Expand All @@ -39,11 +41,15 @@ public class JAXRSArquillianTest {

@Deployment(testable = false)
public static Archive createDeployment() throws Exception {
URL url = Thread.currentThread().getContextClassLoader().getResource("project-test-defaults-path.yml");
assertThat(url).isNotNull();
File projectDefaults = new File(url.toURI());
JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class, "myapp.war");
deployment.addClass(SuccessfulChecks.class);
deployment.addClass(CustomJsonProvider.class);
deployment.addClass(MyResource.class);
deployment.setContextRoot("rest");
deployment.addAsResource(projectDefaults, "/project-defaults.yml");
deployment.addAllDependencies();
return deployment;
}
Expand Down
@@ -0,0 +1,6 @@
# This file is translated in to the project defaults file in to the archives created during the test cases.
swarm:
deployment:
myapp.war:
jaxrs:
application-path: /
@@ -1,5 +1,8 @@
package org.wildfly.swarm.jpa.swarm513;

import java.io.File;
import java.net.URL;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
Expand All @@ -22,6 +25,8 @@
import org.wildfly.swarm.jaxrs.JAXRSArchive;
import org.wildfly.swarm.transactions.TransactionsFraction;

import static org.fest.assertions.Assertions.assertThat;

/**
* @author Heiko Braun
*/
Expand All @@ -30,7 +35,10 @@ public class SWARM_513Test {

@Deployment(testable = true)
public static Archive createDeployment() throws Exception {
JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class, "swarm_513.war");
URL url = Thread.currentThread().getContextClassLoader().getResource("project-test-defaults-path.yml");
assertThat(url).isNotNull();
File projectDefaults = new File(url.toURI());
JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class, "myapp.war");
deployment.addResource(TicketEndpoint.class);
deployment.addClass(Ticket.class);
deployment.addClass(Tickets.class);
Expand All @@ -39,6 +47,7 @@ public static Archive createDeployment() throws Exception {
deployment.addAsWebInfResource(new ClassLoaderAsset("META-INF/persistence.xml", SWARM_513Test.class.getClassLoader()), "classes/META-INF/persistence.xml");
deployment.addAsWebInfResource(new ClassLoaderAsset("META-INF/import.sql", SWARM_513Test.class.getClassLoader()), "classes/META-INF/import.sql");

deployment.addAsResource(projectDefaults, "/project-defaults.yml");
return deployment;
}

Expand Down
@@ -0,0 +1,6 @@
# This file is translated in to the project defaults file in to the archives created during the test cases.
swarm:
deployment:
myapp.war:
jaxrs:
application-path: /
Expand Up @@ -2,5 +2,7 @@
swarm:
deployment:
SwaggerConfiguredArquillianTest.war:
jaxrs:
application-path: /
swagger:
title: My Custom App
title: My Custom App
@@ -0,0 +1,5 @@
swarm:
deployment:
SwaggerArquillianTest.war:
jaxrs:
application-path: /
@@ -0,0 +1,6 @@

swarm:
deployment:
myapp.war:
jaxrs:
application-path: /
@@ -1,6 +1,7 @@
package org.wildfly.swarm.jaxrs;

import java.io.File;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
Expand Down Expand Up @@ -38,12 +39,14 @@ public class ZipkinJAXRSTest {
private static final String SPAN_COLLECTOR = "com.github.kristofa.brave.LoggingSpanCollector";



@Deployment
public static Archive createDeployment() throws Exception {
JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
URL url = Thread.currentThread().getContextClassLoader().getResource("project-defaults.yml");
File projectDefaults = new File(url.toURI());
JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class, "myapp.war");
deployment.addResource(MyResource.class);
deployment.addAllDependencies();
deployment.addAsResource(projectDefaults, "/project-defaults.yml");
return deployment;
}

Expand Down