How to use GetLineReq in AXL Java Client using JAX-WS - java

What I'm trying to do is to obtain a Directory Number from CUCM, using the AXL API from Cisco. Here's the relevant Code:
private void getNumber(){
AXLAPIService axlService = new AXLAPIService();
AXLPort axlPort = axlService.getAXLPort();
String validatorUrl = "https://mycucm: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);
GetLineReq axlParams = new GetLineReq();
axlParams.setPattern("7491817");
axlParams.setUuid("{48a6ff28-cea7-fc3e-3d82-8cc245ed4ea3}");
GetLineRes getLineResponse = axlPort.getLine(axlParams);
Demo.informUser("Line Information: \n"
+ "Alerting Name: " + getLineResponse.getReturn().getLine().getAlertingName() + "\n"
+ "Dial Number: " + getLineResponse.getReturn().getLine().getPattern() + "\n"
+ "Description: " + getLineResponse.getReturn().getLine().getDescription() + "\n"
+ " " + getLineResponse.getReturn().getLine().getShareLineAppearanceCssName());
}
As you can tell from this diagram it is only necessary to specify either the uuid or the pattern of the number:
But the code only works, if I specify the uuid, which is not, what I'm trying to achieve. The only thing i have given, is the pattern, which I want to use, to get all the other information. I Already examined this site from Cisco: How to ... Create an AXL Java Client using JAX-WS
When I leave out the uuid I get this Error:
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Item not valid: The specified Line was not found
I also checked, how the Directory Number is stored inside the CUCM Database using the AXLSqlToolkit:
<?xml version="1.0" encoding="UTF-8" standalone="no"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Header/><SOAP-ENV:Body><axl:executeSQLQueryResponse xmlns:axl="http://www.cisco.com/AXL/API/7.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" sequence="1405672933992"><return><row><dnorpattern>7491817</dnorpattern><pkid>48a6ff28-cea7-fc3e-3d82-8cc245ed4ea3</pkid></row></return></axl:executeSQLQueryResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
Does anyone know, how I can obtain the Directory Number, only by using the pattern-value?

I figured it out myself. The routePartitionName is also a mandatory parameter, which had to be specified. Here's the working code of my method:
private void getNumber(){
AXLAPIService axlService = new AXLAPIService();
AXLPort axlPort = axlService.getAXLPort();
String validatorUrl = "https://mycucm: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);
GetLineReq axlParams = new GetLineReq();
ObjectFactory objectFactory = new ObjectFactory(); //This is new
XFkType routePartition = new XFkType();
routePartition.setValue("PHONES"); // This is where you specify your route partition name
axlParams.setPattern("7491817");
axlParams.setRoutePartitionName(objectFactory.createGetLineReqRoutePartitionName(routePartition));
GetLineRes getLineResponse = axlPort.getLine(axlParams);
Demo.informUser("Line Information: \n"
+ "Alerting Name: " + getLineResponse.getReturn().getLine().getAlertingName() + "\n"
+ "Dial Number: " + getLineResponse.getReturn().getLine().getPattern() + "\n"
+ "Description: " + getLineResponse.getReturn().getLine().getDescription() + "\n"
+ " " + getLineResponse.getReturn().getLine().getShareLineAppearanceCssName());
}

Related

Randomly changing the JSON Values for every "Post" Request Body using Java

This could be a duplicate question, but I couldn't find my solution anywhere. Hence, posting it.
I am trying to simply POST a request for a Student account Creation Scenario. I do have a JSON file which comprises all the "Keys:Values", required for Student account creation.
This is how the file student_Profile.json looks like:
{
"FirstName":"APi1-Stud-FN",
"MiddleInitial":"Q",
"LastName":"APi1-Stud-LN",
"UserAlternateEmail":"",
"SecretQuestionId":12,
"SecretQuestionAnswer":"Scot",
"UserName":"APi1-stud#xyz.com",
"VerifyUserName":"APi1-stud#xyz.com",
"Password":"A123456",
"VerifyPassword":"A123456",
"YKey":"123xyz",
"YId":6,
"Status":false,
"KeyCode":"",
"SsoUserName":"APi1-stud#xyz.com",
"SsoPassword":"",
"BirthYear":2001
}
So everything on Posting the request from "Rest Assured" point of view looks fine, it's just that I want to update a few values from the above JSON body using JAVA so that I can create a new Student profile every time I run my function and don't have to manually change the Body.
For Every POST Student Account Creation scenario, I need to update the value for
the following keys so that a new test student user account can be created:
First Name
Last Name and
Username // "VerifyUserName" and "SSO UserName" will remain same as user name
I modified the answer to get random values and pass them to json body. random value generation was taken from the accepted answer of this question.
public void testMethod() {
List<String> randomValueList = new ArrayList<>();
for (int i = 0; i < 3; i++) {
String SALTCHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
StringBuilder salt = new StringBuilder();
Random rnd = new Random();
while (salt.length() < 18) { // length of the random string.
int index = (int) (rnd.nextFloat() * SALTCHARS.length());
salt.append(SALTCHARS.charAt(index));
}
randomValueList.add(salt.toString());
}
String jsonBody = "{\n" +
" \"FirstName\":\"" + randomValueList.remove(0) + "\",\n" +
" \"MiddleInitial\":\"Q\",\n" +
" \"LastName\":\"" + randomValueList.remove(0) + "\",\n" +
" \"UserAlternateEmail\":\"\",\n" +
" \"SecretQuestionId\":12,\n" +
" \"SecretQuestionAnswer\":\"Scot\",\n" +
" \"UserName\":\"" + randomValueList.remove(0) + " \",\n" +
" \"VerifyUserName\":\"APi1-stud#xyz.com\",\n" +
" \"Password\":\"A123456\",\n" +
" \"VerifyPassword\":\"A123456\",\n" +
" \"YKey\":\"123xyz\",\n" +
" \"YId\":6,\n" +
" \"Status\":false,\n" +
" \"KeyCode\":\"\",\n" +
" \"SsoUserName\":\"APi1-stud#xyz.com\",\n" +
" \"SsoPassword\":\"\",\n" +
" \"BirthYear\":2001\n" +
"}";
Response response = RestAssured
.given()
.body(jsonBody)
.when()
.post("api_url")
.then()
.extract()
.response();
// Do what you need to do with the response body
}
We can used pojo based approach to do certain things very easily . No matter how complex is the payload , serialization and dieselization is the best answer . I have created a framework template for api automation that can we used by putting required POJO's in path :
https://github.com/tanuj-vishnoi/pojo_api_automation
To create pojo, I also have ready to eat food for you :
https://github.com/tanuj-vishnoi/pojo_generator_using_jsonschema2pojo
for the above problem you can refer to the JsonPath lib https://github.com/json-path/JsonPath and use this code:
String mypayload = "{\n" +
" \"FirstName\":\"APi1-Stud-FN\",\n" +
" \"MiddleInitial\":\"Q\",\n" +
" \"LastName\":\"APi1-Stud-LN\"}";
Map map = JsonPath.parse(mypayload).read("$",Map.class);
System.out.println(list);
once the payload converted into map you can change only required values as per the requirement
To generate random strings you can refer to lib org.apache.commons.lang3.RandomStringUtils;
public static String generateUniqueString(int lenghtOfString){
return
RandomStringUtils.randomAlphabetic(lenghtOfString).toLowerCase();
}
I recommend to store payload in a separate file and load it at runtime.

Get only BTC pairs Binance Java API

I'll like to get only the BTC pairs of Binance. I use this code to get all currencies current prices
List<TickerPrice> allPrices = client.getAllPrices();
System.out.println(allPrices);
How do I turn only BTC pairs? Thank, experts in the house.
try and catch BinanceAPIException around .. example of grabbing a pair
BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance();
BinanceApiRestClient client = factory.newRestClient();
// BinanceApiAsyncRestClient client = factory.newAsyncRestClient();
// Test connectivity
client.ping();
long serverTime = client.getServerTime();
out.println("<p> Time of ticker from Binance - its Servertime : " + serverTime + "</p>");
TickerStatistics tickerStatistics = client.get24HrPriceStatistics("NEOETH");
out.println("<p> NEO ETH : " + tickerStatistics.getLastPrice() + "</p>");
String price = tickerStatistics.getLastPrice().toString();
out.println("<p> as string .. " + price + "</p>");
TickerStatistics tickerStatistics2 = client.get24HrPriceStatistics("HBARUSDT");
out.println("<p> HBAR USDT : " + tickerStatistics2.getLastPrice() + "</p>");

Read and write to different Mongo collections using Spark with Java

I am a relative newbie to Spark. I need to read from a Mongo collection in Java using Spark, change some field values, let's say I am appending "123" to one field value and write into another collection. Accordingly I had 2 separate Mongo URIs as the input and output URIs configured in Spark. I am then proceeding to read from the input collection. However, what I am not understanding is how would I make the same RDD of documents as output to another collection. This is the input code:
String inputUri = "mongodb://" + kp.getProperty("source.mongo.userid") + ":"
+ Encryptor.decrypt(kp.getProperty("source.mongo.cache")) + "#"
+ kp.getProperty("source.mongo.bootstrap-servers") + "/" + kp.getProperty("source.mongo.database")
+ "." + kp.getProperty("source.mongo.inputCollection") + "?ssl=true&connectTimeoutMS="
+ kp.getProperty("source.mongo.connectTimeoutMS") + "&socketTimeoutMS="
+ kp.getProperty("source.mongo.socketTimeoutMS") + "&maxIdleTimeMS="
+ kp.getProperty("source.mongo.maxIdleTimeMS");
String outputUri = "mongodb://" + kp.getProperty("source.mongo.userid") + ":"
+ Encryptor.decrypt(kp.getProperty("source.mongo.cache")) + "#"
+ kp.getProperty("source.mongo.bootstrap-servers") + "/" + kp.getProperty("source.mongo.database")
+ "." + kp.getProperty("source.mongo.outputCollection") + "?ssl=true&connectTimeoutMS="
+ kp.getProperty("source.mongo.connectTimeoutMS") + "&socketTimeoutMS="
+ kp.getProperty("source.mongo.socketTimeoutMS") + "&maxIdleTimeMS="
+ kp.getProperty("source.mongo.maxIdleTimeMS");
SparkSession spark = SparkSession.builder().master("local[3]").appName(kp.getProperty("spark.app.name"))
.config("spark.mongodb.input.uri", inputUri)
.config("spark.mongodb.output.uri", outputUri)
...;
JavaSparkContext sc = new JavaSparkContext(spark.sparkContext());
JavaMongoRDD<Document> rdd = MongoSpark.load(sc);
System.out.println("Count: " + rdd.count());
System.out.println(rdd.first().toJson());
Please help me in this regard.
I have got the answer myself. I went the Dataset route instead of RDDs which made the modification simpler. So, to load the Mongo colection, I use
Dataset<Row> df = MongoSpark.load(sc).toDF();
Then I create a temporary view upon it in orcder to be able to use Spark SQL:
df.createOrReplaceTempView("Customer");
I register an UDF for operating upon each column value:
spark.udf().register("Test", new TestUDF(), DataTypes.StringType);
the UDF definition is as follows:
public class TestUDF implements UDF1<String, String> {
#Override
public String call(String customer) throws Exception {
return customer + "123";
}
}
Then I call the UDF using the same column name as the original so that the values in the original dataset are replaced:
df = df.withColumn("CustomerName", functions.callUDF("Test", functions.col("CustomerName")));
Then I write it back to Mongo in a separate collection:
MongoSpark.write(df).option("collection", "myCollection").save();

Convert Loadrunner File Parameter to Java string for payload

I have a java virtual user script that is sending a payload request. I am trying to use values from a file to send via a loadrunner file parameter.
here is the payload:
private static final String PAYLOAD =
"<ips_cad_mdt>\n" +
" <SignOnRequest>\n" +
" <DestApplication>hhhh</DestApplication>\n" +
" <OrigApplication>hhh</OrigApplication>\n" +
" <SessionRef>3</SessionRef>\n" +
" <Aliasing>1234</Aliasing>\n" +
" </SignOnRequest>\n" +
"</ips_cad_mdt>";
I would like to use something like the following:
private static final String PAYLOAD =
"<ips_cad_mdt>\n" +
" <SignOnRequest>\n" +
" <DestApplication>hhh</DestApplication>\n" +
" <OrigApplication>hhh</OrigApplication>\n" +
" <SessionRef>3</SessionRef>\n" +
" <Aliasing>”+lr.eval_string(“{AliasId}”)+”</Aliasing>\n" +
" </SignOnRequest>\n" +
"</ips_cad_mdt>";
for some reason i cant see any output for this value. do i need to declare a variable: e.g. lr.save_string("AliasId", "{AliasId}");
an example of this would help loads. Many Thanks
There seems to be an error in the code completion in VuGen. The parameters should be reversed and without the {} in save_string.
lr.save_string("1234","myId");
lr.message(lr.eval_string("{myId}"));
In the documentation it is correct - https://admhelp.microfocus.com/lr/en/12.55/help/function_reference/FuncRef.htm#FuncRef/c_vuser/lrFr_lr_save_string.htm?Highlight=lr_save_string
I asked the responsible team to fix the code completion in VuGen so you will be able to see this change in one of the future releases.

SOAP client SAAJ

I am relatively new to SOAP and wanted to write a SOAP client in JAVA. I figured out that the WSDL has a lot of other crap and as I use just one service out of it, hence SAAJ would be the shortest way. The first WSDL I got was RPC encoded and did not support SSL connections (http link). The call I made was this:
String request = "<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:AxessInterface\">"
+ " <soapenv:Header/>"
+ " <soapenv:Body>"
+ " <urn:getModemFromACS soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
+ "<ModemIDMACAddressChoice xsi:type=\"urn:ModemIDMACAddressChoiceStruct\">"
+ " <ModemID xsi:type=\"xsd:string\">"
+ modemId
+ "</ModemID>"
+ " </ModemIDMACAddressChoice>"
+ " </urn:getModemFromACS>"
+ " </soapenv:Body>"
+ "</soapenv:Envelope>";
The new WSDL that I have is I guess NOT RPC encoded (it does not have that "style=rpc" tag anywhere) and the link is SSL enabled (https with one way authentication). The style is "document" in this WSDL.
I have a couple of issues:
My soap call doesnt work. I modified it to be:
String request = "http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:AxessInterface\">"
+ " "
+ " "
+ " "
+ " "
+ " "
+ modemId
+ ""
+ " "
+ " "
+ " "
+ "";
I am not sure why the code cannot be displayed, i removed the line "soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" . With this i get a SOAPFault with message: "list index out of range"
Can someone tell me how to add that truststore to my SOAP client? (I use System.setProperty but I am not sure if this is the best way to go).

Categories