Nevermind...
I figured out how to use the Channel Advisor Admin Service API with
Java
For others that are on Java, here is a demonstration on how to
manipulate the admin service:
First create an AuthenticationHandler.java file:
//Set the package to wherever you've extracted the AdminService wsdl.
package com.channeladvisor.adminservice;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;
import org.apache.axis.*;
import org.apache.axis.handlers.BasicHandler;
import org.apache.axis.message.SOAPHeaderElement;
import org.apache.log4j.Logger;
/**
* User: Ezra Oh
* Date: Mar 2, 2012
* Time: 10:10:55 AM
*/
public class AuthenticationHandler extends BasicHandler {
public void invoke(MessageContext context) throws AxisFault {
try {
MessageContext smc = (MessageContext) context;
SOAPMessage message = smc.getMessage();
QName APICredentialsName = new QName("http://
api.channeladvisor.com/webservices/","APICredentials");
QName DeveloperKeyName = new QName("http://
api.channeladvisor.com/webservices/","DeveloperKey");
QName PasswordName = new QName("
http://api.channeladvisor.com/
webservices/", "Password");
SOAPHeader header = message.getSOAPHeader();
SOAPHeaderElement cred = new
SOAPHeaderElement(APICredentialsName);
SOAPHeaderElement key = new SOAPHeaderElement(DeveloperKeyName);
key.setObjectValue("<put your dev key here>");
SOAPHeaderElement pw = new SOAPHeaderElement(PasswordName);
pw.setObjectValue("<put your password here>");
cred.addChildElement(key);
cred.addChildElement(pw);
header.appendChild(cred);
} catch (Exception e) {
throw new AxisFault("Error during authentication", e);
}
}
}
Once you've created the AuthenticationHandler.java file, create a new
file called AdminServiceTestExample.java. Complie then run the
example file:
Note: This is just a demonstration. I'd run each test one at a time.
-Test #1 to verify you have connectivity
-Test #2 to request your Dev key access to a Profile ID
-Test #3 to view what's currently authorized for a given Profile ID
//Set the package to wherever you've extracted the AdminService wsdl.
package com.channeladvisor.adminservice;
import org.apache.axis.Handler;
import org.apache.axis.SimpleChain;
import org.apache.axis.SimpleTargetedChain;
import org.apache.axis.client.AxisClient;
import org.apache.axis.configuration.SimpleProvider;
import org.apache.axis.transport.http.HTTPSender;
import org.apache.axis.transport.http.HTTPTransport;
/**
* User: Ezra Oh
* Date: Mar 2, 2012
* Time: 12:06:48 PM
*/
public class AdminServiceTestExample {
public static void main(String[] args) throws Exception {
SimpleProvider provider = new SimpleProvider();
Handler handler = new AuthenticationHandler();
SimpleChain requestChain = new SimpleChain();
requestChain.addHandler(handler);
SimpleChain responseChain = new SimpleChain();
Handler sender = new HTTPSender();
Handler transport = new SimpleTargetedChain(requestChain,
sender, responseChain);
provider.deployTransport(HTTPTransport.DEFAULT_TRANSPORT_NAME,transport);
AdminServiceLocator locator = new AdminServiceLocator();
locator.setEngineConfiguration(provider);
locator.setEngine(new AxisClient(provider));
//Test #1: Ping the Admin Service and print the response to
the console
APIResultOfString pingResponse =
locator.getAdminServiceSoap().ping();
System.out.println(pingResponse.getResultData());
//Test #2: Request Access to a Profile ID
APIResultOfBoolean raResponse =
locator.getAdminServiceSoap().requestAccess(<put your Profile ID
Here>);
if(raResponse.isResultData()){
System.out.println("Request Access was successfully
submitted: " + raResponse.getStatus());
System.out.println("Now go into the Channel Advisor
Message Center and enable this Dev Key!");
}else{
System.out.println("There was a problem Requesting Access:
" + raResponse.getStatus());
}
//Test #3: With a given Profile ID, obtain a list of account
authorizations and print to the console
java.math.BigInteger bi = new java.math.BigInteger("<put your
Pofile ID Here>");
APIResultOfArrayOfAuthorizationResponse arrAuthResponse =
locator.getAdminServiceSoap().getAuthorizationList(bi);
AuthorizationResponse[] authResponse =
arrAuthResponse.getResultData().getAuthorizationResponse();
for(int i=0; i < authResponse.length; i++){
System.out.println("Account ID:" +
authResponse[i].getAccountID());
System.out.println("Account Name:" +
authResponse[i].getAccountName());
System.out.println("Account Type:" +
authResponse[i].getAccountType());
System.out.println("Local ID:" +
authResponse[i].getLocalID());
System.out.println("Resource Name:" +
authResponse[i].getResourceName());
System.out.println("Status:" +
authResponse[i].getStatus());
}
}
}