diff --git a/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/SQLiteBulletinBoardServer.java b/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/SQLiteBulletinBoardServer.java index ffb5b9d..a3782c1 100644 --- a/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/SQLiteBulletinBoardServer.java +++ b/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/SQLiteBulletinBoardServer.java @@ -4,7 +4,9 @@ import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; @@ -13,8 +15,12 @@ import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import com.google.protobuf.Message; +import meerkat.protobuf.BulletinBoardServer; +import meerkat.protobuf.Bulletinboardserver; import meerkat.protobuf.Voting.MessageFilterList; import meerkat.rest.Constants; import meerkat.bulletinboard.sqlserver.BulletinBoardSQLServer; @@ -97,13 +103,23 @@ public class SQLiteBulletinBoardServer extends BulletinBoardSQLServer { } } - -// @POST - @Consumes(Constants.MEDIATYPE_PROTOBUF) + @Override public boolean postMessage(BulletinBoardMessage msg) throws CommunicationException { return super.postMessage(msg); } + + + @POST + @Consumes(Constants.MEDIATYPE_PROTOBUF) + @Produces(Constants.MEDIATYPE_PROTOBUF) + public Message doPostMessage(BulletinBoardMessage msg)throws CommunicationException { + boolean result = super.postMessage(msg); + + return BulletinBoardServer.Boolean.newBuilder() + .setValue(result) + .build(); + } // @GET @Consumes(Constants.MEDIATYPE_PROTOBUF) @@ -114,8 +130,9 @@ public class SQLiteBulletinBoardServer extends BulletinBoardSQLServer { } @GET - public String test(){ - return "hello"; + @Produces(MediaType.TEXT_PLAIN) + public String test() { + return "Hello World"; } } diff --git a/bulletin-board-server/src/main/java/meerkat/bulletinboard/webapp/HelloProtoWebApp.java b/bulletin-board-server/src/main/java/meerkat/bulletinboard/webapp/HelloProtoWebApp.java index 491c295..b144a5a 100644 --- a/bulletin-board-server/src/main/java/meerkat/bulletinboard/webapp/HelloProtoWebApp.java +++ b/bulletin-board-server/src/main/java/meerkat/bulletinboard/webapp/HelloProtoWebApp.java @@ -20,7 +20,7 @@ public class HelloProtoWebApp { @PostConstruct public void init() { - // helloProtoBuf = new HelloProtoBuf(); + helloProtoBuf = new HelloProtoBuf(); } @GET diff --git a/bulletin-board-server/src/main/java/meerkat/bulletinboard/webapp/SQLiteServerTest.java b/bulletin-board-server/src/main/java/meerkat/bulletinboard/webapp/SQLiteServerTest.java deleted file mode 100644 index 6e702fc..0000000 --- a/bulletin-board-server/src/main/java/meerkat/bulletinboard/webapp/SQLiteServerTest.java +++ /dev/null @@ -1,82 +0,0 @@ -package meerkat.bulletinboard.webapp; - - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; - -import meerkat.rest.Constants; -import meerkat.rest.Constants.*; - -import com.google.protobuf.ByteString; - -import meerkat.bulletinboard.sqlserver.SQLiteBulletinBoardServer; -import meerkat.comm.CommunicationException; -import meerkat.protobuf.Crypto.*; -import meerkat.protobuf.Voting.*; -import meerkat.rest.*; - -@Path("/test") -public class SQLiteServerTest { - - private static String PROP_GETTY_URL = "gretty.httpBaseURI"; - private static String BASE_URL = "http://localhost:8081";//System.getProperty(PROP_GETTY_URL); - private static String SQL_SERVER_URL = BASE_URL + "/SQLServer"; - - @GET - public Response main(){ - byte[] b1 = {(byte) 1, (byte)2, (byte) 3, (byte) 4}; - byte[] b2 = {(byte) 11, (byte)12, (byte) 13, (byte) 14}; - byte[] b3 = {(byte) 21, (byte)22, (byte) 23, (byte) 24}; - - Response response; - - BulletinBoardMessage msg; - try{ - msg = BulletinBoardMessage.newBuilder() - .setMsg(UnsignedBulletinBoardMessage.newBuilder() - .addTags("Signature") - .addTags("Trustee") - .setData(ByteString.copyFrom(b1)) - .build()) - .setSig(Signature.newBuilder() - .setType(SignatureType.DSA) - .setData(ByteString.copyFrom(b2)) - .setSignerId(ByteString.copyFrom(b3)) - .build()) - .build(); - -// SQLiteBulletinBoardServer bbs = new SQLiteBulletinBoardServer(); -// -// -// bbs.init(); -// -// bbs.postMessage(msg); -// response = Response.status(Status.OK).entity(bbs.testPrint()).build(); -// -// bbs.close(); - - - - Client client = ClientBuilder.newClient() - .register(ProtobufMessageBodyWriter.class) - .register(ProtobufMessageBodyWriter.class); - WebTarget webTarget = client.target(SQL_SERVER_URL); - response = webTarget.request(MediaType.TEXT_HTML).post(Entity.entity(msg, Constants.MEDIATYPE_PROTOBUF)); - - } catch(Exception e){ - response = Response.status(Status.OK).entity(e.getMessage()).build();; - } - -// response = Response.status(Status.OK).entity("OK").build(); - - return response; - } - -} diff --git a/bulletin-board-server/src/main/proto/meerkat/bulletin_board_server.proto b/bulletin-board-server/src/main/proto/meerkat/bulletin_board_server.proto new file mode 100644 index 0000000..e31485b --- /dev/null +++ b/bulletin-board-server/src/main/proto/meerkat/bulletin_board_server.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package meerkat; + +option java_package = "meerkat.protobuf"; + +message Boolean { + bool value = 1; +} \ No newline at end of file diff --git a/bulletin-board-server/src/test/java/HelloIntegrationTest.java b/bulletin-board-server/src/test/java/HelloIntegrationTest.java deleted file mode 100644 index 3a01d5e..0000000 --- a/bulletin-board-server/src/test/java/HelloIntegrationTest.java +++ /dev/null @@ -1,22 +0,0 @@ -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.WebTarget; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; - -public class HelloIntegrationTest { - - private static String PROP_GETTY_URL = "gretty.httpBaseURI"; - private static String BASE_URL = System.getProperty(PROP_GETTY_URL); - private static String HELLO_URL = BASE_URL + "/hello"; - - @Test - public void testHello() throws Exception { - Client client = ClientBuilder.newClient(); - WebTarget webTarget = client.target(HELLO_URL); - String response = webTarget.request().get(String.class); - System.out.println(response); - assertThat(response, is("Hello, World!")); - } -} diff --git a/bulletin-board-server/src/test/java/meerkat/bulletinboard/HelloProtoIntegrationTest.java b/bulletin-board-server/src/test/java/meerkat/bulletinboard/HelloProtoIntegrationTest.java index 4a6cbb3..1bcb091 100644 --- a/bulletin-board-server/src/test/java/meerkat/bulletinboard/HelloProtoIntegrationTest.java +++ b/bulletin-board-server/src/test/java/meerkat/bulletinboard/HelloProtoIntegrationTest.java @@ -17,10 +17,10 @@ import static org.hamcrest.MatcherAssert.assertThat; * Created by talm on 10/11/15. */ public class HelloProtoIntegrationTest { - private static String PROP_GETTY_URL = "gretty.httpBaseURI"; - private static String BASE_URL = System.getProperty(PROP_GETTY_URL); - private static String HELLO_URL = BASE_URL + "/proto"; + private static String DEFAULT_BASE_URL = "http://localhost:8081/"; + private static String BASE_URL = System.getProperty(PROP_GETTY_URL, DEFAULT_BASE_URL); + private static String HELLO_URL = "proto"; @Test public void testHello() throws Exception { @@ -28,8 +28,9 @@ public class HelloProtoIntegrationTest { client.register(ProtobufMessageBodyReader.class); client.register(ProtobufMessageBodyWriter.class); - WebTarget webTarget = client.target(HELLO_URL); - Voting.BulletinBoardMessage response = webTarget.request(Constants.MEDIATYPE_PROTOBUF).get(Voting.BulletinBoardMessage.class); + WebTarget webTarget = client.target(BASE_URL).path(HELLO_URL); + Voting.BulletinBoardMessage response = webTarget.request(Constants.MEDIATYPE_PROTOBUF) + .get(Voting.BulletinBoardMessage.class); System.out.println(response.getMsg().getData()); diff --git a/bulletin-board-server/src/test/java/meerkat/bulletinboard/SQLiteServerIntegrationTest.java b/bulletin-board-server/src/test/java/meerkat/bulletinboard/SQLiteServerIntegrationTest.java new file mode 100644 index 0000000..6a6371d --- /dev/null +++ b/bulletin-board-server/src/test/java/meerkat/bulletinboard/SQLiteServerIntegrationTest.java @@ -0,0 +1,75 @@ +package meerkat.bulletinboard; + + +import com.google.protobuf.ByteString; +import meerkat.protobuf.Crypto.Signature; +import meerkat.protobuf.Crypto.SignatureType; +import meerkat.protobuf.Voting.BulletinBoardMessage; +import meerkat.protobuf.Voting.UnsignedBulletinBoardMessage; +import meerkat.rest.Constants; +import meerkat.rest.ProtobufMessageBodyReader; +import meerkat.rest.ProtobufMessageBodyWriter; +import org.junit.Before; +import org.junit.Test; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; + +public class SQLiteServerIntegrationTest { + + private static String PROP_GETTY_URL = "gretty.httpBaseURI"; + private static String DEFAULT_BASE_URL = "http://localhost:8081/"; + private static String BASE_URL = System.getProperty(PROP_GETTY_URL, DEFAULT_BASE_URL); + private static String SQL_SERVER_URL = "SQLServer"; + + Client client; + + @Before + public void setup() throws Exception { + client = ClientBuilder.newClient(); + client.register(ProtobufMessageBodyReader.class); + client.register(ProtobufMessageBodyWriter.class); + } + + @Test + public void testPost() throws Exception { + byte[] b1 = {(byte) 1, (byte) 2, (byte) 3, (byte) 4}; + byte[] b2 = {(byte) 11, (byte) 12, (byte) 13, (byte) 14}; + byte[] b3 = {(byte) 21, (byte) 22, (byte) 23, (byte) 24}; + + Response response; + + BulletinBoardMessage msg; + + msg = BulletinBoardMessage.newBuilder() + .setMsg(UnsignedBulletinBoardMessage.newBuilder() + .addTags("Signature") + .addTags("Trustee") + .setData(ByteString.copyFrom(b1)) + .build()) + .setSig(Signature.newBuilder() + .setType(SignatureType.DSA) + .setData(ByteString.copyFrom(b2)) + .setSignerId(ByteString.copyFrom(b3)) + .build()) + .build(); + +// SQLiteBulletinBoardServer bbs = new SQLiteBulletinBoardServer(); +// +// +// bbs.init(); +// +// bbs.postMessage(msg); +// response = Response.status(Status.OK).entity(bbs.testPrint()).build(); +// +// bbs.close(); + + System.err.println("******** Testing: " + SQL_SERVER_URL); + WebTarget webTarget = client.target(BASE_URL).path(SQL_SERVER_URL); + response = webTarget.request(Constants.MEDIATYPE_PROTOBUF).post(Entity.entity(msg, Constants.MEDIATYPE_PROTOBUF)); + } + +}