Eclipse 新手 - AXL - Java
我正在逐步学习上述内容。
使用 JavaSE 1.8 和 eclipse 4.13.0 与运行 v 10.5 的实验室呼叫管理器进行交互,并通过跟踪和修改演示,我能够成功运行 getphone 以返回有关手机的信息 - 包括 UUID 和描述。
从那里我尝试添加一个“setphone”部分来仅更改电话描述,然后再次显示电话信息。
一切运行良好,没有错误,但描述永远不会改变。
这是我正在使用的代码:
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();
}
}
主要问题是,为什么它不更新描述?我看到以前的帖子表明我需要调用“应用”,但我没有看到相应的方法。当我查看 AXL 日志以进行尝试时,它显示为 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>
显然 xlParams.setDescription(NewDescription); 没有通过参数 - 很明显我对我在做什么还不太了解。
您可以就该问题提供的任何帮助将不胜感激。
此外,当我第一次开始处理“设置”部分时,我认为我不必第二次设置连接,因为它是在“获取”部分中设置的。但是我发现有必要重复一遍。这是因为它在 getphone 部分而不是 main 部分,还是必须每次都设置?
此外,每次我运行它(一次用于获取,一次用于设置,然后再次用于第二次获取),我都会收到此错误:
警告:文件的导入:/C:/Users/ME/eclipse-workspace/axl-demo/schema/current/AXLSoap.xsd 违反了 BP 1.1 R2001。继续警告。R2001 描述只能使用 WSDL“import”语句来导入另一个 WSDL 描述。
我发现的帖子表明这是 Web 服务本身的问题,而不是我的代码:这是正确的吗?有没有办法在这种环境下压制它?
谢谢你的帮助