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