Search in sources :

Example 11 with ServiceException

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

Example 12 with ServiceException

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;
}
Also used : ResponseInfo(com.google.api.ads.common.lib.client.ResponseInfo) ServiceException(com.google.api.ads.common.lib.exception.ServiceException) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader)

Aggregations

ServiceException (com.google.api.ads.common.lib.exception.ServiceException)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 SOAPException (javax.xml.soap.SOAPException)5 SOAPElement (javax.xml.soap.SOAPElement)4 QName (javax.xml.namespace.QName)3 Stub (org.apache.axis.client.Stub)3 SOAPFactory (javax.xml.soap.SOAPFactory)2 SOAPHeaderElement (org.apache.axis.message.SOAPHeaderElement)2 RequestInfo (com.google.api.ads.common.lib.client.RequestInfo)1 ResponseInfo (com.google.api.ads.common.lib.client.ResponseInfo)1 SoapClientHandler (com.google.api.ads.common.lib.soap.SoapClientHandler)1 AxisCompatible (com.google.api.ads.common.lib.soap.compatability.AxisCompatible)1 JaxWsCompatible (com.google.api.ads.common.lib.soap.compatability.JaxWsCompatible)1 MalformedURLException (java.net.MalformedURLException)1 SOAPHeader (javax.xml.soap.SOAPHeader)1 SOAPMessage (javax.xml.soap.SOAPMessage)1 BindingProvider (javax.xml.ws.BindingProvider)1 Handler (javax.xml.ws.handler.Handler)1 EngineConfiguration (org.apache.axis.EngineConfiguration)1 Service (org.apache.axis.client.Service)1