Search in sources :

Example 1 with JaxWsCompatible

use of com.google.api.ads.common.lib.soap.compatability.JaxWsCompatible in project googleads-java-lib by googleads.

the class JaxWsHandler 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 BindingProvider createSoapClient(SoapServiceDescriptor soapServiceDescriptor) throws ServiceException {
    try {
        if (soapServiceDescriptor instanceof JaxWsCompatible) {
            JaxWsCompatible jaxWsCompatibleService = (JaxWsCompatible) soapServiceDescriptor;
            Object portLocator = jaxWsCompatibleService.getServiceClass().getConstructor(new Class[0]).newInstance(new Object[0]);
            String interfaceClassName = soapServiceDescriptor.getInterfaceClass().getSimpleName();
            BindingProvider soapClient = (BindingProvider) portLocator.getClass().getMethod("get" + interfaceClassName + "Port").invoke(portLocator);
            // Required for App Engine to avoid default 10s timeout for UrlFetch requests.
            setConnectTimeout(soapClient);
            // getHandlerChain returns a list of raw Handler.
            @SuppressWarnings("rawtypes") List<Handler> bindings = soapClient.getBinding().getHandlerChain();
            bindings.add(contextHandlerProvider.get());
            soapClient.getBinding().setHandlerChain(bindings);
            return soapClient;
        }
        throw new ServiceException("Service [" + soapServiceDescriptor + "] is not compatible with JAX-WS", 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.getCause());
    } catch (ClassNotFoundException e) {
        throw new ServiceException("Unexpected Exception.", e);
    } catch (InstantiationException e) {
        throw new ServiceException("Unexpected Exception.", e);
    }
}
Also used : JaxWsCompatible(com.google.api.ads.common.lib.soap.compatability.JaxWsCompatible) Handler(javax.xml.ws.handler.Handler) SoapClientHandler(com.google.api.ads.common.lib.soap.SoapClientHandler) BindingProvider(javax.xml.ws.BindingProvider) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServiceException(com.google.api.ads.common.lib.exception.ServiceException)

Aggregations

ServiceException (com.google.api.ads.common.lib.exception.ServiceException)1 SoapClientHandler (com.google.api.ads.common.lib.soap.SoapClientHandler)1 JaxWsCompatible (com.google.api.ads.common.lib.soap.compatability.JaxWsCompatible)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 BindingProvider (javax.xml.ws.BindingProvider)1 Handler (javax.xml.ws.handler.Handler)1