Skip to content

Commit

Permalink
feat: align Java HTTP mapping with the new model and add a test (#2453)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas authored Aug 20, 2024
1 parent 147a98c commit f8f8969
Show file tree
Hide file tree
Showing 24 changed files with 667 additions and 166 deletions.
270 changes: 143 additions & 127 deletions backend/controller/ingress/ingress_integration_test.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions backend/controller/ingress/testdata/java/httpingress/ftl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module = "httpingress"
language = "java"
14 changes: 14 additions & 0 deletions backend/controller/ingress/testdata/java/httpingress/pom.xml
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>
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;
}
}
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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package xyz.block.ftl.java.test.http;

public class DeleteResponse {
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package xyz.block.ftl.java.test.http;

public class PutResponse {

}
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;
}
}
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;
}

}
Loading

0 comments on commit f8f8969

Please sign in to comment.