Search in sources :

Example 1 with Stub

use of org.apache.axis.client.Stub in project googleads-java-lib by googleads.

the class AdManagerAxisHeaderHandler method setHeaders.

/**
 * @see HeaderHandler#setHeaders(Object, com.google.api.ads.common.lib.client.AdsSession,
 *     com.google.api.ads.common.lib.client.AdsServiceDescriptor)
 */
@Override
public void setHeaders(Object soapClient, AdManagerSession adManagerSession, AdManagerServiceDescriptor adManagerServiceDescriptor) throws AuthenticationException, ServiceException {
    try {
        Preconditions.checkArgument(soapClient instanceof Stub, "soapClient must be Stub but was: %s", soapClient);
        Stub stub = (Stub) soapClient;
        adManagerHttpHeaderHandler.setHttpHeaders(soapClient, adManagerSession);
        Object soapHeader = createSoapHeader(adManagerServiceDescriptor);
        BeanUtils.setProperty(soapHeader, "applicationName", userAgentCombiner.getUserAgent(adManagerSession.getApplicationName()));
        if (adManagerSession.getNetworkCode() != null) {
            BeanUtils.setProperty(soapHeader, "networkCode", adManagerSession.getNetworkCode());
        }
        setAuthenticationHeaders(soapClient, adManagerSession);
        String namespace = adManagerApiConfiguration.getNamespacePrefix() + "/" + adManagerServiceDescriptor.getVersion();
        soapClientHandler.setHeader(stub, namespace, "RequestHeader", soapHeader);
        soapClientHandler.setCompression(stub, adsLibConfiguration.isCompressionEnabled());
        soapClientHandler.setRequestTimeout(stub, adsLibConfiguration.getSoapRequestTimeout());
    } catch (InstantiationException e) {
        throw new ServiceException("Unexpected exception.", e);
    } catch (IllegalAccessException e) {
        throw new ServiceException("Unexpected exception.", e);
    } catch (ClassNotFoundException e) {
        throw new ServiceException("Unexpected exception.", e);
    } catch (InvocationTargetException e) {
        throw new ServiceException("Unexpected exception.", e);
    } catch (IllegalArgumentException e) {
        throw new ServiceException("Unexpected exception.", e);
    } catch (SecurityException e) {
        throw new ServiceException("Unexpected exception.", e);
    }
}
Also used : ServiceException(com.google.api.ads.common.lib.exception.ServiceException) Stub(org.apache.axis.client.Stub) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with Stub

use of org.apache.axis.client.Stub in project googleads-java-lib by googleads.

the class AdWordsAxisHeaderHandler method setHeaders.

/**
 * @see HeaderHandler#setHeaders(Object,
 *      com.google.api.ads.common.lib.client.AdsSession,
 *      com.google.api.ads.common.lib.client.AdsServiceDescriptor)
 */
@Override
public void setHeaders(Object soapClient, AdWordsSession adWordsSession, AdWordsServiceDescriptor adWordsServiceDescriptor) throws AuthenticationException, ServiceException {
    try {
        Preconditions.checkArgument(soapClient instanceof Stub, "soapClient must be Stub but was: %s", soapClient);
        Stub stub = (Stub) soapClient;
        Object soapHeader = soapHeaderFactory.createSoapHeader(adWordsServiceDescriptor);
        String namespace = adWordsApiConfiguration.getNamespacePrefix() + "/" + adWordsServiceDescriptor.getPackageGroup() + "/" + adWordsServiceDescriptor.getVersion();
        soapClientHandler.setHeader(stub, namespace, REQUEST_HEADER_LOCAL_PART, soapHeader);
        soapClientHandler.setHeaderChild(stub, REQUEST_HEADER_LOCAL_PART, "developerToken", adWordsSession.getDeveloperToken());
        soapClientHandler.setHeaderChild(stub, REQUEST_HEADER_LOCAL_PART, "clientCustomerId", adWordsSession.getClientCustomerId());
        soapClientHandler.setHeaderChild(stub, REQUEST_HEADER_LOCAL_PART, "userAgent", userAgentCombiner.getUserAgent(adWordsSession.getUserAgent()));
        soapClientHandler.setHeaderChild(stub, REQUEST_HEADER_LOCAL_PART, "validateOnly", adWordsSession.isValidateOnly());
        soapClientHandler.setHeaderChild(stub, REQUEST_HEADER_LOCAL_PART, "partialFailure", adWordsSession.isPartialFailure());
        soapClientHandler.setCompression(stub, adsLibConfiguration.isCompressionEnabled());
        soapClientHandler.setRequestTimeout(stub, adsLibConfiguration.getSoapRequestTimeout());
        authorizationHeaderHandler.setAuthorization(soapClient, adWordsSession);
    } catch (InstantiationException | IllegalAccessException | ServiceException | ClassNotFoundException | InvocationTargetException | NoSuchMethodException e) {
        throw new ServiceException("Unexpected exception setting headers for: " + adWordsServiceDescriptor, e);
    }
}
Also used : ServiceException(com.google.api.ads.common.lib.exception.ServiceException) Stub(org.apache.axis.client.Stub) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with Stub

use of org.apache.axis.client.Stub in project googleads-java-lib by googleads.

the class AxisHandler method createSoapClient.

/**
 * Creates a SOAP client using a SOAP service descriptor.
 *
 * @param soapServiceDescriptor the descriptor to use for creating a client
 * @return the SOAP client for this descriptor
 * @throws ServiceException thrown if the SOAP client cannot be created
 */
@Override
public Stub createSoapClient(SoapServiceDescriptor soapServiceDescriptor) throws ServiceException {
    try {
        if (soapServiceDescriptor instanceof AxisCompatible) {
            AxisCompatible axisCompatibleService = (AxisCompatible) soapServiceDescriptor;
            EngineConfiguration engineConfiguration = engineConfigurationFactory.getClientEngineConfig();
            Service locator = (Service) axisCompatibleService.getLocatorClass().getConstructor(new Class[] { EngineConfiguration.class }).newInstance(new Object[] { engineConfiguration });
            return (Stub) locator.getClass().getMethod("getPort", Class.class).invoke(locator, soapServiceDescriptor.getInterfaceClass());
        }
        throw new ServiceException("Service [" + soapServiceDescriptor + "] not compatible with Axis", null);
    } catch (SecurityException e) {
        throw new ServiceException("Unexpected Exception.", e);
    } catch (NoSuchMethodException e) {
        throw new ServiceException("Unexpected Exception.", e);
    } catch (IllegalArgumentException e) {
        throw new ServiceException("Unexpected Exception.", e);
    } catch (IllegalAccessException e) {
        throw new ServiceException("Unexpected Exception.", e);
    } catch (InvocationTargetException e) {
        throw new ServiceException("Unexpected Exception.", e);
    } catch (ClassNotFoundException e) {
        throw new ServiceException("Unexpected Exception.", e);
    } catch (InstantiationException e) {
        throw new ServiceException("Unexpected Exception.", e);
    }
}
Also used : Service(org.apache.axis.client.Service) Stub(org.apache.axis.client.Stub) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServiceException(com.google.api.ads.common.lib.exception.ServiceException) EngineConfiguration(org.apache.axis.EngineConfiguration) AxisCompatible(com.google.api.ads.common.lib.soap.compatability.AxisCompatible)

Example 4 with Stub

use of org.apache.axis.client.Stub in project googleads-java-lib by googleads.

the class AxisHandler method invokeSoapCall.

/**
 * 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<Stub> soapCall) {
    Stub stub = soapCall.getSoapClient();
    RemoteCallReturn.Builder builder = new RemoteCallReturn.Builder();
    synchronized (stub) {
        Object result = null;
        try {
            result = invoke(soapCall);
        } catch (InvocationTargetException e) {
            builder.withException(e.getTargetException());
        } catch (Exception e) {
            builder.withException(e);
        } finally {
            MessageContext messageContext = stub._getCall().getMessageContext();
            RequestInfo.Builder requestInfoBuilder = new RequestInfo.Builder().withMethodName(stub._getCall().getOperationName().getLocalPart()).withServiceName(stub._getService().getServiceName().getLocalPart()).withUrl(stub._getCall().getTargetEndpointAddress());
            requestInfoXPathSet.parseMessage(requestInfoBuilder, messageContext.getRequestMessage());
            builder.withRequestInfo(requestInfoBuilder.build());
            ResponseInfo.Builder responseInfoBuilder = new ResponseInfo.Builder();
            responseInfoXPathSet.parseMessage(responseInfoBuilder, messageContext.getResponseMessage());
            builder.withResponseInfo(responseInfoBuilder.build());
        }
        return builder.withReturnValue(result).build();
    }
}
Also used : ResponseInfo(com.google.api.ads.common.lib.client.ResponseInfo) Stub(org.apache.axis.client.Stub) MessageContext(org.apache.axis.MessageContext) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) InvocationTargetException(java.lang.reflect.InvocationTargetException) SOAPException(javax.xml.soap.SOAPException) ServiceException(com.google.api.ads.common.lib.exception.ServiceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteCallReturn(com.google.api.ads.common.lib.client.RemoteCallReturn)

Aggregations

ServiceException (com.google.api.ads.common.lib.exception.ServiceException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Stub (org.apache.axis.client.Stub)4 RemoteCallReturn (com.google.api.ads.common.lib.client.RemoteCallReturn)1 RequestInfo (com.google.api.ads.common.lib.client.RequestInfo)1 ResponseInfo (com.google.api.ads.common.lib.client.ResponseInfo)1 AxisCompatible (com.google.api.ads.common.lib.soap.compatability.AxisCompatible)1 SOAPException (javax.xml.soap.SOAPException)1 EngineConfiguration (org.apache.axis.EngineConfiguration)1 MessageContext (org.apache.axis.MessageContext)1 Service (org.apache.axis.client.Service)1