This repository has been archived by the owner on Jun 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from paypal/develop
Bringing in 2.3.2 changes to master
- Loading branch information
Showing
17 changed files
with
268 additions
and
84 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
71 changes: 71 additions & 0 deletions
71
...asy-spring-boot-starter-test/src/test/java/com/paypal/springboot/resteasy/AsyncJobIT.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,71 @@ | ||
package com.paypal.springboot.resteasy; | ||
|
||
import com.sample.app.Application; | ||
import io.restassured.RestAssured; | ||
import io.restassured.response.Response; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.util.SocketUtils; | ||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.Properties; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.CoreMatchers.notNullValue; | ||
import static org.hamcrest.Matchers.empty; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.isEmptyString; | ||
|
||
/** | ||
* Integration tests for RESTEasy Asynchronous Job Service | ||
* | ||
* @author facarvalho | ||
*/ | ||
public class AsyncJobIT { | ||
|
||
@BeforeClass | ||
public void setUp() { | ||
int appPort = SocketUtils.findAvailableTcpPort(); | ||
|
||
RestAssured.basePath = "sample-app"; | ||
RestAssured.port = appPort; | ||
|
||
Properties properties = new Properties(); | ||
properties.put("server.context-parameters.resteasy.async.job.service.enabled", true); | ||
|
||
SpringApplication app = new SpringApplication(Application.class); | ||
app.setDefaultProperties(properties); | ||
app.addListeners(new LogbackTestApplicationListener()); | ||
app.run("--server.port=" + appPort).registerShutdownHook(); | ||
} | ||
|
||
@Test | ||
public void regularRequestTest() { | ||
Response response = given().body("is there anybody out there?").post("/echo"); | ||
response.then().statusCode(200).body("timestamp", notNullValue()).body("echoText", equalTo("is there anybody out there?")); | ||
} | ||
|
||
@Test | ||
public void asyncRequestTest() { | ||
Response response = given().body("is there anybody out there?").post("/echo?asynch=true"); | ||
response.then().statusCode(202).body(isEmptyString()); | ||
|
||
String location = response.getHeader("Location"); | ||
response = given().get(location + "?wait=50"); | ||
response.then().statusCode(200).body("timestamp", notNullValue()).body("echoText", equalTo("is there anybody out there?")); | ||
} | ||
|
||
@Test | ||
public void fireAndForgetRequestTest() { | ||
Response response = given().body("is there anybody out there?").post("/echo?oneway=true"); | ||
response.then().statusCode(202).body(isEmptyString()); | ||
} | ||
|
||
@AfterClass | ||
public void shuttingDownApplication() { | ||
Response response = given().basePath("/").post("/shutdown"); | ||
response.then().statusCode(200).body("message", equalTo("Shutting down, bye...")); | ||
} | ||
|
||
} |
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
8 changes: 8 additions & 0 deletions
8
...ng-boot-starter-test/src/test/java/com/sample/app/test/NonSpringBeanJaxrsApplication.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,8 @@ | ||
package com.sample.app.test; | ||
|
||
import javax.ws.rs.ApplicationPath; | ||
import javax.ws.rs.core.Application; | ||
|
||
@ApplicationPath("sample-app-test-two") | ||
public class NonSpringBeanJaxrsApplication extends Application { | ||
} |
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 |
---|---|---|
@@ -1,22 +1,20 @@ | ||
package com.paypal.springboot.resteasy; | ||
|
||
import org.apache.commons.io.FilenameUtils; | ||
import org.reflections.Reflections; | ||
import org.reflections.scanners.SubTypesScanner; | ||
import org.reflections.util.ClasspathHelper; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.config.BeanDefinition; | ||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; | ||
import org.springframework.core.type.filter.AssignableTypeFilter; | ||
import org.springframework.util.ClassUtils; | ||
|
||
import javax.ws.rs.core.Application; | ||
import java.io.File; | ||
import java.net.URL; | ||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** | ||
* Helper class to scan the classpath searching for | ||
* JAX-RS Application sub-classes | ||
* Helper class to scan the classpath under the specified packages | ||
* searching for JAX-RS Application sub-classes | ||
* | ||
* @author Fabio Carvalho ([email protected] or [email protected]) | ||
*/ | ||
|
@@ -26,58 +24,47 @@ public abstract class JaxrsApplicationScanner { | |
|
||
private static Set<Class<? extends Application>> applications; | ||
|
||
public static Set<Class<? extends Application>> getApplications() { | ||
public static Set<Class<? extends Application>> getApplications(List<String> packagesToBeScanned) { | ||
if(applications == null) { | ||
applications = findJaxrsApplicationClasses(); | ||
applications = findJaxrsApplicationClasses(packagesToBeScanned); | ||
} | ||
|
||
return applications; | ||
} | ||
|
||
/* | ||
* Scan the classpath looking for JAX-RS Application sub-classes | ||
* Scan the classpath under the specified packages looking for JAX-RS Application sub-classes | ||
*/ | ||
private static Set<Class<? extends Application>> findJaxrsApplicationClasses() { | ||
private static Set<Class<? extends Application>> findJaxrsApplicationClasses(List<String> packagesToBeScanned) { | ||
logger.info("Scanning classpath to find JAX-RS Application classes"); | ||
|
||
final Collection<URL> systemPropertyURLs = ClasspathHelper.forJavaClassPath(); | ||
final Collection<URL> classLoaderURLs = ClasspathHelper.forClassLoader(); | ||
ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false); | ||
scanner.addIncludeFilter(new AssignableTypeFilter(Application.class)); | ||
|
||
Set<URL> classpathURLs = new HashSet<URL>(); | ||
Set<BeanDefinition> candidates = new HashSet<BeanDefinition>(); | ||
Set<BeanDefinition> candidatesSubSet; | ||
|
||
copyValidClasspathEntries(systemPropertyURLs, classpathURLs); | ||
copyValidClasspathEntries(classLoaderURLs, classpathURLs); | ||
|
||
logger.debug("Classpath URLs to be scanned: " + classpathURLs); | ||
|
||
Reflections reflections = new Reflections(classpathURLs, new SubTypesScanner()); | ||
|
||
return reflections.getSubTypesOf(Application.class); | ||
} | ||
|
||
/* | ||
* Copy all entries that are a JAR file or a directory | ||
*/ | ||
private static void copyValidClasspathEntries(Collection<URL> source, Set<URL> destination) { | ||
String fileName; | ||
boolean isJarFile; | ||
boolean isDirectory; | ||
for (String packageToScan : packagesToBeScanned) { | ||
candidatesSubSet = scanner.findCandidateComponents(packageToScan); | ||
candidates.addAll(candidatesSubSet); | ||
} | ||
|
||
for (URL url : source) { | ||
if(destination.contains(url)) { | ||
continue; | ||
Set<Class<? extends Application>> classes = new HashSet<Class<? extends Application>>(); | ||
ClassLoader classLoader = JaxrsApplicationScanner.class.getClassLoader(); | ||
Class<? extends Application> type; | ||
for (BeanDefinition candidate : candidates) { | ||
try { | ||
type = (Class<? extends Application>) ClassUtils.forName(candidate.getBeanClassName(), classLoader); | ||
classes.add(type); | ||
} catch (ClassNotFoundException e) { | ||
logger.error("JAX-RS Application subclass could not be loaded", e); | ||
} | ||
} | ||
|
||
fileName = url.getFile(); | ||
isJarFile = FilenameUtils.isExtension(fileName, "jar"); | ||
isDirectory = new File(fileName).isDirectory(); | ||
// We don't want the JAX-RS Application class itself in there | ||
classes.remove(Application.class); | ||
|
||
if (isJarFile || isDirectory) { | ||
destination.add(url); | ||
} else if (logger.isDebugEnabled()) { | ||
logger.debug("Ignored classpath entry: " + fileName); | ||
} | ||
} | ||
return classes; | ||
} | ||
|
||
} |
Oops, something went wrong.