3-64

User Guide for Resource Manager Essentials 4.1
OL-11714-01
Chapter 3 Adding and Troubleshooting Devices Using Device Management
Device List Manipulation Service
public class UseDevListSvc extends HttpServlet {
public synchronized void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/plain");
PrintWriter pw = res.getWriter();
int port = req.getServerPort();
String host = req.getServerName();;
// Make sure you put show.xml in the right directory. the default
// is CSCOpx/example .
String filename = "/opt/CSCOpx/example/show.xml";
String paramList = fileToString(filename, pw);
String URL = "/rme/com.cisco.nm.rmeng.inventory.servlet.DeviceListService";
try {
DataInputStream ds = execPOST(host, port, URL, paramList, pw);
if (ds == null) {
throw new Exception("Could not contact URL " + URL+ " with "+paramList); }
BufferedReader br = new BufferedReader(new InputStreamReader(ds));
String line = null;
while ((line = br.readLine()) != null ){
if (line.indexOf("-1:") > 0 ) { //this indicates an error.
throw new Exception("Received result " + line );
}
pw.println(line);
}
} catch (Exception e) {
pw.println("Error in doGet: "+ e.getMessage());
}
pw.flush();
pw.close();
}
public static DataInputStream execPOST(String Host,int Port, String URI, String data,
PrintWriter pw) {
URL url = null;
URLConnection urlConn;
DataOutputStream printout;
try {
if (Port == -1) {