void startJettyServer() { try { server.start(); } catch (Exception e) { logger.error(e.getMessage(), e); throw new SystemException("Internal jetty server can not be started!", e); } }
/** * Converts an inputStream to a String with Apache Commons' IOUtils. * @param inputStream InputStream to convert * @return converted stream * @throws ApplicationException when IOUtils or mark/reset fails */ public String getStringFromStream(final InputStream inputStream) throws ApplicationException { String result = ""; if (inputStream != null) { try { int extendedReadLimit = inputStream.available() + BUFFER_SIZE; inputStream.mark(extendedReadLimit); result = IOUtils.toString(inputStream); inputStream.reset(); } catch (IOException e) { throw new ApplicationException("Could not transform request input stream into string!", e); } } return result; } }
/** * Creates a new CronTrigger. * @param cronExpression the cronExpression that is used for the CronTrigger * @return created CronTrigger */ public CronTrigger createCronTrigger(final String cronExpression) { CronTrigger result; try { result = new CronTrigger(cronExpression); } catch (IllegalArgumentException e) { throw new SchedulingCannotBeStartedException("Scheduling cannot be started, cron expression given in properties file is not valid! " + e.getMessage(), e); } return result; }
@Test public void testFailedWhenSystemExceptionAndErrorCauseExistsShouldLogErrorAtErrorLevel() { //GIVEN State state = Mockito.mock(State.class); SystemException exception = new SystemException(ERR_MSG); Throwable cause = new Throwable(); exception.initCause(cause); //WHEN underTest.failed(state, exception); //THEN verify(logger).error(FAILED_MESSAGE, exception); }
@Override public void process(final BrowserMobHttpRequest request) { try { WilmaHttpRequest wilmaHttpRequest = httpRequestTransformer.transformRequest(request); wilmaHttpRequestProcessor.processRequest(wilmaHttpRequest); browserMobRequestUpdater.updateRequest(request, wilmaHttpRequest); } catch (ApplicationException e) { logger.error(e.getMessage(), e); } }
private void logErrorByTypeOfException(final Exception e) { SystemException ex = systemExceptionSelector.getSystemException(e); if (ex != null) { logError(ex.getMessage(), ex); } else { logError("", e); } }
/** * Adds a file to the system classpath. * @param folder the folder that contains the class file */ public void addFile(final String folder) { parameters = new Class[]{URL.class}; File f = new File(folder); try { addFile(f); } catch (IOException e) { throw new com.epam.wilma.domain.exception.SystemException("could not put class file to classpath", e); } }
/** * Starts the scheduling of the {@link SequenceCleanerTask}. */ public void startScheduling() { CronTrigger cronTrigger = createCronTrigger(); if (maintainerTask != null) { taskScheduler.schedule(maintainerTask, cronTrigger); } else { throw new SchedulingCannotBeStartedException("Scheduling cannot be started, in Sequence module."); } }
@Test public void testExtractShouldDoNothingWhenExceptionIsThrown() throws Exception { doThrow(new ApplicationException("")).when(base64DecoderProcessor).process(message); underTest.extract(message); } }
@Override public void process(final BrowserMobHttpResponse response) { try { WilmaHttpResponse wilmaResponse = responseTransformer.transformResponse(response); responseProcessor.processResponse(wilmaResponse); browserMobResponseUpdater.updateResponse(response, wilmaResponse); } catch (ApplicationException e) { logger.error(e.getMessage(), e); } } }
private void resetDlqAsNecessary() { boolean sizeIsValid = false; Long dlqSize = Long.valueOf(0); try { dlqSize = (Long) mBeanServerConnection.getAttribute(dlqQueue, QUEUE_SIZE_TEXT); sizeIsValid = true; if (dlqSize > 0) { mBeanServerConnection.invoke(dlqQueue, "purge", null, null); logger.info("Message found in ActiveMQ.DLQ. Queue size is: " + dlqSize + ", queue purged successfully."); } } catch (Exception e) { if (!(e instanceof InstanceNotFoundException)) { if (sizeIsValid) { throw new SystemException("Message found in ActiveMQ.DLQ. Queue size is: " + dlqSize + ", QUEUE PURGE FAILED.", e); } else { throw new SystemException("Message found in ActiveMQ.DLQ. Queue size cannot be detected.", e); } //otherwise no DLQ exists, and that is fine } } }
/** * Starts the scheduling of the LogFileMaintainerTask. */ public void startScheduling() { CronTrigger cronTrigger = createCronTrigger(); MaintainerMethod method = getMaintainerMethod(); MaintainerTask maintainerTask = maintainerTasks.get(method); if (maintainerTask != null) { taskScheduler.schedule(maintainerTask, cronTrigger); maintainerTask.logParameters(); } else { throw new SchedulingCannotBeStartedException("Scheduling cannot be started, maintenance method given in properties file is not valid!"); } }
@Test public void testProcessShouldLogErrorWhenRequestTransformerThrowsApplicationException() throws ApplicationException { // GIVEN ApplicationException e = new ApplicationException(EMPTY_STRING); given(httpRequestTransformer.transformRequest(bmRequest)).willThrow(e); // WHEN underTest.process(bmRequest); // THEN verify(logger).error(EMPTY_STRING, e); }
private Long retrieveQuerySize() { try { Long responseQueueSize = (Long) mBeanServerConnection.getAttribute(responseQueue, QUEUE_SIZE_TEXT); Long loggerQueueSize = (Long) mBeanServerConnection.getAttribute(loggerQueue, QUEUE_SIZE_TEXT); queueSizeProvider.setResponseQueueSize(responseQueueSize); queueSizeProvider.setLoggerQueueSize(loggerQueueSize); return responseQueueSize + loggerQueueSize; } catch (Exception e) { throw new SystemException("Exception while monitoring queue sizes", e); } }
@Override public ByteArrayOutputStream decompress(final InputStream inputStream) { OutputStream writer = outputStreamFactory.createByteArrayOutputStream(); try { GZIPInputStream gzipStream = gzipInputStreamFactory.createInputStream(inputStream); IOUtils.copy(gzipStream, writer); } catch (IOException e) { throw new SystemException("Could not ungzip message body!", e); } return (ByteArrayOutputStream) writer; } }
/** * Compresses an {@link InputStream} object into gzip. * @param inputStream the inputstream that will be compressed * @return a {@link ByteArrayOutputStream} containing gzipped byte array */ @Override public ByteArrayOutputStream compress(final InputStream inputStream) { InputStream source = inputStream; ByteArrayOutputStream baos = outputStreamFactory.createByteArrayOutputStream(); try { GZIPOutputStream gout = gzipOutputStreamFactory.createOutputStream(baos); //... Code to read from your original uncompressed data and write to gout. IOUtils.copy(source, gout); gout.finish(); gout.close(); } catch (IOException e) { throw new SystemException("Could not gzip message body!", e); } return baos; }
@Test public void testFailedShouldLogError() { //GIVEN SystemException e = new SystemException(ERR_MSG); State state = Mockito.mock(State.class); //WHEN underTest.failed(state, e); //THEN verify(logger).error(FAILED_MESSAGE, e); }
@Override public ByteArrayOutputStream compress(final InputStream inputStream) { InputStream source = inputStream; try { ByteArrayOutputStream fis = outputStreamFactory.createByteArrayOutputStream(); SAXDocumentSerializer saxDocumentSerializer = documentSerializerFactory.createSAXDocumentSerializer(); saxDocumentSerializer.setOutputStream(fis); SAXParserFactory saxParserFactory = saxParserCreator.createSAXParserFactory(); saxParserFactory.setNamespaceAware(true); SAXParser saxParser = saxParserFactory.newSAXParser(); saxParser.parse(source, saxDocumentSerializer); return fis; } catch (Exception e) { throw new SystemException("Could not perform fastinfoset compression!", e); } }
@Test public void testStartWhenSystemExceptionShouldStopServers() { //GIVEN SystemException e = new SystemException(ERR_MSG); doThrow(e).when(proxy).start(); //WHEN underTest.start(); //THEN verify(webAppServer).stop(); verify(proxy).stop(); verify(applicationCloser).closeTriggers(); }
@Test(expectedExceptions = SystemException.class) public void testStartWhenStartJettyServerThrowsExceptionShouldThrowSystemException() { //GIVEN String exceptionMessage = "exception"; SystemException e = new SystemException("Something went wrong :("); willThrow(e).given(underTest).startJettyServer(); given(serverFactory.createServer(serverProperties)).willReturn(jettyServer); //WHEN underTest.start(); //THEN verify(logger).error(exceptionMessage, e); }