jvm-jersey-env (#1677)
A new Jersey framework based JVM environment which is lightweight and simpler.
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user