@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); }
@Test public void testInvoke_soapClientMethod() throws Throwable { Object returnValue = new Object(); RemoteCallReturn callReturn = new RemoteCallReturn.Builder().withReturnValue(returnValue).build(); Method identityCallMethod = MockSoapClient.class.getMethod("identityCall", Object[].class); Object[] arg = new String[] {"arg1", "arg2"}; Object[] args = new Object[] {arg}; SoapCall<Object> soapCall = new SoapCall<Object>(identityCallMethod, soapClient, args); when(soapClientHandler.getSoapClientMethod(soapClient, identityCallMethod)) .thenReturn(identityCallMethod); when(soapClientHandler.invokeSoapCall(soapCall)).thenReturn(callReturn); Object result = soapServiceClient.invoke(null, identityCallMethod, args); assertEquals(returnValue, result); }
@Test @SuppressWarnings("unchecked") public void testCallSoapClient() throws Throwable { RemoteCallReturn expectedRemoteCallReturn = new RemoteCallReturn.Builder().build(); SoapCall<Object> soapCall = Mockito.mock(SoapCall.class); when(soapClientHandler.invokeSoapCall(soapCall)).thenReturn(expectedRemoteCallReturn); RemoteCallReturn remoteCallReturn = soapServiceClient.callSoapClient(soapCall); assertSame(expectedRemoteCallReturn, remoteCallReturn); }
.withResponseInfo(responseInfoBuilder.build()) .withException(throwable) .build(); loggerDelegate.logRequestSummary(remoteCallReturn); loggerDelegate.logRequestDetails(remoteCallReturn);
.withResponseInfo(responseInfoBuilder.build()) .withException(throwable) .build(); loggerDelegate.logRequestSummary(remoteCallReturn); loggerDelegate.logRequestDetails(remoteCallReturn);
.withResponseInfo(responseInfo) .withException(throwable) .build(); loggerDelegate.logRequestSummary(remoteCallReturn); loggerDelegate.logRequestDetails(remoteCallReturn);
return builder.withReturnValue(result).build();
return builder.withReturnValue(result).build();
.withResponseInfo(responseInfo) .withException(throwable) .build(); loggerDelegate.logRequestSummary(remoteCallReturn); loggerDelegate.logRequestDetails(remoteCallReturn);
/** * Logs the specified request and response information. * * <p>Note that in order to avoid any temptation to consume the contents of the response, this * does <em>not</em> take an {@link com.google.api.client.http.HttpResponse} object, but instead * accepts the status code and message from the response. */ public void logRequest( @Nullable HttpRequest request, int statusCode, @Nullable String statusMessage) { boolean isSuccess = HttpStatusCodes.isSuccess(statusCode); if (!loggerDelegate.isSummaryLoggable(isSuccess) && !loggerDelegate.isDetailsLoggable(isSuccess)) { return; } // Populate the RequestInfo builder from the request. RequestInfo requestInfo = buildRequestInfo(request); // Populate the ResponseInfo builder from the response. ResponseInfo responseInfo = buildResponseInfo(request, statusCode, statusMessage); RemoteCallReturn.Builder remoteCallReturnBuilder = new RemoteCallReturn.Builder().withRequestInfo(requestInfo).withResponseInfo(responseInfo); if (!isSuccess) { remoteCallReturnBuilder.withException( new ReportException(String.format("%s: %s", statusCode, statusMessage))); } RemoteCallReturn remoteCallReturn = remoteCallReturnBuilder.build(); loggerDelegate.logRequestSummary(remoteCallReturn); loggerDelegate.logRequestDetails(remoteCallReturn); }
/** * Logs the specified request and response information. * * <p>Note that in order to avoid any temptation to consume the contents of the response, this * does <em>not</em> take an {@link com.google.api.client.http.HttpResponse} object, but instead * accepts the status code and message from the response. */ public void logRequest( @Nullable HttpRequest request, int statusCode, @Nullable String statusMessage) { boolean isSuccess = HttpStatusCodes.isSuccess(statusCode); if (!loggerDelegate.isSummaryLoggable(isSuccess) && !loggerDelegate.isDetailsLoggable(isSuccess)) { return; } // Populate the RequestInfo builder from the request. RequestInfo requestInfo = buildRequestInfo(request); // Populate the ResponseInfo builder from the response. ResponseInfo responseInfo = buildResponseInfo(request, statusCode, statusMessage); RemoteCallReturn.Builder remoteCallReturnBuilder = new RemoteCallReturn.Builder().withRequestInfo(requestInfo).withResponseInfo(responseInfo); if (!isSuccess) { remoteCallReturnBuilder.withException( new ReportException(String.format("%s: %s", statusCode, statusMessage))); } RemoteCallReturn remoteCallReturn = remoteCallReturnBuilder.build(); loggerDelegate.logRequestSummary(remoteCallReturn); loggerDelegate.logRequestDetails(remoteCallReturn); }
/** * Invoke a SOAP call. * * @param soapCall the call to make to a SOAP web service * @return information about the SOAP response */ @Override public RemoteCallReturn invokeSoapCall(SoapCall<BindingProvider> soapCall) { BindingProvider webService = soapCall.getSoapClient(); RemoteCallReturn.Builder builder = new RemoteCallReturn.Builder(); synchronized (webService) { Object result = null; try { result = invoke(soapCall); } catch (InvocationTargetException e) { builder.withException(e.getTargetException()); } catch (Exception e) { builder.withException(e); } finally { JaxWsSoapContextHandler contextHandler = getContextHandlerFromClient(webService); String url = getEndpointAddress(webService); builder.withRequestInfo(contextHandler.getLastRequestInfoBuilder().withUrl(url).build()); builder.withResponseInfo(contextHandler.getLastResponseInfoBuilder().build()); } return builder.withReturnValue(result).build(); } }
/** * Invoke a SOAP call. * * @param soapCall the call to make to a SOAP web service * @return information about the SOAP response */ @Override public RemoteCallReturn invokeSoapCall(SoapCall<BindingProvider> soapCall) { BindingProvider webService = soapCall.getSoapClient(); RemoteCallReturn.Builder builder = new RemoteCallReturn.Builder(); synchronized (webService) { Object result = null; try { result = invoke(soapCall); } catch (InvocationTargetException e) { builder.withException(e.getTargetException()); } catch (Exception e) { builder.withException(e); } finally { JaxWsSoapContextHandler contextHandler = getContextHandlerFromClient(webService); String url = getEndpointAddress(webService); builder.withRequestInfo(contextHandler.getLastRequestInfoBuilder().withUrl(url).build()); builder.withResponseInfo(contextHandler.getLastResponseInfoBuilder().build()); } return builder.withReturnValue(result).build(); } }
@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()); }
@Test public void testUnwrapRemoteCallReturn_exception() throws Throwable { RemoteCallReturn remoteCallReturn = new RemoteCallReturn.Builder().withException(new NoSuchMethodException()).build(); thrown.expect(NoSuchMethodException.class); soapServiceClient.unwrapRemoteCallReturn(remoteCallReturn); }
@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()); }
@Test public void testUnwrapRemoteCallReturn_successful() throws Throwable { Object expectedReturnValue = "return"; RemoteCallReturn remoteCallReturn = new RemoteCallReturn.Builder().withReturnValue(expectedReturnValue).build(); assertEquals(expectedReturnValue, soapServiceClient.unwrapRemoteCallReturn(remoteCallReturn)); }