jvm-jersey-env (#1677)

A new Jersey framework based JVM environment which is lightweight and simpler.
This commit is contained in:
Sahil Lakhwani
2020-09-08 21:24:25 +05:30
committed by GitHub
parent 975286c2ac
commit 54b384efec
28 changed files with 1049 additions and 25 deletions
@@ -0,0 +1,25 @@
package io.fission;
import javax.ws.rs.core.Response;
import javax.ws.rs.container.ContainerRequestContext;
import io.fission.Function;
import java.io.BufferedReader;
import java.util.stream.Collectors;
import java.io.InputStreamReader;
public class HelloWorld implements Function<ContainerRequestContext,Response> {
public static final String RETURN_STRING = "Hello World!";
@Override
public Response call(ContainerRequestContext request, Context arg1) {
if(request.getMethod().equals("GET")) {
return Response.ok(RETURN_STRING).build();
}
else {
String body = new BufferedReader(new InputStreamReader(request.getEntityStream())).lines()
.parallel().collect(Collectors.joining("\n"));
return Response.ok("Echo: " + body).build();
}
}
}
@@ -0,0 +1,25 @@
package io.fission;
import java.net.URI;
import java.net.URISyntaxException;
import org.glassfish.jersey.server.ContainerRequest;
import javax.ws.rs.core.Response;
import org.junit.Assert;
import org.junit.Test;
public class HelloWorldTest {
@Test
public void testResponse() {
HelloWorld hw = new HelloWorld();
ContainerRequest request = null;
try {
request = new ContainerRequest(new URI("http://example.com/"),new URI("/hello"),"GET",null,null);
} catch (URISyntaxException e) {
e.printStackTrace();
}
Response response = hw.call(request, null);
Assert.assertTrue(response.getEntity().toString().equals(HelloWorld.RETURN_STRING));
}
}