public void logRequestDetails(RemoteCallReturn remoteCallReturn) { if (remoteCallReturn == null) { return; } boolean isSuccess = remoteCallReturn.getException() == null; if (!isDetailsLoggable(isSuccess)) { return; } String prettyRequest = null; if (remoteCallReturn.getRequestInfo() != null) { prettyRequest = prettyPrinter.prettyPrint(remoteCallReturn.getRequestInfo().getPayload()); } String prettyResponse = null; if (remoteCallReturn.getResponseInfo() != null) { prettyResponse = prettyPrinter.prettyPrint(remoteCallReturn.getResponseInfo().getPayload()); } if (isSuccess) { detailLogger.debug(DETAILS_REQUEST_TEMPLATE, remoteCallType, prettyRequest); detailLogger.debug(DETAILS_RESPONSE_TEMPLATE, remoteCallType, prettyResponse); } else { detailLogger.info(DETAILS_REQUEST_TEMPLATE, remoteCallType, prettyRequest); detailLogger.info(DETAILS_RESPONSE_TEMPLATE, remoteCallType, prettyResponse); } }
/** * Constructor. */ public Builder() { this.remoteCallReturn = new RemoteCallReturn(); }
/** * Unwraps a SOAP remote call return such that if there was an exception, it is * thrown and if it was a successful call, the return value of the SOAP call * is returned. * * @param remoteCallReturn the {@link RemoteCallReturn} to unwrap * @return the {@link RemoteCallReturn#getReturnValue()} if the call was * successful * @throws Throwable the exception captured in the * {@link RemoteCallReturn#getException()} if present */ protected Object unwrapRemoteCallReturn(RemoteCallReturn remoteCallReturn) throws Throwable { if (remoteCallReturn.getException() != null) { throw handleException(remoteCallReturn.getException()); } else { return remoteCallReturn.getReturnValue(); } } }
@Test public void testLogRequestDetails_failure_infoLevelEnabled() { Throwable returnedException = new Throwable(); remoteCallReturn = new RemoteCallReturn.Builder() .withRequestInfo(remoteCallReturn.getRequestInfo()) .withResponseInfo(remoteCallReturn.getResponseInfo()) .withException(returnedException) .build(); when(soapXmlLogger.isInfoEnabled()).thenReturn(true); when(soapXmlLogger.isWarnEnabled()).thenReturn(true); loggerDelegate.logRequestDetails(remoteCallReturn); verify(soapXmlLogger) .info( RemoteCallLoggerDelegate.DETAILS_REQUEST_TEMPLATE, RemoteCallType.SOAP, prettyRequest); verify(soapXmlLogger) .info( RemoteCallLoggerDelegate.DETAILS_RESPONSE_TEMPLATE, RemoteCallType.SOAP, prettyResponse); }
/** * Confirms that passing {@code null} to {@code logUpload} for parameters marked {@code Nullable} * does not result in any exceptions. */ @Test public void testLogDownload_nullablesNull() { batchJobLogger.logDownload(url, null, null); ArgumentCaptor<RemoteCallReturn> returnCaptor = ArgumentCaptor.forClass(RemoteCallReturn.class); verify(loggerDelegate).logRequestSummary(returnCaptor.capture()); RemoteCallReturn capturedReturn = returnCaptor.getValue(); assertNull(capturedReturn.getException()); ResponseInfo responseInfo = capturedReturn.getResponseInfo(); assertEquals("Results count: 0", responseInfo.getPayload()); verify(loggerDelegate).logRequestDetails(returnCaptor.capture()); assertSame( "The same RemoteCallReturn object was not passed to request details and request summary", capturedReturn, returnCaptor.getValue()); } }
/** * Confirms that passing {@code null} to {@code logUpload} for parameters marked {@code Nullable} * does not result in any exceptions. */ @Test public void testLogUpload_nullablesNull() { String contentsString = "success contents"; ArgumentCaptor<RemoteCallReturn> returnCaptor = ArgumentCaptor.forClass(RemoteCallReturn.class); batchJobLogger.logUpload(contentsString, URI.create(url), null, null); verify(loggerDelegate).logRequestSummary(returnCaptor.capture()); RemoteCallReturn capturedReturn = returnCaptor.getValue(); assertNull(capturedReturn.getException()); verify(loggerDelegate).logRequestDetails(returnCaptor.capture()); assertSame( "The same RemoteCallReturn object was not passed to request details and request summary", capturedReturn, returnCaptor.getValue()); }
@Test public void testLogRequestSummary_success() { // Set up the request info mock. when(requestInfoLogger.isInfoEnabled()).thenReturn(true); loggerDelegate.logRequestSummary(remoteCallReturn); RequestInfo requestInfo = remoteCallReturn.getRequestInfo(); ResponseInfo responseInfo = remoteCallReturn.getResponseInfo(); verify(requestInfoLogger) .info( RemoteCallLoggerDelegate.SUMMARY_TEMPLATE, requestInfo.getServiceName(), requestInfo.getMethodName(), requestInfo.getContextName(), requestInfo.getContextValue(), requestInfo.getUrl(), responseInfo.getRequestId(), responseInfo.getResponseTime(), responseInfo.getOperationsCount(), false, null); }
@Test @SuppressWarnings("unchecked") public void testCallSoapClient_exception() { RemoteCallReturn expectedRemoteCallReturn = new RemoteCallReturn.Builder().withException(MockSoapClient.EXCEPTION).build(); SoapCall<Object> soapCall = Mockito.mock(SoapCall.class); when(soapClientHandler.invokeSoapCall(soapCall)).thenReturn(expectedRemoteCallReturn); RemoteCallReturn testRemoteCallReturn = soapServiceClient.callSoapClient(soapCall); assertSame(MockSoapClient.EXCEPTION, testRemoteCallReturn.getException()); }
public void logRequestDetails(RemoteCallReturn remoteCallReturn) { if (remoteCallReturn == null) { return; } boolean isSuccess = remoteCallReturn.getException() == null; if (!isDetailsLoggable(isSuccess)) { return; } String prettyRequest = null; if (remoteCallReturn.getRequestInfo() != null) { prettyRequest = prettyPrinter.prettyPrint(remoteCallReturn.getRequestInfo().getPayload()); } String prettyResponse = null; if (remoteCallReturn.getResponseInfo() != null) { prettyResponse = prettyPrinter.prettyPrint(remoteCallReturn.getResponseInfo().getPayload()); } if (isSuccess) { detailLogger.debug(DETAILS_REQUEST_TEMPLATE, remoteCallType, prettyRequest); detailLogger.debug(DETAILS_RESPONSE_TEMPLATE, remoteCallType, prettyResponse); } else { detailLogger.info(DETAILS_REQUEST_TEMPLATE, remoteCallType, prettyRequest); detailLogger.info(DETAILS_RESPONSE_TEMPLATE, remoteCallType, prettyResponse); } }
@Test public void testLogRequestSummary_failure() { Throwable returnedException = new Throwable(); remoteCallReturn = new RemoteCallReturn.Builder() .withRequestInfo(remoteCallReturn.getRequestInfo()) .withResponseInfo(remoteCallReturn.getResponseInfo()) .withException(returnedException) .build(); when(requestInfoLogger.isWarnEnabled()).thenReturn(true); loggerDelegate.logRequestSummary(remoteCallReturn); RequestInfo requestInfo = remoteCallReturn.getRequestInfo(); ResponseInfo responseInfo = remoteCallReturn.getResponseInfo(); verify(requestInfoLogger) .warn( RemoteCallLoggerDelegate.SUMMARY_TEMPLATE, requestInfo.getServiceName(), requestInfo.getMethodName(), requestInfo.getContextName(), requestInfo.getContextValue(), requestInfo.getUrl(), responseInfo.getRequestId(), responseInfo.getResponseTime(), responseInfo.getOperationsCount(), true, returnedException.toString()); }
/** * Unwraps a SOAP remote call return such that if there was an exception, it is * thrown and if it was a successful call, the return value of the SOAP call * is returned. * * @param remoteCallReturn the {@link RemoteCallReturn} to unwrap * @return the {@link RemoteCallReturn#getReturnValue()} if the call was * successful * @throws Throwable the exception captured in the * {@link RemoteCallReturn#getException()} if present */ protected Object unwrapRemoteCallReturn(RemoteCallReturn remoteCallReturn) throws Throwable { if (remoteCallReturn.getException() != null) { throw handleException(remoteCallReturn.getException()); } else { return remoteCallReturn.getReturnValue(); } } }
/** * Constructor. */ public Builder() { this.remoteCallReturn = new RemoteCallReturn(); }
return; boolean isSuccess = remoteCallReturn.getException() == null; if (!isSummaryLoggable(isSuccess)) { return; RequestInfo request = remoteCallReturn.getRequestInfo(); ResponseInfo response = remoteCallReturn.getResponseInfo(); Object[] logArgs = new Object[10]; if (request != null) { logArgs[6] = response.getResponseTime(); logArgs[7] = response.getOperationsCount(); Throwable throwable = remoteCallReturn.getException(); logArgs[8] = throwable != null; logArgs[9] = truncateThrowable(throwable, MAX_SUMMARY_ERROR_LENGTH);
return; boolean isSuccess = remoteCallReturn.getException() == null; if (!isSummaryLoggable(isSuccess)) { return; RequestInfo request = remoteCallReturn.getRequestInfo(); ResponseInfo response = remoteCallReturn.getResponseInfo(); Object[] logArgs = new Object[10]; if (request != null) { logArgs[6] = response.getResponseTime(); logArgs[7] = response.getOperationsCount(); Throwable throwable = remoteCallReturn.getException(); logArgs[8] = throwable != null; logArgs[9] = truncateThrowable(throwable, MAX_SUMMARY_ERROR_LENGTH);
verify(loggerDelegate).logRequestSummary(returnCaptor.capture()); RemoteCallReturn capturedReturn = returnCaptor.getValue(); assertEquals(exception, capturedReturn.getException()); RequestInfo requestInfo = capturedReturn.getRequestInfo(); assertEquals(url, requestInfo.getUrl()); assertEquals("clientCustomerId", requestInfo.getContextName()); assertThat(requestInfo.getServiceName(), containsString("download")); ResponseInfo responseInfo = capturedReturn.getResponseInfo(); assertNull(responseInfo.getRequestId()); assertEquals("Results count: 2", responseInfo.getPayload());
/** Confirms an upload is logged as expected. */ @Test public void testLogUpload() throws IOException { String contentsString = "some contents"; InputStream responseContent = CharSource.wrap(contentsString).asByteSource(UTF_8).openStream(); BatchJobUploadResponse response = new BatchJobUploadResponse( responseContent, statusCode, statusMessage, contentsString.length(), URI.create(url)); ArgumentCaptor<RemoteCallReturn> returnCaptor = ArgumentCaptor.forClass(RemoteCallReturn.class); batchJobLogger.logUpload(contentsString, URI.create(url), response, exception); verify(loggerDelegate).logRequestSummary(returnCaptor.capture()); RemoteCallReturn capturedReturn = returnCaptor.getValue(); assertEquals(exception, capturedReturn.getException()); RequestInfo requestInfo = capturedReturn.getRequestInfo(); assertEquals(url, requestInfo.getUrl()); assertEquals("clientCustomerId", requestInfo.getContextName()); assertNull(requestInfo.getContextValue()); assertThat(requestInfo.getPayload(), containsString(contentsString)); assertThat(requestInfo.getServiceName(), containsString("upload")); ResponseInfo responseInfo = capturedReturn.getResponseInfo(); assertNull(responseInfo.getRequestId()); assertThat(responseInfo.getPayload(), startsWith(String.valueOf(response.getHttpStatus()))); assertThat(responseInfo.getPayload(), containsString(response.getHttpResponseMessage())); verify(loggerDelegate).logRequestDetails(returnCaptor.capture()); assertSame( "The same RemoteCallReturn object was not passed to request details and request summary", capturedReturn, returnCaptor.getValue()); }