-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 #12546 from gsmet/1.8.2-backports-2
1.8.2 backports 2
- Loading branch information
Showing
17 changed files
with
186 additions
and
23 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
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
75 changes: 75 additions & 0 deletions
75
...ng-web/runtime/src/main/java/io/quarkus/spring/web/runtime/SpringWebEndpointProvider.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,75 @@ | ||
package io.quarkus.spring.web.runtime; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.Optional; | ||
import java.util.function.Function; | ||
|
||
import org.eclipse.microprofile.config.ConfigProvider; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
import io.quarkus.runtime.test.TestHttpEndpointProvider; | ||
|
||
public class SpringWebEndpointProvider implements TestHttpEndpointProvider { | ||
@Override | ||
public Function<Class<?>, String> endpointProvider() { | ||
return new Function<Class<?>, String>() { | ||
@Override | ||
public String apply(Class<?> aClass) { | ||
String[] paths = getPath(aClass); | ||
if (paths == null) { | ||
return null; | ||
} | ||
String value; | ||
if (paths.length == 0) { | ||
value = ""; | ||
} else { | ||
value = paths[0]; | ||
if (value.startsWith("/")) { | ||
value = value.substring(1); | ||
} | ||
} | ||
//TODO: there is not really any way to handle @ApplicationPath, we could do something for @QuarkusTest apps but we can't for | ||
//native apps, so we just have to document the limitation | ||
String path = "/"; | ||
Optional<String> appPath = ConfigProvider.getConfig().getOptionalValue("quarkus.resteasy.path", String.class); | ||
if (appPath.isPresent()) { | ||
path = appPath.get(); | ||
} | ||
if (!path.endsWith("/")) { | ||
path = path + "/"; | ||
} | ||
value = path + value; | ||
return value; | ||
} | ||
}; | ||
} | ||
|
||
private String[] getPath(Class<?> aClass) { | ||
String[] value = null; | ||
for (Annotation annotation : aClass.getAnnotations()) { | ||
if (annotation.annotationType().getName().equals(RequestMapping.class.getName())) { | ||
try { | ||
value = (String[]) annotation.annotationType().getMethod("value").invoke(annotation); | ||
break; | ||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
if (value == null) { | ||
for (Class<?> i : aClass.getInterfaces()) { | ||
value = getPath(i); | ||
if (value != null) { | ||
break; | ||
} | ||
} | ||
} | ||
if (value == null) { | ||
if (aClass.getSuperclass() != Object.class) { | ||
value = getPath(aClass.getSuperclass()); | ||
} | ||
} | ||
return value; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ime/src/main/resources/META-INF/services/io.quarkus.runtime.test.TestHttpEndpointProvider
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 @@ | ||
io.quarkus.spring.web.runtime.SpringWebEndpointProvider |
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
21 changes: 21 additions & 0 deletions
21
...gration-tests/spring-web/src/test/java/io/quarkus/it/spring/web/TestHTTPEndpointTest.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,21 @@ | ||
package io.quarkus.it.spring.web; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.common.http.TestHTTPEndpoint; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.RestAssured; | ||
|
||
@QuarkusTest | ||
@TestHTTPEndpoint(GreetingController.class) | ||
public class TestHTTPEndpointTest { | ||
|
||
@Test | ||
public void testJsonResult() { | ||
RestAssured.when().get("/json/hello").then() | ||
.contentType("application/json") | ||
.body(containsString("hello")); | ||
} | ||
} |
Binary file not shown.
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
Oops, something went wrong.