@Test public void shouldDisableIfCantMakeFile() throws IOException { handler = new RaygunOnFailedSendOfflineStorageHandler(storageDir, "apiKey") { @Override File getStorage(String storageDir) { return storage; } @Override OutputStream getOutputStream(File file) throws FileNotFoundException { return outputStream; } @Override File getFile(File storage, String name) { return file; } }; when(file.createNewFile()).thenReturn(false); handler.onFailedSend(null, "payload"); verify(outputStream, never()).write((byte[]) anyObject()); assertFalse(handler.enabled); }
public String onFailedSend(RaygunClient client, String jsonPayload) { if (!enabled) { return jsonPayload; } OutputStream fileOutputStream = null; try { File file = getFile(); if (file == null) { return jsonPayload; } fileOutputStream = getOutputStream(file); fileOutputStream.write(jsonPayload.getBytes()); exceptionLogged = false; hasStoredExceptions = true; } catch (Exception e1) { if(!exceptionLogged) { Logger.getLogger("Raygun4Java").warning("exception adding to offline storage: " + e1.getMessage()); exceptionLogged = true; } } finally { if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException e1) { Logger.getLogger("Raygun4Java").warning("exception closing file stream: " + e1.getMessage()); } } } return jsonPayload; }
RaygunOnFailedSendOfflineStorageHandler implements IRaygunOnFailedSend, IRaygunOnBeforeSend, IRaygunSendEventFactory { public String onFailedSend(RaygunClient client, String jsonPayload) { if (!enabled) { return jsonPayload; } OutputStream fileOutputStream = null; try { File file = getFile(); if (file == null) { return jsonPayload; } fileOutputStream = getOutputStream(file); fileOutputStream.write(jsonPayload.getBytes()); exceptionLogged = false; hasStoredExceptions = true; } catch (Exception e1) { if(!exceptionLogged) { Logger.getLogger("Raygun4Java").warning("exception adding to offline storage: " + e1.getMessage()); exceptionLogged = true; } } finally { if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException e1) { Logger.getLogger("Raygun4Java").warning("exception closing file stream: " + e1.getMessage()); } } } return jsonPayload; } }
RaygunOnFailedSendOfflineStorageHandler implements IRaygunOnFailedSend, IRaygunOnBeforeSend, IRaygunSendEventFactory { public String onFailedSend(RaygunClient client, String jsonPayload) { if (!enabled) { return jsonPayload; } OutputStream fileOutputStream = null; try { File file = getFile(); if (file == null) { return jsonPayload; } fileOutputStream = getOutputStream(file); fileOutputStream.write(jsonPayload.getBytes()); exceptionLogged = false; hasStoredExceptions = true; } catch (Exception e1) { if(!exceptionLogged) { Logger.getLogger("Raygun4Java").warning("exception adding to offline storage: " + e1.getMessage()); exceptionLogged = true; } } finally { if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException e1) { Logger.getLogger("Raygun4Java").warning("exception closing file stream: " + e1.getMessage()); } } } return jsonPayload; } RaygunOnFailedSendOfflineStorageHandler(String storageDir, String apiKey); }
RaygunOnFailedSendOfflineStorageHandler implements IRaygunOnFailedSend, IRaygunOnBeforeSend, IRaygunSendEventFactory { public String onFailedSend(RaygunClient client, String jsonPayload) { if (!enabled) { return jsonPayload; } OutputStream fileOutputStream = null; try { File file = getFile(); if (file == null) { return jsonPayload; } fileOutputStream = getOutputStream(file); fileOutputStream.write(jsonPayload.getBytes()); exceptionLogged = false; hasStoredExceptions = true; } catch (Exception e1) { if(!exceptionLogged) { Logger.getLogger("Raygun4Java").warning("exception adding to offline storage: " + e1.getMessage()); exceptionLogged = true; } } finally { if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException e1) { Logger.getLogger("Raygun4Java").warning("exception closing file stream: " + e1.getMessage()); } } } return jsonPayload; } RaygunOnFailedSendOfflineStorageHandler(String storageDir, String apiKey); void setEnabled(boolean enabled); RaygunMessage onBeforeSend(RaygunClient client, RaygunMessage message); String onFailedSend(RaygunClient client, String jsonPayload); IRaygunOnBeforeSend create(); }
RaygunOnFailedSendOfflineStorageHandler implements IRaygunOnFailedSend, IRaygunOnBeforeSend, IRaygunSendEventFactory { public String onFailedSend(RaygunClient client, String jsonPayload) { if (!enabled) { return jsonPayload; } OutputStream fileOutputStream = null; try { File file = getFile(); if (file == null) { return jsonPayload; } fileOutputStream = getOutputStream(file); fileOutputStream.write(jsonPayload.getBytes()); exceptionLogged = false; hasStoredExceptions = true; } catch (Exception e1) { if(!exceptionLogged) { Logger.getLogger("Raygun4Java").warning("exception adding to offline storage: " + e1.getMessage()); exceptionLogged = true; } } finally { if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException e1) { Logger.getLogger("Raygun4Java").warning("exception closing file stream: " + e1.getMessage()); } } } return jsonPayload; } RaygunOnFailedSendOfflineStorageHandler(String storageDir, String apiKey); void setEnabled(boolean enabled); RaygunMessage onBeforeSend(RaygunClient client, RaygunMessage message); String onFailedSend(RaygunClient client, String jsonPayload); IRaygunOnBeforeSend create();  }