Alejandro,
It looks like Axis2 v1.4's wsdl2java implementation automatically
generates SOAP 1.2 bindings for the service; these appear to be
slightly incompatible--at least, with respect to faults--with our
service, so I suggest you use either the '-ap' or '-pn v3/$
{SERVICENAME}SOAP11port_https' (where ${SERVICENAME} is similar to
AccountService, etc.) flags to generate SOAP 1.1 bindings. For
reference, my command looks like this:
./axis2-1.4.1/bin/wsdl2java.sh -p
com.google.api.adsense.v3.AccountService -ap -uri
https://sandbox.google.com/api/adsense/v3/AccountService?wsdl
After generating stubs for the AccountService, I wrote a short
(relatively speaking) java sample to call the CreateAccount method,
which I've appended below. I'm sure the formatting is going to get
messed up, but I hope you can get the idea. I'll write a few more and
then get them up under our sample code section.
// Copyright 2009 Google Inc. All Rights Reserved.
package com.google.api.adsense.v3.SampleCode;
import com.google.api.adsense.v3.AccountService.CreateAccountFault;
import
com.google.api.adsense.v3.AccountService.V3AccountServicev3AccountServiceSOAP11Port_httpsStub;
import
com.google.api.adsense.v3.AccountService.V3AccountServicev3AccountServiceSOAP11Port_httpsStub.SyndicationService_Data;
import org.apache.axis2.client.ServiceClient;
import org.apache.axiom.om.OMElement;
import java.util.Iterator;
import javax.xml.namespace.QName;
/**
* Sample code for calling AdSense API v3's CreateAccount method.
*
* @author
adsenseapi-...@google.com (Wes Goodman)
*/
public class CreateAccountSample {
static final String DEVELOPER_EMAIL = "DEVELOPER_EMAIL";
static final String DEVELOPER_PASS = "DEVELOPER_PASS";
static final String ADSENSE_V3_NS = "
http://www.google.com/api/
adsense/v3";
/**
* @param args
*/
public static void main(String[] args) {
try {
V3AccountServicev3AccountServiceSOAP11Port_httpsStub
account_service = new
V3AccountServicev3AccountServiceSOAP11Port_httpsStub();
ServiceClient service_client = account_service._getServiceClient
();
service_client.addStringHeader(new QName(ADSENSE_V3_NS,
"developer_email"), DEVELOPER_EMAIL);
service_client.addStringHeader(new QName(ADSENSE_V3_NS,
"developer_password"), DEVELOPER_PASS);
V3AccountServicev3AccountServiceSOAP11Port_httpsStub.CreateAccount
account_msg = new
V3AccountServicev3AccountServiceSOAP11Port_httpsStub.CreateAccount();
account_msg.setLoginEmail("USER'S_LOGIN_EMAIL");
V3AccountServicev3AccountServiceSOAP11Port_httpsStub.EntityType
entity_type = new
V3AccountServicev3AccountServiceSOAP11Port_httpsStub.EntityType();
entity_type.setValue("Individual");
account_msg.setEntityType(entity_type);
account_msg.setWebsiteUrl("
www.PLACEHOLDER_URL.org");
account_msg.setWebsiteLocale("en");
account_msg.setUsersPreferredLocale("en_US");
account_msg.setEmailPromotionsPreference(false);
V3AccountServicev3AccountServiceSOAP11Port_httpsStub.SyndicationService_Type
synservice_type = new
V3AccountServicev3AccountServiceSOAP11Port_httpsStub.SyndicationService_Type
();
synservice_type.setValue("ContentAds");
account_msg.addSynServiceTypes(synservice_type);
account_msg.setDeveloperUrl("
code.google.com");
V3AccountServicev3AccountServiceSOAP11Port_httpsStub.CreateAccountResponse
response = account_service.createAccount(account_msg);
V3AccountServicev3AccountServiceSOAP11Port_httpsStub.SyndicationService_Data
[] synservice_response = response.get_return();
for (SyndicationService_Data syndicationService_Data :
synservice_response) {
System.out.println("Syndication Type: " +
syndicationService_Data.getType().getValue());
System.out.println("Publisher Id: " +
syndicationService_Data.getId());
}
} catch (CreateAccountFault fault) {
System.out.println("Due to axis issues, only AxisFault will ever
be thrown");
System.out.println("Therefore, this catch block is for
completeness only.");
} catch (org.apache.axis2.AxisFault fault) {
OMElement faultElement = fault.getDetail();
OMElement exElement = (OMElement) (faultElement.getChildElements
().next());
Iterator<?> i = exElement.getChildElements();
OMElement codeElement = (OMElement) i.next();
OMElement internalElement = (OMElement) i.next();
OMElement messageElement = (OMElement) i.next();
OMElement triggerElement = (OMElement) i.next();
OMElement triggerDetailsElement = (OMElement) i.next();
System.out.println("Code: " + codeElement.getText());
System.out.println("Internal: " + internalElement.getText());
System.out.println("Message: " + messageElement.getText());
System.out.println("Trigger: " + triggerElement.getText());
System.out.println("Trigger Detail: " +
triggerDetailsElement.getText());
} catch (java.rmi.RemoteException e) {
System.out.println("remote exception");
}
}
}
Cheers,
Wes
AdSense API
> > > > When i get the wsdl from the sandbox, the stubs are generated usinghttp://
www.google.com/api/adsense/v3insteadoftheoldhttps://sandbox.google.com
> > > > firefox) to
httpS://www.google.com/api/adsense/v3andthenshowsme a