void startJettyServer() { try { server.start(); } catch (Exception e) { logger.error(e.getMessage(), e); throw new SystemException("Internal jetty server can not be started!", 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 } } }
/** * 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); } }
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); } }
logger.info("ActiveMQ Total Queue Size is too high (" + totalQueueSize + ">" + totalQueueSizeLimit + "), AMQ restart initiated."); } catch (Exception e) { throw new SystemException("ActiveMQ Total Queue Size is too high (\" + totalQueueSize + \">\" + totalQueueSizeLimit + \"), AMQ RESTART FAILED.", e); if (!(e instanceof InstanceNotFoundException)) { if (valueIsValid) { throw new SystemException("ActiveMQ Memory usage is too high:" + memoryPercentUsage + "%, AMQ RESTART FAILED.", e); } else { throw new SystemException("ActiveMQ Memory usage cannot be detected.", 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; }
@Override public ByteArrayOutputStream decompress(final InputStream inputStream) { StreamResult streamResult = streamResultFactory.createStreamResult(); InputStream fiDocument = inputStream; ByteArrayOutputStream baos = outputStreamFactory.createByteArrayOutputStream(); try { Transformer tx = fastInfosetTransformerFactory.createTransformer(); tx.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); tx.setOutputProperty(OutputKeys.INDENT, "yes"); FastInfosetSource fastInfosetSource = fastInfosetSourceFactory.createFastInfosetSource(fiDocument); tx.transform(fastInfosetSource, streamResult); fiDocument.close(); baos.write(streamResult.getWriter().toString().getBytes()); } catch (TransformerFactoryConfigurationError | Exception e) { throw new SystemException("Could not perform fastinfoset decompression!", e); } return baos; }
@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 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); }
@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); }
@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(); }
@Override public void onMessage(final Message message) { if (message instanceof ObjectMessage) { try { WilmaHttpResponse response = getWilmaHttpResponseFromMessage(message); boolean consistentFIDecompressionEnabled = fiDecompressionEnabled; if (consistentFIDecompressionEnabled) { messageExtractor.extract(response); } response.setInputStream(null); if (messageLoggingEnabled && response.isLoggingEnabled()) { jmsTemplate.send(loggerQueue, messageCreatorFactory.create(response, consistentFIDecompressionEnabled)); } manager.tryToSaveResponseIntoSequence(response); } catch (JMSException e) { throw new SystemException("JMS Exception occurred", e); } } else { throw new IllegalArgumentException("Message must be of type ObjectMessage"); } }
@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); }