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);
}
}
Aggregations