/** * Creates the {@link SoapCall} from the {@code soapClientMethod} and its * {@code args}. */ protected SoapCall<T> createSoapCall(Method soapClientMethod, Object[] args) { return new SoapCall<T>(soapClientMethod, soapClient, args); }
/** * Sets the endpoint address of the underlying SOAP client. */ public void setEndpointAddress(String endpointAddress) { soapClientHandler.setEndpointAddress(soapClient, endpointAddress); }
/** * Sets the authentication headers. * * @param soapClient the SOAP client * @param adManagerSession the Ad Manager session * @throws AuthenticationException if there was a problem getting/setting the header */ private void setAuthenticationHeaders(Object soapClient, AdManagerSession adManagerSession) throws AuthenticationException { authorizationHeaderHandler.setAuthorization(soapClient, adManagerSession); }
/** * Takes a {@link SoapCall} object and invokes the method by reflection. * * @param soapCall contains the SOAP method, SOAP client, and args to be * called * @return the response from the SOAP web service * @throws Exception thrown if calling the operation on the remote service * fails */ protected Object invoke(SoapCall<T> soapCall) throws Exception { Method soapClientMethod = soapCall.getSoapClientMethod(); Object[] soapArgs = soapCall.getSoapArgs(); soapArgs = processSoapArguments(soapClientMethod, soapArgs); return soapClientMethod.invoke(soapCall.getSoapClient(), soapArgs); } }
/** * Captures the raw XML message behind a SOAP interaction. * * @param context the context of the SOAP message passing through this handler */ private void captureSoapXml(SOAPMessageContext context) { SOAPMessage message = context.getMessage(); if ((Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) { // Outbound message (request). requestInfoXPathSet.parseMessage(lastRequestInfo, message); } else { // Inbound message (response). responseInfoXPathSet.parseMessage(lastResponseInfo, message); } }
@Test public void testCreateSoapCall() throws SecurityException, NoSuchMethodException { Method indentityCallMethod = MockSoapClient.class.getMethod("identityCall", Object[].class); Object[] args = new String[] {"arg1", "arg2"}; SoapCall<Object> expectedSoapCall = new SoapCall<Object>(indentityCallMethod, soapClient, args); SoapCall<Object> soapCall = soapServiceClient.createSoapCall(indentityCallMethod, args); assertEquals(expectedSoapCall, soapCall); }
/** * Creates the SOAP client from the SOAP client handler. */ @VisibleForTesting Object createSoapClient(D adsServiceDescriptor) { return soapClientHandler.createSoapClient(adsServiceDescriptor); }
/** Sets the HTTP headers on the SOAP client. */ @SuppressWarnings("unchecked") /* See constructor comments. */ public void setHttpHeaders(Object soapClient, AdManagerSession adManagerSession) { Map<String, String> headersMap = Maps.newHashMap(); soapClientHandler.putAllHttpHeaders(soapClient, headersMap); }
@Test public void testSetEndpointAddress() { String expectedEndpointAddress = "endpoint"; soapServiceClient.setEndpointAddress(expectedEndpointAddress); verify(soapClientHandler).setEndpointAddress(soapClient, expectedEndpointAddress); }
@Test public void testInvoke_serviceClientMethod() throws Throwable { String endpointAddress = "http://test.com"; soapServiceClient.invoke(null, SoapServiceClient.class.getMethod("setEndpointAddress", String.class), new Object[] {endpointAddress}); verify(soapClientHandler).setEndpointAddress(soapClient, endpointAddress); }
/** * Called from {@link #invoke(Object, Method, Object[])} if the method is * intended for the SOAP client. Extending classes should override this method * if they wish to wrap the call, such in cases of reauthentication or * exception handling. The actual SOAP call is synchronized on the SOAP client * so that only one request to the SOAP client can be made with without * interruption, useful for logging and exception handling. * * @param soapCall the call to send to the SOAP client * @return the return value from the {@code soapCall} */ protected synchronized RemoteCallReturn callSoapClient(SoapCall<T> soapCall) { return soapClientHandler.invokeSoapCall(soapCall); }
/** * Takes a {@link SoapCall} object and invokes the method by reflection. * * @param soapCall contains the SOAP method, SOAP client, and args to be * called * @return the response from the SOAP web service * @throws Exception thrown if calling the operation on the remote service * fails */ protected Object invoke(SoapCall<T> soapCall) throws Exception { Method soapClientMethod = soapCall.getSoapClientMethod(); Object[] soapArgs = soapCall.getSoapArgs(); soapArgs = processSoapArguments(soapClientMethod, soapArgs); return soapClientMethod.invoke(soapCall.getSoapClient(), soapArgs); } }
/** * Sets the authentication headers. * * @param soapClient the SOAP client * @param adManagerSession the Ad Manager session * @throws AuthenticationException if there was a problem getting/setting the authorization header * @throws IllegalArgumentException if there was a problem setting the header */ private void setAuthenticationHeaders(Object soapClient, AdManagerSession adManagerSession) throws AuthenticationException { authorizationHeaderHandler.setAuthorization(soapClient, adManagerSession); }
/** * Captures the raw XML message behind a SOAP interaction. * * @param context the context of the SOAP message passing through this handler */ private void captureSoapXml(SOAPMessageContext context) { SOAPMessage message = context.getMessage(); if ((Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) { // Outbound message (request). requestInfoXPathSet.parseMessage(lastRequestInfo, message); } else { // Inbound message (response). responseInfoXPathSet.parseMessage(lastResponseInfo, message); } }
/** * Creates the {@link SoapCall} from the {@code soapClientMethod} and its * {@code args}. */ protected SoapCall<T> createSoapCall(Method soapClientMethod, Object[] args) { return new SoapCall<T>(soapClientMethod, soapClient, args); }
/** * Creates the SOAP client from the SOAP client handler. */ @VisibleForTesting Object createSoapClient(D adsServiceDescriptor) { return soapClientHandler.createSoapClient(adsServiceDescriptor); }
/** Sets the HTTP headers on the SOAP client. */ @SuppressWarnings("unchecked") /* See constructor comments. */ public void setHttpHeaders(Object soapClient, AdManagerSession adManagerSession) { Map<String, String> headersMap = Maps.newHashMap(); soapClientHandler.putAllHttpHeaders(soapClient, headersMap); }
/** * Sets the endpoint address of the underlying SOAP client. */ public void setEndpointAddress(String endpointAddress) { soapClientHandler.setEndpointAddress(soapClient, endpointAddress); }
/** * Called from {@link #invoke(Object, Method, Object[])} if the method is * intended for the SOAP client. Extending classes should override this method * if they wish to wrap the call, such in cases of reauthentication or * exception handling. The actual SOAP call is synchronized on the SOAP client * so that only one request to the SOAP client can be made with without * interruption, useful for logging and exception handling. * * @param soapCall the call to send to the SOAP client * @return the return value from the {@code soapCall} */ protected synchronized RemoteCallReturn callSoapClient(SoapCall<T> soapCall) { return soapClientHandler.invokeSoapCall(soapCall); }
/** * Sets the authentication headers. * * @param soapClient the SOAP client * @param headerElements the map housing header elements * @param adWordsSession the AdWords session * @throws AuthenticationException if there was a problem getting/setting the * header */ @VisibleForTesting void setAuthenticationHeaders(Object soapClient, Map<String, Object> headerElements, AdWordsSession adWordsSession) throws AuthenticationException { authorizationHeaderHandler.setAuthorization(soapClient, adWordsSession); }