Cisco Cisco Evolved Programmable Network Manager 2.0 Developer's Guide
Appendix II – Example Java Client to Retrieve Inventory
Cisco EPN Manager 2.0.2 MTOSI API Guide for OSS Integration
133
8 Appendix II – Example Java Client to Retrieve Inventory
This section provides a Java code snippet that can be used by Java-based OSS clients to invoke an MTOSI web
service for retrieving the managed element’s inventory.
package com.cisco.nms.nbi.mtosi.client.example;
import java.net.URL;
import javax.xml.ws.Holder;
import org.tmforum.mtop.fmw.xsd.hdr.v1.Header;
import org.tmforum.mtop.mri.wsdl.mer.v1_0.ManagedElementRetrievalHttp;
import org.tmforum.mtop.mri.wsdl.mer.v1_0.ManagedElementRetrievalRPC;
import org.tmforum.mtop.mri.xsd.mer.v1.GetAllManagedElementsRequest;
import org.tmforum.mtop.mri.xssd.mer.v1.MultipleMeObjectsResponseType;
import org.tmforum.mtop.nrf.xsd.me.v1.ManagedElementType;
/**
* This example illustrates how to use java api to access mtosi web service
methods. This example
* creates Managed Element Retrieval service client, invokes the
getAllManagedElement operation to
* get list of managed elements and print the me names from the response.
*/
public class MtosiClientExample {
public static void main(String[] args) {
try {
// Replace localhost with host name or ip address if the target
host is remote host
String targetHost = "localhost";
// 1. Create WSDL url - endpoint url with "wsdl" query parameter
to provide the wsdl
// defintion
URL wsdlUrl = new URL("http://" + targetHost
+ "/mtosi/nbi/v1/mri/managedElementRetrievalRPC?wsdl");
// 2. Create Web Service Client
ManagedElementRetrievalHttp merClient = new
ManagedElementRetrievalHttp(wsdlUrl);
// 3. Get Service Interface (PortType)
ManagedElementRetrievalRPC merService =
merClient.getManagedElementRetrievalSoapHttp();
// 4. Create Request
Holder<Header> reqHeader = new Holder<Header>(new Header());
GetAllManagedElementsRequest reqBody = new
GetAllManagedElementsRequest();
// 5. Invoke Operation
MultipleMeObjectsResponseType respType =
merService.getAllManagedElements(reqHeader,
reqBody);
// 6. Process Response
for (ManagedElementType me : respType.getMeList().getMe()) {
System.out.printf("ME Discovered Name = %s",
me.getDiscoveredName());
}
} catch (Exception ex) {
ex.printStackTrace();
}
import java.net.URL;
import javax.xml.ws.Holder;
import org.tmforum.mtop.fmw.xsd.hdr.v1.Header;
import org.tmforum.mtop.mri.wsdl.mer.v1_0.ManagedElementRetrievalHttp;
import org.tmforum.mtop.mri.wsdl.mer.v1_0.ManagedElementRetrievalRPC;
import org.tmforum.mtop.mri.xsd.mer.v1.GetAllManagedElementsRequest;
import org.tmforum.mtop.mri.xssd.mer.v1.MultipleMeObjectsResponseType;
import org.tmforum.mtop.nrf.xsd.me.v1.ManagedElementType;
/**
* This example illustrates how to use java api to access mtosi web service
methods. This example
* creates Managed Element Retrieval service client, invokes the
getAllManagedElement operation to
* get list of managed elements and print the me names from the response.
*/
public class MtosiClientExample {
public static void main(String[] args) {
try {
// Replace localhost with host name or ip address if the target
host is remote host
String targetHost = "localhost";
// 1. Create WSDL url - endpoint url with "wsdl" query parameter
to provide the wsdl
// defintion
URL wsdlUrl = new URL("http://" + targetHost
+ "/mtosi/nbi/v1/mri/managedElementRetrievalRPC?wsdl");
// 2. Create Web Service Client
ManagedElementRetrievalHttp merClient = new
ManagedElementRetrievalHttp(wsdlUrl);
// 3. Get Service Interface (PortType)
ManagedElementRetrievalRPC merService =
merClient.getManagedElementRetrievalSoapHttp();
// 4. Create Request
Holder<Header> reqHeader = new Holder<Header>(new Header());
GetAllManagedElementsRequest reqBody = new
GetAllManagedElementsRequest();
// 5. Invoke Operation
MultipleMeObjectsResponseType respType =
merService.getAllManagedElements(reqHeader,
reqBody);
// 6. Process Response
for (ManagedElementType me : respType.getMeList().getMe()) {
System.out.printf("ME Discovered Name = %s",
me.getDiscoveredName());
}
} catch (Exception ex) {
ex.printStackTrace();
}