From: Dave H. <hel...@us...> - 2014-05-16 22:08:11
|
Update of /cvsroot/sblim/jsr48-client/smpl/org/sblim/cimclient/samples In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv3184/smpl/org/sblim/cimclient/samples Modified Files: Tag: Experimental Jsr48IndicationTester.java Log Message: 2734 Support file-based URL in destination handler Index: Jsr48IndicationTester.java =================================================================== RCS file: /cvsroot/sblim/jsr48-client/smpl/org/sblim/cimclient/samples/Jsr48IndicationTester.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -d -r1.1.2.3 -r1.1.2.4 --- Jsr48IndicationTester.java 17 Aug 2012 01:45:15 -0000 1.1.2.3 +++ Jsr48IndicationTester.java 16 May 2014 22:08:08 -0000 1.1.2.4 @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corp. 2012 + * (C) Copyright IBM Corp. 2014 * * THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE @@ -14,6 +14,7 @@ * Flag Date Prog Description * ------------------------------------------------------------------------------- * 3529066 2012-07-06 hellerda Add Jsr48IndicationTester (initial version) + * 2734 2014-05-16 hellerda Support file:// URL in destination handler */ package org.sblim.cimclient.samples; @@ -317,9 +318,10 @@ public static boolean subscribe(WBEMClient pClient, String pInteropNS, String pIndicationNS, String pHost, URL pDestURL, String pQuery) { try { - cDestinationPath = pClient.createInstance(makeListenerDestination(pInteropNS, pDestURL - .getProtocol() - + "://" + pDestURL.getHost() + ":" + pDestURL.getPort() + "/create", pHost)); + cDestinationPath = pClient.createInstance(makeListenerDestination(pInteropNS, + getUrlString(pDestURL) + + (pDestURL.getProtocol().equalsIgnoreCase("file") ? "" : "/create"), + pHost)); cFilterPath = pClient.createInstance(makeFilter(pInteropNS, pIndicationNS, pQuery, pHost)); cSubscriptionPath = pClient.createInstance(makeSubscription(pInteropNS, @@ -398,14 +400,24 @@ } /** + * Workaround to http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6561321 + */ + private static String getUrlString(URL url) { + if (url.getProtocol().equalsIgnoreCase("file")) return url.toString().substring(0, 5) + + "//" + url.toString().substring(5); + return url.toString(); + } + + /** * Print all the elements of a URL */ private static void printURL(URL url) { - System.out.printf("Full URL string : %s\n", url.toString()); + System.out.printf("Full URL string : %s\n", getUrlString(url)); System.out.printf("Protocol (scheme) : %s\n", url.getProtocol()); System.out.printf("Authority : %s\n", url.getAuthority()); System.out.printf("Host : %s\n", url.getHost()); - System.out.printf("Port : %d\n", Integer.valueOf(url.getPort())); + System.out.printf("Port : %d\n", + url.getPort() > 0 ? Integer.valueOf(url.getPort()) : null); System.out.printf("UserInfo : %s\n", url.getUserInfo()); if (url.getUserInfo() != null) { String[] userInfo = url.getUserInfo().split(":"); @@ -443,7 +455,9 @@ */ static void cleanup(WBEMClient client, String namespace, URL destURL) { unsubscribe(client, namespace); - cListener.removeListener(destURL.getPort()); + if (destURL.getProtocol().equalsIgnoreCase("http") + || destURL.getProtocol().equalsIgnoreCase("https")) cListener + .removeListener(destURL.getPort()); client.close(); System.out.println("Cleaned up. Sample completed."); } @@ -571,13 +585,16 @@ // start the listener so that we are "on air" when the indications // come in - if (startListener(destURL, printInd)) { - System.out.println("Listener started."); - } else { - System.err.println("Listener startup failed. Most probably the port " - + destURL.getPort() + " is not available."); - client.close(); - return; + if (destURL.getProtocol().equalsIgnoreCase("http") + || destURL.getProtocol().equalsIgnoreCase("https")) { + if (startListener(destURL, printInd)) { + System.out.println("Listener started."); + } else { + System.err.println("Listener startup failed. Most probably the port " + + destURL.getPort() + " is not available."); + client.close(); + return; + } } try { |