generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: align Java HTTP mapping with the new model and add a test (#2453)
- Loading branch information
1 parent
147a98c
commit f8f8969
Showing
24 changed files
with
667 additions
and
166 deletions.
There are no files selected for viewing
270 changes: 143 additions & 127 deletions
270
backend/controller/ingress/ingress_integration_test.go
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
backend/controller/ingress/testdata/java/httpingress/ftl.toml
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 @@ | ||
module = "httpingress" | ||
language = "java" |
14 changes: 14 additions & 0 deletions
14
backend/controller/ingress/testdata/java/httpingress/pom.xml
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,14 @@ | ||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>xyz.block.ftl.examples</groupId> | ||
<artifactId>httpingress</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<parent> | ||
<groupId>xyz.block.ftl</groupId> | ||
<artifactId>ftl-build-parent-java</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
</project> |
15 changes: 15 additions & 0 deletions
15
...gress/testdata/java/httpingress/src/main/java/xyz/block/ftl/java/test/http/ArrayType.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,15 @@ | ||
package xyz.block.ftl.java.test.http; | ||
|
||
public class ArrayType { | ||
|
||
private String item; | ||
|
||
public String getItem() { | ||
return item; | ||
} | ||
|
||
public ArrayType setItem(String item) { | ||
this.item = item; | ||
return this; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...s/testdata/java/httpingress/src/main/java/xyz/block/ftl/java/test/http/DeleteRequest.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,13 @@ | ||
package xyz.block.ftl.java.test.http; | ||
|
||
public class DeleteRequest { | ||
private String userId; | ||
|
||
public String getUserId() { | ||
return userId; | ||
} | ||
|
||
public void setUserId(String userId) { | ||
this.userId = userId; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
.../testdata/java/httpingress/src/main/java/xyz/block/ftl/java/test/http/DeleteResponse.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,4 @@ | ||
package xyz.block.ftl.java.test.http; | ||
|
||
public class DeleteResponse { | ||
} |
23 changes: 23 additions & 0 deletions
23
...ress/testdata/java/httpingress/src/main/java/xyz/block/ftl/java/test/http/GetRequest.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 xyz.block.ftl.java.test.http; | ||
|
||
public class GetRequest { | ||
|
||
private String userId; | ||
private String postId; | ||
|
||
public String getUserId() { | ||
return userId; | ||
} | ||
|
||
public void setUserId(String userId) { | ||
this.userId = userId; | ||
} | ||
|
||
public String getPostId() { | ||
return postId; | ||
} | ||
|
||
public void setPostId(String postId) { | ||
this.postId = postId; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ess/testdata/java/httpingress/src/main/java/xyz/block/ftl/java/test/http/GetResponse.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,27 @@ | ||
package xyz.block.ftl.java.test.http; | ||
|
||
public class GetResponse { | ||
|
||
private Nested nested; | ||
|
||
private String msg; | ||
|
||
public Nested getNested() { | ||
return nested; | ||
} | ||
|
||
public GetResponse setNested(Nested nested) { | ||
this.nested = nested; | ||
return this; | ||
|
||
} | ||
|
||
public String getMsg() { | ||
return msg; | ||
} | ||
|
||
public GetResponse setMsg(String msg) { | ||
this.msg = msg; | ||
return this; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
.../ingress/testdata/java/httpingress/src/main/java/xyz/block/ftl/java/test/http/Nested.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,18 @@ | ||
package xyz.block.ftl.java.test.http; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAlias; | ||
|
||
public class Nested { | ||
|
||
@JsonAlias("good_stuff") | ||
private String goodStuff; | ||
|
||
public String getGoodStuff() { | ||
return goodStuff; | ||
} | ||
|
||
public Nested setGoodStuff(String goodStuff) { | ||
this.goodStuff = goodStuff; | ||
return this; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ess/testdata/java/httpingress/src/main/java/xyz/block/ftl/java/test/http/PostRequest.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,25 @@ | ||
package xyz.block.ftl.java.test.http; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAlias; | ||
|
||
public class PostRequest { | ||
@JsonAlias("user_id") | ||
private int userId; | ||
private int postId; | ||
|
||
public int getUserId() { | ||
return userId; | ||
} | ||
|
||
public void setUserId(int userId) { | ||
this.userId = userId; | ||
} | ||
|
||
public int getPostId() { | ||
return postId; | ||
} | ||
|
||
public void setPostId(int postId) { | ||
this.postId = postId; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...ss/testdata/java/httpingress/src/main/java/xyz/block/ftl/java/test/http/PostResponse.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,14 @@ | ||
package xyz.block.ftl.java.test.http; | ||
|
||
public class PostResponse { | ||
private boolean success; | ||
|
||
public boolean isSuccess() { | ||
return success; | ||
} | ||
|
||
public PostResponse setSuccess(boolean success) { | ||
this.success = success; | ||
return this; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ress/testdata/java/httpingress/src/main/java/xyz/block/ftl/java/test/http/PutRequest.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,13 @@ | ||
package xyz.block.ftl.java.test.http; | ||
|
||
public class PutRequest { | ||
private String postId; | ||
|
||
public String getPostId() { | ||
return postId; | ||
} | ||
|
||
public void setPostId(String postId) { | ||
this.postId = postId; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...ess/testdata/java/httpingress/src/main/java/xyz/block/ftl/java/test/http/PutResponse.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,5 @@ | ||
package xyz.block.ftl.java.test.http; | ||
|
||
public class PutResponse { | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...stdata/java/httpingress/src/main/java/xyz/block/ftl/java/test/http/QueryParamRequest.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,18 @@ | ||
package xyz.block.ftl.java.test.http; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class QueryParamRequest { | ||
|
||
@Nullable | ||
String foo; | ||
|
||
public @Nullable String getFoo() { | ||
return foo; | ||
} | ||
|
||
public QueryParamRequest setFoo(@Nullable String foo) { | ||
this.foo = foo; | ||
return this; | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
...ngress/testdata/java/httpingress/src/main/java/xyz/block/ftl/java/test/http/TestHTTP.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,124 @@ | ||
package xyz.block.ftl.java.test.http; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.ws.rs.DELETE; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.PUT; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
|
||
import jakarta.ws.rs.core.MediaType; | ||
import org.jboss.resteasy.reactive.ResponseHeader; | ||
import org.jboss.resteasy.reactive.ResponseStatus; | ||
import org.jboss.resteasy.reactive.RestPath; | ||
import org.jboss.resteasy.reactive.RestQuery; | ||
|
||
@Path("/") | ||
public class TestHTTP { | ||
|
||
@GET | ||
@Path("/users/{userId}/posts/{postId}") | ||
@ResponseHeader(name = "Get", value = "Header from FTL") | ||
public GetResponse get(@RestPath String userId, @RestPath String postId) { | ||
return new GetResponse() | ||
.setMsg(String.format("UserID: %s, PostID: %s", userId, postId)) | ||
.setNested(new Nested().setGoodStuff("This is good stuff")); | ||
} | ||
|
||
@POST | ||
@Path("/users") | ||
@ResponseStatus(201) | ||
@ResponseHeader(name = "Post", value = "Header from FTL") | ||
public PostResponse post(PostRequest req) { | ||
return new PostResponse().setSuccess(true); | ||
} | ||
|
||
@PUT | ||
@Path("/users/{userId}") | ||
@ResponseHeader(name = "Put", value = "Header from FTL") | ||
public PutResponse put(PutRequest req) { | ||
return new PutResponse(); | ||
} | ||
|
||
@DELETE | ||
@Path("/users/{userId}") | ||
@ResponseHeader(name = "Delete", value = "Header from FTL") | ||
@ResponseStatus(200) | ||
public DeleteResponse delete(@RestPath String userId) { | ||
System.out.println("delete"); | ||
return new DeleteResponse(); | ||
} | ||
|
||
@GET | ||
@Path("/queryparams") | ||
public String query(@RestQuery String foo) { | ||
return foo == null ? "No value" : foo; | ||
} | ||
|
||
@GET | ||
@Path("/html") | ||
@Produces("text/html; charset=utf-8") | ||
public String html() { | ||
return "<html><body><h1>HTML Page From FTL 🚀!</h1></body></html>"; | ||
} | ||
|
||
@POST | ||
@Path("/bytes") | ||
public byte[] bytes(byte[] b) { | ||
return b; | ||
} | ||
|
||
@GET | ||
@Path("/empty") | ||
@ResponseStatus(200) | ||
public void empty() { | ||
} | ||
|
||
@POST | ||
@Path("/string") | ||
public String string(String val) { | ||
return val; | ||
} | ||
|
||
@POST | ||
@Path("/int") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public int intMethod(int val) { | ||
return val; | ||
} | ||
|
||
@POST | ||
@Path("/float") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public float floatVerb(float val) { | ||
return val; | ||
} | ||
|
||
@POST | ||
@Path("/bool") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public boolean bool(boolean val) { | ||
return val; | ||
} | ||
|
||
@GET | ||
@Path("/error") | ||
public String error() { | ||
throw new RuntimeException("Error from FTL"); | ||
} | ||
|
||
@POST | ||
@Path("/array/string") | ||
public String[] arrayString(String[] array) { | ||
return array; | ||
} | ||
|
||
@POST | ||
@Path("/array/data") | ||
public List<ArrayType> arrayData(List<ArrayType> array) { | ||
return array; | ||
} | ||
|
||
} |
Oops, something went wrong.