Refactored into WebApp and Server

Bulletin_Board_Server_phase_1
Arbel Deutsch Peled 2015-11-20 21:59:45 +02:00
parent a6afb74893
commit c68eba84d2
2 changed files with 64 additions and 27 deletions

View File

@ -7,25 +7,13 @@ import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.List; import java.util.List;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ws.rs.Consumes;
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 com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.InvalidProtocolBufferException;
import meerkat.protobuf.BulletinBoardAPI.*; import meerkat.protobuf.BulletinBoardAPI.*;
import meerkat.protobuf.Crypto.Signature; import meerkat.protobuf.Crypto.Signature;
import meerkat.rest.Constants;
import meerkat.bulletinboard.sqlserver.BulletinBoardSQLServer; import meerkat.bulletinboard.sqlserver.BulletinBoardSQLServer;
import meerkat.comm.CommunicationException; import meerkat.comm.CommunicationException;
@Path("/sqlserver")
public class SQLiteBulletinBoardServer extends BulletinBoardSQLServer { public class SQLiteBulletinBoardServer extends BulletinBoardSQLServer {
protected static final int TIMEOUT = 20; protected static final int TIMEOUT = 20;
@ -35,7 +23,7 @@ public class SQLiteBulletinBoardServer extends BulletinBoardSQLServer {
* 1. The database connection * 1. The database connection
* 2. The database tables (if they do not yet exist). * 2. The database tables (if they do not yet exist).
*/ */
@PostConstruct
@Override @Override
public void init() throws CommunicationException { public void init() throws CommunicationException {
@ -65,7 +53,6 @@ public class SQLiteBulletinBoardServer extends BulletinBoardSQLServer {
} }
@PreDestroy
public void close() throws CommunicationException{ public void close() throws CommunicationException{
try{ try{
@ -78,7 +65,6 @@ public class SQLiteBulletinBoardServer extends BulletinBoardSQLServer {
} }
@Override @Override
protected void insertNewTags(String[] tags) throws SQLException { protected void insertNewTags(String[] tags) throws SQLException {
@ -104,17 +90,11 @@ public class SQLiteBulletinBoardServer extends BulletinBoardSQLServer {
} }
@Path("postmessage")
@POST
@Override @Override
public BoolMsg postMessage(BulletinBoardMessage msg) throws CommunicationException { public BoolMsg postMessage(BulletinBoardMessage msg) throws CommunicationException {
return super.postMessage(msg); return super.postMessage(msg);
} }
@Path("readmessages")
@POST
@Consumes(Constants.MEDIATYPE_PROTOBUF)
@Produces(Constants.MEDIATYPE_PROTOBUF)
@Override @Override
public BulletinBoardMessageList readMessages(MessageFilterList filterList) throws CommunicationException{ public BulletinBoardMessageList readMessages(MessageFilterList filterList) throws CommunicationException{
@ -278,11 +258,5 @@ public class SQLiteBulletinBoardServer extends BulletinBoardSQLServer {
return resultListBuilder.build(); return resultListBuilder.build();
} }
@GET
@Produces(MediaType.TEXT_PLAIN)
public String test() {
return "Hello World";
}
} }

View File

@ -0,0 +1,63 @@
package meerkat.bulletinboard.webapp;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ws.rs.Consumes;
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 meerkat.bulletinboard.BulletinBoardServer;
import meerkat.bulletinboard.sqlserver.SQLiteBulletinBoardServer;
import meerkat.comm.CommunicationException;
import meerkat.protobuf.BulletinBoardAPI.BoolMsg;
import meerkat.protobuf.BulletinBoardAPI.BulletinBoardMessage;
import meerkat.protobuf.BulletinBoardAPI.BulletinBoardMessageList;
import meerkat.protobuf.BulletinBoardAPI.MessageFilterList;
import meerkat.rest.Constants;
@Path("/sqlserver")
public class BulletinBoardWebApp implements BulletinBoardServer{
BulletinBoardServer bulletinBoard;
@PostConstruct
@Override
public void init() throws CommunicationException {
bulletinBoard = new SQLiteBulletinBoardServer();
bulletinBoard.init();
}
@Path("postmessage")
@POST
@Consumes(Constants.MEDIATYPE_PROTOBUF)
@Produces(Constants.MEDIATYPE_PROTOBUF)
@Override
public BoolMsg postMessage(BulletinBoardMessage msg) throws CommunicationException {
return bulletinBoard.postMessage(msg);
}
@Path("readmessages")
@POST
@Consumes(Constants.MEDIATYPE_PROTOBUF)
@Produces(Constants.MEDIATYPE_PROTOBUF)
@Override
public BulletinBoardMessageList readMessages(MessageFilterList filterList) throws CommunicationException {
return bulletinBoard.readMessages(filterList);
}
@Override
@PreDestroy
public void close() throws CommunicationException {
bulletinBoard.close();
}
@GET
@Produces(MediaType.TEXT_PLAIN)
public String test() {
return "This BulletinBoard is up and running!\n Please consult the API documents to perform queries.";
}
}