use of com.google.api.ads.common.lib.exception.ServiceException 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);
}
}
use of com.google.api.ads.common.lib.exception.ServiceException in project googleads-java-lib by googleads.
the class JaxWsSoapContextHandler method handleMessage.
/**
* Captures pertinent information from SOAP messages exchanged by the SOAP
* service this handler is attached to. Also responsible for placing custom
* (implicit) SOAP headers on outgoing messages.
*
* @see SOAPHandler#handleMessage(MessageContext)
* @param context the context of the SOAP message passing through this handler
* @return whether this SOAP interaction should continue
*/
@Override
public boolean handleMessage(SOAPMessageContext context) {
if ((Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
// Outbound message (request), so reset the last request and response builders.
lastRequestInfo = new RequestInfo.Builder();
lastResponseInfo = new ResponseInfo.Builder();
SOAPMessage soapMessage = context.getMessage();
try {
SOAPHeader soapHeader = soapMessage.getSOAPHeader();
if (soapHeader == null) {
soapHeader = soapMessage.getSOAPPart().getEnvelope().addHeader();
}
for (SOAPElement header : soapHeaders) {
soapHeader.addChildElement(header);
}
} catch (SOAPException e) {
throw new ServiceException("Error setting SOAP headers on outbound message.", e);
}
captureServiceAndOperationNames(context);
}
captureSoapXml(context);
return true;
}
Aggregations