id
stringlengths
36
36
text
stringlengths
1
1.25M
ef7fe0f0-eaa3-4007-a59f-e5629ac5238b
@Override public void messageReceived(ChannelHandlerContext ctx, Env env) throws Exception { ctx.fireInboundBufferUpdated(); }
d1accb55-7e62-47b7-bbb9-9f7582c995f6
public boolean nextHandler(ChannelHandlerContext ctx, Env env) throws Exception { return ChannelHandlerUtil.addToNextInboundBuffer(ctx, env); }
5e643209-bf5e-4c54-b990-febb7e2ce4d9
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { cause.printStackTrace(); ctx.close(); }
1c1fe33a-4472-4ca3-b734-d671ab3a47f9
@Override protected HttpMessage createMessage(String[] initialLine) throws Exception { return new Request( HttpVersion.valueOf(initialLine[2]), HttpMethod.valueOf(initialLine[0]), initialLine[1]); }
e9b8bc16-a2fc-4beb-bcb5-2c436f77faa1
@Override public void messageReceived(ChannelHandlerContext ctx, Env env) throws Exception { env.getResponse().end("Hello World"); }
456dee23-02c9-4e84-a760-64ee4ce64de7
@Before public void initialize() { MockitoAnnotations.initMocks(this); when(ctx.nextOutboundMessageBuffer()).thenReturn(buf); when(buf.add(anyObject())).thenReturn(true); response = new Response(ctx); }
c1e84740-89dd-482d-bba5-8b56c3a8463f
@Test(expected=HeadersAlreadySentException.class) public void cantSetStatusCodeAfterHeadersHasBeenSent() throws HeadersAlreadySentException { response.writeHead(200); response.setStatusCode(204); }
f6314458-7616-4af4-873a-7689204987f4
@Test(expected=HeadersAlreadySentException.class) public void cantSetHeaderAfterHeadersHasBeenSent() throws HeadersAlreadySentException { response.writeHead(200); response.setHeader("Foo", "bar"); }
9eb31bf3-72c5-403d-9b39-2fc325c50fad
@Test(expected=HeadersAlreadySentException.class) public void cantRemoveHeaderAfterHeadersHasBeenSent() throws HeadersAlreadySentException { response.writeHead(200); response.removeHeader("Foo"); }
7a71659d-1f6e-419b-a3a7-7989ebb66a0c
@Test public void setHeadersWhileWritingHead() throws HeadersAlreadySentException { HashMap<String, String> headers = new HashMap<String, String>(); headers.put("Foo", "bar"); response.writeHead(200, headers); assertEquals("bar", response.getHeader("Foo")); }
ac0ca318-42cf-4783-bd41-e4e9e39f5c49
@Before public void initialize() throws Exception { MockitoAnnotations.initMocks(this); when(context.nextInboundMessageBuffer()).thenReturn(buf); when(buf.add(anyObject())).thenReturn(true); }
2de35170-e2d8-4477-a68c-d901d1813c9c
@Test public void exposesBodyParamsInRequest() throws Exception { HashMap<String,String> params = new HashMap<String,String>(); params.put("foo", "bar"); assertEquals(new HashMap<String,String>(), env.getRequest().getParams()); handler.messageReceived(context, env); assertEquals(params, env.getRe...
e7a39a52-086f-4e47-a031-9fc6e631fc6f
@Test public void notExposesBodyParamsInRequestonGet() throws Exception { env.getRequest().setMethod(GET); assertEquals(new HashMap<String,String>(), env.getRequest().getParams()); handler.messageReceived(context, env); assertEquals(new HashMap<String,String>(), env.getRequest().getParams()); }
1b32c36a-af31-4901-bb68-8674a8c2bdfd
@Before public void initialize() { MockitoAnnotations.initMocks(this); when(context.nextInboundMessageBuffer()).thenReturn(buf); when(buf.add(anyObject())).thenReturn(true); when(context.nextOutboundMessageBuffer()).thenReturn(outboundBuf); }
4ca8acfb-5669-4645-8775-c2a09f774edc
@Test public void testThatAuthIsDeniedWithWrongUser() throws Exception { receiveRequest(encodeBasicAuth("noUser", "pass")); assertThat(env.getResponse().getStatusCode(), is(403)); }
bdc834b4-4a6b-4b6b-8da0-59357e967e7c
@Test public void testThatAuthIsDeniedWithWrongPass() throws Exception { receiveRequest(encodeBasicAuth("user", "wrongpass")); assertThat(env.getResponse().getStatusCode(), is(403)); }
7b93972c-2843-4f8d-b449-57d73ae217a5
@Test public void testThatAuthIsDeniedWithArbitraryString() throws Exception { receiveRequest("dafuq"); assertThat(env.getResponse().getStatusCode(), is(403)); }
10fad425-dffa-4ce0-8014-ed5a579ee647
@Test public void testThatAuthIsAllowedWithValidUserAndPass() throws Exception { receiveRequest(encodeBasicAuth("user", "pass")); assertThat(env.getResponse().getStatusCode(), is(200)); }
7f466ead-4f51-46a6-86bb-38241c7f2ed8
private void receiveRequest(String basicAuthHeader) throws Exception { request.headers().add(AUTHORIZATION, basicAuthHeader); env = new Env(context, request); env.getRequest().setPath(request.getUri()); handler.messageReceived(context, env); }
a79c36cc-3368-47a2-89f0-180acddcbfef
private String encodeBasicAuth(String noUser, String pass) { return "Basic " + base64Encoder.encode(new String (noUser + ":" + pass).getBytes()); }
01e96be8-8c6d-494b-af1e-59d29422339e
@Before public void initialize() { MockitoAnnotations.initMocks(this); when(context.nextInboundMessageBuffer()).thenReturn(buf); when(buf.add(anyObject())).thenReturn(true); }
04c615e4-6341-4f3c-bb5d-d3b510d1b546
@Test public void exposesPathInRequest() throws Exception { assertEquals(null, env.getRequest().getPath()); handler.messageReceived(context, env); assertEquals("/path", env.getRequest().getPath()); }
60ae99ad-76c1-43f4-b0b0-e91aa0990bc1
@Test public void exposesQueryStringParamsInRequest() throws Exception { HashMap<String,String> params = new HashMap<String,String>(); params.put("id", "1"); assertEquals(new HashMap<String,String>(), env.getRequest().getParams()); handler.messageReceived(context, env); assertEquals(params, env.g...
e2579e33-c466-4e04-9d8e-f300d38b1a80
public Timer(BukkitRunnable task, long delay) { this.task = task; this.delay = delay; }
d218e518-8bb9-40f8-b291-a4fc1c931557
@Override public void run() { try { sleep(delay * 200); //sleep delay ticks } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } task.run(); }
01e8f33f-45c0-45f0-85fe-4d6c0c673688
@Override public void run() { Bukkit.getServer().getPluginManager().callEvent(new CheckRainEvent()); }
144290ee-0cd4-45eb-a4be-e055c001df8c
@Override public void run() { Bukkit.getServer().getPluginManager().callEvent(new StartRainEvent()); }
134e9ae8-cf99-4ff4-9efe-6fed4cdb627d
@Override public void run() { Bukkit.getServer().getPluginManager().callEvent(new ToggleRainEvent()); }
f3447c6b-c104-41ed-b8ff-115d10622ceb
@Override public void run() { Bukkit.getServer().getPluginManager().callEvent(new CheckWorldEvent()); }
586b2671-3b93-4209-aab5-63526b93df31
public RainListener(AcidRainPlugin plugin, String worldName) { this.plugin = plugin; this.worldName = worldName; rand = new Random(); this.world = plugin.getServer().getWorld(worldName); if (this.world == null) { plugin.getLogger().info("World " + worldName + " doesn't seem to exist. This listener wi...
807c2cdd-75f5-433c-91be-59836ebe56ff
public int getState() { return this.state; }
e2c9a566-29c4-4080-96e7-f6f3aee0e51b
@EventHandler public void rainEvent(CheckRainEvent event) { if (state != 2) { return; //we only want this to happen if it's raining } PotionEffect frostbite = new PotionEffect(PotionEffectType.POISON, 100, 1); //poison 1 for 5 seconds try { for (Iterator<Player> playerlist = world.getPlayers().iterato...
d756f128-888c-4f4f-ba4a-c0c182d8494c
@EventHandler public void rainChange(WeatherChangeEvent event) { if (!event.isCancelled()) if (event.getWorld().getName().equals(this.world.getName())) if (event.toWeatherState()) { //starting to rain if (state == 1) { //it's already been waiting. Now we just actually make it rain. state = 2; ...
05067478-c565-47d1-8654-b4524a5f876b
@EventHandler public void rainStart(StartRainEvent event) { //We call the previous event again. This time, state will be 1, meaning it's thundering. world.setStorm(true); }
b7de590e-8ac9-4d77-b68b-256c7f681725
@EventHandler public void toggleRain(ToggleRainEvent event) { if (state == 2) { //it's raining and we want to stop that. world.setStorm(false); return; } else if (state == 0) { //it's not currently raining. We want to change that. world.setStorm(true); } }
599d4092-2c9e-4cef-a75c-369456ae8580
public World getWorld() { return world; }
1f84c0a2-dd31-4556-bf64-c51597185df9
public void setWorld(World world) { this.world = world; }
ec913cf4-c616-4a33-aaf1-cdc6301906f0
public AcidRainPlugin getPlugin() { return plugin; }
847607b0-26e6-44ab-aab3-e283b971d505
@EventHandler public void checkWorld(CheckWorldEvent event) { this.world = plugin.getServer().getWorld(worldName); if (world == null) { plugin.getLogger().info("World " + worldName + " doesn't seem to exist. This listener will wait until it does..."); Timer timer = new Timer(checkWorld, 50); timer.start(...
5a2d6562-a230-4a02-9c3b-5b6a177a7167
public void onLoad() { checkConfig(new File(getDataFolder(), configFilename)); }
5b678e88-8575-4c5c-8f06-2d9dc36d5eb6
public void onEnable() { if (mvplugin == null) { System.out.println("error finding multiverse!"); } config = load(new File(getDataFolder(), configFilename)); System.out.println("Worlds: " + config.getString("worlds", "Wilderness")); rainListener = new RainListener(this, config.getString("worlds...
731d79d0-e594-4d1a-81d4-dfa54cc0b394
private void checkConfig(File configFile) { //First, check if the file exists. If it does, we don't need to do anything for now. if (configFile.exists()) { return; } //Now we set up the default config that we're going to create. YamlConfiguration defaultConfig = new YamlConfiguration(); defaultConfi...
c5d4ab2a-45a9-4721-879a-40d98cc809d2
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){ if (cmd.getName().equalsIgnoreCase("acidstate")) { sender.sendMessage("state: " + rainListener.getState()); return true; } return false; }
f5070b89-3d69-4dc7-8b61-25440a2bcf03
private YamlConfiguration load(File configFile) { YamlConfiguration config = new YamlConfiguration(); if (!configFile.exists()) { checkConfig(configFile); } try { config.load(configFile); } catch (IOException e) { e.printStackTrace(); } catch (InvalidConfigurationException e) { e.printStac...
af24217c-f389-434b-af2e-fd72463685b9
@Override public HandlerList getHandlers() { return handlers; }
7224189a-add6-4b58-b14e-64bc499cee62
public static HandlerList getHandlerList() { return handlers; }
1393868c-1d1b-404c-b6b4-3a3357cd6415
@Override public HandlerList getHandlers() { return handlers; }
ab3d3edb-2c9f-4628-bf40-4389b7d8b074
public static HandlerList getHandlerList() { return handlers; }
37b04e4b-26ed-41f7-9bdd-23a7e1641b16
@Override public HandlerList getHandlers() { return handlers; }
c6bf00df-5cfa-46c0-83d8-227d635f2b0e
public static HandlerList getHandlerList() { return handlers; }
cf29ef75-613b-47f8-a65d-fffd213fc09b
@Override public HandlerList getHandlers() { return handlers; }
82c51911-dab7-465f-95a8-14be78e2cf4c
public static HandlerList getHandlerList() { return handlers; }
f0fed9fe-2c69-41d8-ab1d-f211b3cfd522
boolean checkAndAddName(String clientName) throws RemoteException;
385bebf9-fcec-4009-93d5-2a7be510dd80
void removeName(String clientName) throws RemoteException;
11099c12-51b1-4d62-af4d-ed18dc525a53
boolean getLock(String filepath, String clientName) throws RemoteException;
2c03cf0b-f156-442d-bbec-3d42e0e02b1a
boolean dropLock(String filepath, String clientName) throws RemoteException;
2ddcc228-c975-47ff-ac9d-445a965b8ed5
boolean checkLock(String filepath, String clientName) throws RemoteException;
df23e745-eafd-4407-850e-50c9ee943fa5
private BackupServer(){}
5078e761-641f-4693-8469-4a034d6f2376
public BackupServer(String directory, String serverName){ backupDir = directory; try{ Registry registry = LocateRegistry.getRegistry(null); //Initialise Lock Server BackupServer BServerObj = new BackupServer(); BServerRMI BServerStub = (BServerRMI) UnicastRemoteObject.exportObject(BServerObj, 0);...
fddee17f-566e-4094-9c2a-31d36226dd99
public boolean backupFile(byte file[], String filepath){ String filename = (new File(filepath)).getName(); String localpath = backupDir + filename + "_" + internalNumber; internalNumber++; try { Utils.getUtils().deSerialiseFile(file, localpath); System.err.println(localpath); } catch (Exception e) { ...
5b066146-7cd3-42bb-a0c7-248587773628
public byte[] getFile(String filepath){ byte returnFile[] = null; try{ returnFile = Utils.getUtils().serialiseFile(filepaths.get(filepath)); }catch(Exception e){ return null; } return returnFile; }
638de082-42ba-4746-9e18-17b3e4a329d5
public static void main(String args[]){ //Set code base so RMI can see the classes (classpath) System.setProperty("java.rmi.server.codebase", DServerRMI.class.getProtectionDomain().getCodeSource().getLocation().toString()); Scanner scanner = new Scanner(System.in); System.out.print("Enter name for backup ...
5fbd0b5f-7f9c-4384-a931-7ec030dccf5b
public Client(){}
1f6766f5-eb82-47b2-a78a-b9008863ecb5
public Client(String workspace){workingDir = workspace;}
7f7c5b00-ea73-4d7b-97ed-12122efd2764
public void setup(){ try{ //System.setSecurityManager(new RMISecurityManager()); //Get RMI registry registry = LocateRegistry.getRegistry(null); //Get stubs for File, Directory, and Lock Servers FServerStub = (FServerRMI) registry.lookup("FileServer"); DServerStub = (DServerRMI) regi...
98f6f364-dd96-471a-8b13-0dce0eb297ef
public void closeConnection(){ //Remove client name from lock server when done try{ LServerStub.removeName(clientName); } catch(RemoteException e){ System.err.println("Exception removing client name from lock server " + e.toString()); e.printStackTrace(); } }
69db1104-a138-4da0-9773-2fcd81661de8
public static void main(String args[]){ //Set code base so RMI can see the classes (classpath) System.setProperty("java.rmi.server.codebase", DServerRMI.class.getProtectionDomain().getCodeSource().getLocation().toString()); //Run test client Client client = new Client("C:/Users/Tom/Desktop/Servers/Client"...
8d09d393-6519-44cc-8018-0ff44396ba6b
public void mainMenu(){ setup(); boolean exit = false; String choiceInput; while(!exit){ System.out.println("\n-------------"); System.out.println("Main Menu\n"); System.out.println("1) Get File List"); System.out.println("2) Change Directory"); System.out.println("3) Rename File"); Syst...
1b49e258-dc1b-41ce-80a2-c06becab6b34
public static void setup() throws RemoteException{ //Get handle on RMI registry registry = LocateRegistry.getRegistry(); //Initialise Replication Server ReplicationServer RServerObj = new ReplicationServer(); RServerStub = (RServerRMI) UnicastRemoteObject.exportObject(RServerObj, 0); //Bind to RMI regist...
c48fde4f-6c9d-4a53-9541-68571f1c48a3
public static void setdown() throws Exception{ //To unbind names from RMI registry System.out.println("\nExiting..."); registry.unbind("FileServer"); System.out.println("File Server unbound from registry"); registry.unbind("DirectoryServer"); System.out.println("Directory Server unbound from registry"); ...
aa38090b-7f11-416f-b6f6-08258d677fd0
public static void main(String args[]){ //Set code base so RMI can see the classes (classpath) System.setProperty("java.rmi.server.codebase", DServerRMI.class.getProtectionDomain().getCodeSource().getLocation().toString()); try{ //Set up file, directory, and lock servers in RMI registry setup(); ...
8f4eb4b6-8b87-49a7-88a2-8b41b1ebe8d0
String[] getFileFolderList(String breadcrumbs) throws RemoteException;
2e636322-570e-453b-a4b2-af3482fdfb42
String getFilePath(String breadcrumbs, String file) throws RemoteException;
31d6d851-b88a-46f4-a8ee-c2ca226921d3
boolean renameFile(String breadcrumbs, String currentFilename, String newFilename) throws RemoteException;
df67933c-7bef-4e0b-8dfa-535238d69051
boolean createFolder(String breadcrumbs, String newFolderName) throws RemoteException;
0e13cb41-3c78-411a-95b0-f809d87e0c27
boolean addNewFile(String breadcrumbs, String filename, String filepath) throws RemoteException;
1cfc2a74-6bea-4974-9d8f-f2e0d2480bb1
boolean checkTimestamp(String filename, Date time) throws RemoteException;
276319c2-98a5-49e1-ade9-982cb334863a
void updateTimestamp(String filename, Date time) throws RemoteException;
71d20ab7-ad25-46f8-bde9-0ac8d96e59a9
String[] getFileList() throws RemoteException;
fd9749ae-9dc0-46a5-9715-4a6ab96ed947
byte[] retrieveFile(String filepath) throws RemoteException;
cc0a925a-719d-4690-b1f9-bd25855282d1
boolean writeNewFile(byte[] newFile, String filename, String breadcrumbs) throws RemoteException;
2fc997ca-d36a-45de-8f60-4b77b0f673c1
boolean overwriteFile(byte[] newFile, String filepath, String clientName) throws RemoteException;
ac49a599-ddc5-4fe7-a982-7be488c50676
public LockServer(){ System.out.println("Lock Server Ready."); }
5527e97d-88c3-4bb9-9015-0ef08b101a61
public boolean checkAndAddName(String clientName){ if(clientSet.contains(clientName)){ return false; } else{ clientSet.add(clientName); return true; } }
8afcf53f-ae54-40ce-9538-7ba2dd21536d
public void removeName(String clientName){ clientSet.remove(clientName); }
de79b020-f11d-45cf-a4fc-afc45ba79e80
public boolean getLock(String filepath, String clientName){ //If client has not been registered, return false if(!clientSet.contains(clientName)) return false; String lockHolder = lockMap.get(filepath); if(lockHolder == null){ //Grant lock, return true lockMap.put(filepath, clientName); return true;...
f17ac1ec-3d3a-4690-972f-2fb9b175e401
public boolean dropLock(String filepath, String clientName){ if(!lockMap.containsKey(filepath)) return false; //Lock not held //Check if client is the lock holder, drop lock if they are String lockHolder = lockMap.get(filepath); if(clientName.equals(lockHolder)){ lockMap.remove(filepath); return tru...
d20ff690-b025-4eb6-b27d-2c31a7977f82
public boolean checkLock(String filepath, String clientName){ if(!lockMap.containsKey(filepath)) return false; //No one has lock on this file String lockHolder = lockMap.get(filepath); if(clientName.equals(lockHolder)) return true; else return false; }
5a05ff38-d1f6-4b82-8a4d-774ce84968b4
public static void main(String args[]){ //Set code base so RMI can see the classes (classpath) System.setProperty("java.rmi.server.codebase", DServerRMI.class.getProtectionDomain().getCodeSource().getLocation().toString()); try { Registry registry = LocateRegistry.getRegistry(); //Initialise Lock Server...
23cf669b-4f43-486f-a6ab-4bab82ce9096
private Utils(){}
1cdf3d6c-40e9-4581-86eb-1af6f49c3d72
public static Utils getUtils(){ return instance; }
8f428c4e-3c07-499d-9c97-777730a532f6
public byte[] serialiseFile(String filepath) throws FileNotFoundException, IOException{ //Check if file exists: File fileToSerialise = new File(filepath); if(!fileToSerialise.exists()){ System.err.println("File not found."); return null; } //Open file and read into byte array fileByteArray[], retu...
fad55bf1-a9a1-4d6a-b8af-75374336b1f4
public void deSerialiseFile(byte[] serialisedFile, String filepath) throws FileNotFoundException, IOException{ //Check if file already exists in this path, if yes, rename existing file (append '_old') File testExists = new File(filepath); if(testExists.exists()){ System.out.println("File already exists with...
1a575fd1-34cd-44c1-9fc0-2d547a18dd1e
public FileServer(){ try{ registry = LocateRegistry.getRegistry(); RServerStub = (RServerRMI) registry.lookup("ReplicationServer"); }catch(Exception e){} }
d80406e1-e4cb-4cf4-975e-a88168f4704d
public String[] getFileList(){ File dir = new File(homeDir); File listDir[] = dir.listFiles(); ArrayList<String> listOfFiles = new ArrayList<String>(); //Create list of files, ignoring directories for(int i=0; i<listDir.length; i++){ if(listDir[i].isFile()) listOfFiles.add(listDir[i].getAbsolutePa...
62e28a00-786e-4ff5-8986-8e01d9483814
public byte[] retrieveFile(String filepath){ try{ return Utils.getUtils().serialiseFile(filepath); } catch(Exception e){ System.err.println("Error serialising file " + e.toString()); e.printStackTrace(); return null; } }
66b5a3cf-e3ad-455f-ab3f-a97847b5b6e7
public boolean writeNewFile(byte[] newFile, String filename, String breadcrumbs){ //Write newFile into new file 'filename' String filepath = homeDir + "/" + filename; try{ File test = new File(filepath); while(test.exists()){ filepath += "_1"; test = new File(filepath); } Utils.getUtils().deSe...
b9d765f6-1331-4e80-b52b-03b969c50148
public boolean overwriteFile(byte[] newFile, String filepath, String clientName){ try{ Registry registry = LocateRegistry.getRegistry(null); LServerRMI LServerStub = (LServerRMI) registry.lookup("LockServer"); //Make sure client has lock on file if(LServerStub.checkLock(filepath, clientName)){ ...
31bae6d0-6653-418c-ba36-5399cdb51aeb
public boolean rollbackFile(String filepath, String clientName){ try{ Registry registry = LocateRegistry.getRegistry(null); LServerRMI LServerStub = (LServerRMI) registry.lookup("LockServer"); //Make sure client has lock on file if(LServerStub.checkLock(filepath, clientName)){ //Utils.getUtils(...
83abbfd4-5874-47e2-bc01-012b7bbc8605
public static void main(String args[]) throws RemoteException{ //Set code base so RMI can see the classes (classpath) System.setProperty("java.rmi.server.codebase", DServerRMI.class.getProtectionDomain().getCodeSource().getLocation().toString()); //Initialise File Server FileServer FServerObj = new FileSe...