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