Newbie to eclipse - AXL - Java
I am inching my way forward to learn the above.
using JavaSE 1.8, and eclipse 4.13.0, to interact with a lab call manager running v 10.5, and by following and modifying a demo, Ive been able to successfully run a getphone to return information about a phone - including UUID and description.
From there Im attempting to add a 'setphone' section to change just the phone description, then display the phone information again.
Everything runs fine, with no errors, but the description never changes.
This is the code I'm using:
package com.cisco.axl.demo;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
/**
* ------------ AXL DEMO 4 ------------
* Intro - THIS VERSION AXLD3 WORKS on Laptop!!!
*/
import javax.xml.ws.BindingProvider;
import com.cisco.axlapiservice.AXLAPIService;
import com.cisco.axlapiservice.AXLError;
import com.cisco.axlapiservice.AXLPort;
import com.cisco.axl.api._10.*;
/**
*
* Performs getPhone operation using AXL API
*
* Note, service consumers were generated by the Java 6 wsimport command:
*
* <code>
* wsimport -keep -b schema/current/AXLSOAP.xsd -Xnocompile -s src -d bin -verbose schema/current/AXLAPI.ws
* </code>
*
* Since AXL uses HTTPS you will have to install the UC application's
* Certificate into your keystore in order to run this sample code
*
* you can run the program by cd'ing to bin folder within this project and running the following command
*
* <code>
* java -cp . com.cisco.axl.demo.Demo
*</code>
*
* it is necessary to install the target systems ssl certificate to all JRE and JDK
* certificate stores - for JREs use:
* "C:\Program Files\Java\jre1.8.0_231\bin\keytool" -import -alias LabCertJre16 -file "C:\Apps\USFEL1-UCL201_corp_pattersoncompanies_com.crt" -keystore "C:\Program Files\Java\jre<VER>\lib\security\jssecacerts"
*
* for JDKs use:
* "C:\Program Files\Java\jre1.8.0_231\bin\keytool" -import -alias LabCertJre16 -file "C:\Apps\USFEL1-UCL201_corp_pattersoncompanies_com.crt" -keystore "C:\Program Files\Java\jdk<VER>\jre\lib\security\cacerts"
*
*/
/*
/*
Things to fix
password is exposed
cert requires fqdn - need to support IP and just server name
warning at beginning
*/
public class Demo {
/**
* UC app host.
*/
protected static String ucHost = null;
/**
* OS admin.
*/
protected static String ucAdmin = null;
/**
* OS admin password.
*/
protected static String ucPswd = null;
/**
* New Description.
*/
protected static String ucDescr = null;
/**
* phoneName used in request.
*/
protected static String phoneName = null;
/**
* phoneName used in request.
*/
protected static String NewDescription = null;
/**
* UUID returned from getphone - used in setphone
*/
protected static String PhoneUUID = null;
/**
* Run the demo
*
* @param args not used
*/
public static void main(String[] args) {
// Verify JVM has a console
if (System.console() == null) {
System.err.println("The Cisco AXL Sample App requires a console.");
System.exit(1);
} else {
Demo.informUser("%nWelcome to the Cisco AXL Sample APP .%n");
}
Demo demo = new Demo();
demo.getPhoneInfo();
}
/**
* get information about phone
*/
public void getPhoneInfo() {
// Ask for the UC application to upgrade
// Demo.informuser("%nWhat UC server would you like to access?%n");
ucHost = promptUser(" Host: ");
ucAdmin = promptUser(" OS Admin Account: ");
ucPswd = promptUser(" OS Admin Password: ");
// Ask for the phone name
Demo.informUser("%nEnter the name of the phone you want to retrieve information about.%n");
phoneName = promptUser(" Phone Name: ");
// Make the getPhoneRequest
getPhone();
SetPhoneDescr();
getPhone();
}
/**
* Makes the getPhone request and displays some of the fields that are returned.
*/
private void getPhone()
{
// Instantiate the wsimport generated AXL API Service client --
// see the wsimport comments in the class javadocs above
AXLAPIService axlService = new AXLAPIService();
AXLPort axlPort = axlService.getAXLPort();
// Set the URL, user, and password on the JAX-WS client
String validatorUrl = "https://"
+ Demo.ucHost
+ ":8443/axl/";
((BindingProvider) axlPort).getRequestContext().put(
BindingProvider.ENDPOINT_ADDRESS_PROPERTY, validatorUrl);
((BindingProvider) axlPort).getRequestContext().put(
BindingProvider.USERNAME_PROPERTY, Demo.ucAdmin);
((BindingProvider) axlPort).getRequestContext().put(
BindingProvider.PASSWORD_PROPERTY, Demo.ucPswd);
// Create a GetPhoneReq object to represent the getPhone request and set the name of the device
//to name entered by user
GetPhoneReq axlParams = new GetPhoneReq();
axlParams.setName(phoneName);
//Make a call to the AXL Service and pass the getPhone request
GetPhoneRes getPhoneResponse = null;
try {
getPhoneResponse = axlPort.getPhone(axlParams);
} catch (AXLError e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//display information returned in the response to the user
// Demo.informUser("Product=" + getPhoneResponse.getReturn().getPhone().getProduct() + "%n"
// + getPhoneResponse.getReturn().getPhone().getLoadInformation().getValue() + "%n");
Demo.informUser("Product=" + getPhoneResponse.getReturn().getPhone().getProduct() + "%n");
Demo.informUser("Load=" + getPhoneResponse.getReturn().getPhone().getLoadInformation().getValue() + "%n");
Demo.informUser("Descr=" + getPhoneResponse.getReturn().getPhone().getDescription() + "%n");
Demo.informUser("Model=" + getPhoneResponse.getReturn().getPhone().getModel() + "%n");
Demo.informUser("Name=" + getPhoneResponse.getReturn().getPhone().getName() + "%n");
PhoneUUID = getPhoneResponse.getReturn().getPhone().getUuid();
Demo.informUser("UUID=" + PhoneUUID + "%n");
System.out.println(" ");
System.out.println(" ");
}
public void SetPhoneDescr() {
// Ask for the new description to apply to the phone
ucDescr = promptUser(" NewDescription: ");
// Instantiate the wsimport generated AXL API Service client --
// see the wsimport comments in the class javadocs above
AXLAPIService axlService = new AXLAPIService();
AXLPort axlPort = axlService.getAXLPort();
// Set the URL, user, and password on the JAX-WS client
String validatorUrl = "https://"
+ Demo.ucHost
+ ":8443/axl/";
((BindingProvider) axlPort).getRequestContext().put(
BindingProvider.ENDPOINT_ADDRESS_PROPERTY, validatorUrl);
((BindingProvider) axlPort).getRequestContext().put(
BindingProvider.USERNAME_PROPERTY, Demo.ucAdmin);
((BindingProvider) axlPort).getRequestContext().put(
BindingProvider.PASSWORD_PROPERTY, Demo.ucPswd);
// Create a GetPhoneReq object to represent the getPhone request and set the name of the device
//to name entered by user
UpdatePhoneReq axlParams = new UpdatePhoneReq();
axlParams.setNewName(phoneName);
axlParams.setDescription(NewDescription);
axlParams.setName(phoneName);
axlParams.setUuid(PhoneUUID);
/**
/**
* some test code from devnet Support on JAXBElement
// String username = null;
String device_uuid = null;
axlParams.setUuid(device_uuid); //.setUuid(device_uuid);
XFkType user = new XFkType();
user.setUuid(PhoneUUID); //returns UserUUID
JAXBElement<XFkType> user2 = new JAXBElement(new QName(XFkType.class.getSimpleName()), XFkType.class, user);
* end of sample code from devnet
*/
//Make a call to the AXL Service and pass the getPhone request
StandardResponse UpdatePhoneRes = null;
try {
UpdatePhoneRes = axlPort.updatePhone(axlParams);
} catch (AXLError e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// -------------------- Some I/O Helper Methods ------------------------
/**
* Provide the user some instructions.
*/
protected static void informUser(String info) {
System.console().format(info);
}
/**
* Ask the user a question
* @return A non-null, non-empty answer to the question
*/
protected static String promptUser(String question){
String answer = null;
while (answer == null || answer.isEmpty()) {
answer = System.console().readLine(question);
}
return answer.trim();
}
}
The main question is, why isnt it updating the description? I saw a previous post that indicated I needed to call an 'apply' but I didnt see a method for that. When I looked at the AXL log for the attempt it showed this as the XML:
<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:updatePhone xmlns:ns2="http://www.cisco.com/AXL/API/10.5"><name>SEP00AF1F9C5D7A</name><newName>SEP00AF1F9C5D7A</newName></ns2:updatePhone></S:Body></S:Envelope>
clearly the xlParams.setDescription(NewDescription); is not passing the param - just as clearly I dont know too much about what Im doing yet.
Any help you can give on that question would be much appreciated.
Also, when I first started working on the 'set' part of this, I thought I wouldnt have to set up the connection a second time, since it was set up in the 'get' part. However I found it necessary to repeat it. Is this because it was in the getphone section instead of the main, or must it be set up everytime?
Also, everytime I run it (once for the get, once for the set, then again for the second get), I get this error:
WARNING: Import of file:/C:/Users/ME/eclipse-workspace/axl-demo/schema/current/AXLSoap.xsd is violation of BP 1.1 R2001. Proceeding with a warning. R2001 A DESCRIPTION must only use the WSDL "import" statement to import another WSDL description.
Posts Ive found suggest this is a problem in the web service itself rather than my code: is this correct? Is there a way to suppress it in this enviroment?
Thanks for your help
I found the issue. It turned out to be a simple programming error rather than an AXL problem, etc. I populated one variable when prompting the user: ucDescr = promptUser(" NewDescription: ")
but updated the phone build with the original description variable - so it was probably working the whole time - but setting the description back to its original value.
So for anyone finding this question in the future - nothing fancy or magical - just check the basics