From: Dave B. <bla...@us...> - 2012-02-06 22:07:58
|
Update of /cvsroot/sblim/jsr48-client/src/org/sblim/cimclient In directory vz-cvs-3.sog:/tmp/cvs-serv5163/src/org/sblim/cimclient Modified Files: Tag: Experimental WBEMListenerSBLIM.java Added Files: Tag: Experimental IndicationListenerSBLIM.java Log Message: 3477087 - Need Access to an Indication Sender's IP Address Index: WBEMListenerSBLIM.java =================================================================== RCS file: /cvsroot/sblim/jsr48-client/src/org/sblim/cimclient/WBEMListenerSBLIM.java,v retrieving revision 1.5.2.9 retrieving revision 1.5.2.10 diff -u -d -r1.5.2.9 -r1.5.2.10 --- WBEMListenerSBLIM.java 3 Jan 2012 16:33:56 -0000 1.5.2.9 +++ WBEMListenerSBLIM.java 6 Feb 2012 22:07:56 -0000 1.5.2.10 @@ -22,12 +22,14 @@ * 3023348 2010-07-02 blaschke-oss Listener uses # constructor instead of valueOf * 3400209 2011-08-31 blaschke-oss Highlighted Static Analysis (PMD) issues * 3469018 2012-01-03 blaschke-oss Properties not passed to CIMIndicationHandler + * 3477087 2012-01-23 blaschke-oss Need Access to an Indication Sender's IP Address */ package org.sblim.cimclient; import java.io.IOException; import java.net.BindException; +import java.util.EventListener; import java.util.HashMap; import java.util.Map; import java.util.Properties; @@ -56,7 +58,7 @@ */ public static class WBEMListenerImpl { - private IndicationListener iIndicationListener; + private EventListener iIndicationListener; private HttpServerConnection iConnection; @@ -66,24 +68,27 @@ * @param pLocalAddress * The local address to bind the port to. If null the port is * bound to all local addresses. For use on multi-homed - * systems - * + * systems. * @param pPort * The port to listen on. If zero any free port will be * chosen. * @param pSSL - * SSL secured connection ? + * SSL secured connection? * @param pIndicationListener * The indication listener to forward the incoming - * indications to + * indications to (an instance of IndicationListener or + * IndicationListenerSBLIM). * @param pProperties - * The configuration + * The configuration. * @throws IOException */ public WBEMListenerImpl(String pLocalAddress, int pPort, boolean pSSL, - IndicationListener pIndicationListener, Properties pProperties) throws IOException { + EventListener pIndicationListener, Properties pProperties) throws IOException { WBEMConfiguration config = (pProperties != null ? new WBEMConfiguration(pProperties) : WBEMConfiguration.getGlobalConfiguration()); + if (!(pIndicationListener instanceof IndicationListener) + && !(pIndicationListener instanceof IndicationListenerSBLIM)) throw new IllegalArgumentException( + "Listener must be instance of IndicationListener or IndicationListenerSBLIM"); this.iIndicationListener = pIndicationListener; CIMEventDispatcher eventDispatcher = new CIMEventDispatcher(this.iIndicationListener); CIMIndicationHandler indicationHandler = new CIMIndicationHandler(eventDispatcher, @@ -100,32 +105,43 @@ } /** - * start + * Starts the HTTP server connection receiving the indications. */ public void start() { this.iConnection.start(); } /** - * stop + * Stops the HTTP server connection receiving the indications. */ public void stop() { this.iConnection.close(); } /** - * Returns the listener we forward the indications to + * Returns the listener we forward the indications to. * - * @return The listener + * @return The listener. */ public IndicationListener getIndicationListener() { - return this.iIndicationListener; + return (this.iIndicationListener instanceof IndicationListener) ? (IndicationListener) this.iIndicationListener + : null; } /** - * Returns the listener port + * Returns the listener we forward the indications to. * - * @return The listener port + * @return The listener. + */ + public IndicationListenerSBLIM getIndicationListenerSBLIM() { + return (this.iIndicationListener instanceof IndicationListenerSBLIM) ? (IndicationListenerSBLIM) this.iIndicationListener + : null; + } + + /** + * Returns the listener port. + * + * @return The listener port. */ public int getListenerPort() { return this.iConnection.getPort(); @@ -161,7 +177,7 @@ */ public int addListener(IndicationListener pListener, int pPort, String pTransport) throws IOException { - return addListener(pListener, pPort, pTransport, null, null); + return addListener((EventListener) pListener, pPort, pTransport, null, null); } /* @@ -172,30 +188,130 @@ */ public int addListener(IndicationListener pListener, int pPort, String pTransport, String pLocalAddr) throws IOException { - return addListener(pListener, pPort, pTransport, pLocalAddr, null); + return addListener((EventListener) pListener, pPort, pTransport, pLocalAddr, null); } /** * Add a new listener using the specified port. * * @param pListener - * - The Indication Listener that will be called when an + * The Indication Listener that will be called when an indication + * is received. + * @param pPort + * The port to listen on. Use 0 to specify any available port. + * @param pTransport + * The transport to use (e.g. HTTP or HTTPS). + * @param pLocalAddr + * The local IP address to bind to. This is only needed in + * multi-homed systems. A value of <code>null</code> will bind to + * all IP addresses. + * @param pConfigurationProperties + * The individual configuration properties for this listener. + * @return The port that was used. + * @throws IOException + * This exception is thrown when binding to pPort fails. + */ + public int addListener(IndicationListener pListener, int pPort, String pTransport, + String pLocalAddr, Properties pConfigurationProperties) throws IOException { + + return addListener((EventListener) pListener, pPort, pTransport, pLocalAddr, + pConfigurationProperties); + } + + /** + * Add a new listener using the specified port. + * + * @param pListener + * The SBLIM Indication Listener that will be called when an * indication is received. * @param pPort - * - The port to listen on. Use 0 to specify any available port. + * The port to listen on. Use 0 to specify any available port. * @param pTransport - * - The transport to use (e.g. HTTP or HTTPS). + * The transport to use (e.g. HTTP or HTTPS). + * @return The port that was used. + * @throws IOException + * This exception is thrown when binding to pPort fails. + */ + public int addListener(IndicationListenerSBLIM pListener, int pPort, String pTransport) + throws IOException { + return addListener((EventListener) pListener, pPort, pTransport, null, null); + } + + /** + * Add a new listener using the specified port and local address. + * + * @param pListener + * The SBLIM Indication Listener that will be called when an + * indication is received. + * @param pPort + * The port to listen on. Use 0 to specify any available port. + * @param pTransport + * The transport to use (e.g. HTTP or HTTPS). * @param pLocalAddr - * - The local IP address to bind to. This is only needed in + * The local IP address to bind to. This is only needed in + * multi-homed systems. A value of <code>null</code> will bind to + * all IP addresses. + * @return The port that was used. + * @throws IOException + * This exception is thrown when binding to pPort fails. + */ + public int addListener(IndicationListenerSBLIM pListener, int pPort, String pTransport, + String pLocalAddr) throws IOException { + return addListener((EventListener) pListener, pPort, pTransport, pLocalAddr, null); + } + + /** + * Add a new listener using the specified port, local address and + * properties. + * + * @param pListener + * The SBLIM Indication Listener that will be called when an + * indication is received. + * @param pPort + * The port to listen on. Use 0 to specify any available port. + * @param pTransport + * The transport to use (e.g. HTTP or HTTPS). + * @param pLocalAddr + * The local IP address to bind to. This is only needed in * multi-homed systems. A value of <code>null</code> will bind to * all IP addresses. * @param pConfigurationProperties - * - The individual configuration properties for this listener + * The individual configuration properties for this listener. * @return The port that was used. * @throws IOException - * - This exception is thrown when binding to pPort fails. + * This exception is thrown when binding to pPort fails. */ - public synchronized int addListener(IndicationListener pListener, int pPort, String pTransport, + public int addListener(IndicationListenerSBLIM pListener, int pPort, String pTransport, + String pLocalAddr, Properties pConfigurationProperties) throws IOException { + + return addListener((EventListener) pListener, pPort, pTransport, pLocalAddr, + pConfigurationProperties); + } + + /** + * Add a new listener using the specified port, local address and + * properties. This is the worker routine for all public addListener + * methods. + * + * @param pListener + * The indication listener (<code>IndicationListener</code> or + * <code>IndicationListenerSBLIM</code>) that will be called when + * an indication is received. + * @param pPort + * The port to listen on. Use 0 to specify any available port. + * @param pTransport + * The transport to use (e.g. HTTP or HTTPS). + * @param pLocalAddr + * The local IP address to bind to. This is only needed in + * multi-homed systems. A value of <code>null</code> will bind to + * all IP addresses. + * @param pConfigurationProperties + * The individual configuration properties for this listener. + * @return The port that was used. + * @throws IOException + * This exception is thrown when binding to pPort fails. + */ + private synchronized int addListener(EventListener pListener, int pPort, String pTransport, String pLocalAddr, Properties pConfigurationProperties) throws IOException { if (pPort > 0 && this.iPortMap.containsKey(Integer.valueOf(pPort))) { throw new BindException( --- NEW FILE: IndicationListenerSBLIM.java --- /** * (C) Copyright IBM Corp. 2012 * * THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. * * You can obtain a current copy of the Eclipse Public License from * http://www.opensource.org/licenses/eclipse-1.0.php * * @author : Alexander Wolf-Reber, IBM, a.w...@de... * @author : Dave Blaschke, IBM, bla...@us... * * Change History * Flag Date Prog Description *------------------------------------------------------------------------------- * 3477087 2012-01-23 blaschke-oss Need Access to an Indication Sender's IP Address */ package org.sblim.cimclient; import java.net.InetAddress; import java.util.EventListener; import javax.cim.CIMInstance; /** * This interface is implemented by the code that wants to create a listener for * indications. See the <code>WBEMListenerFactory</code> class for an example. * * The difference between this interface and <code>IndicationListener</code> is * that the JSR48 standard (<code>javax.wbem.listener.IndicationListener</code>) * does not allow for the listener to receive the IP of the indication sender * whereas this internal interface ( * <code>org.sblim.cimclinet.IndicationListenerSBLIM</code>) does. */ public interface IndicationListenerSBLIM extends EventListener { /** * Called when an indication has been received by the listener * * @param pIndicationURL * The URL to which the indication was posted. For example if the * indication was delivered over the https protocol to the * destination listener https://hostname:6111/, pIndicationURL * would be set to https://hostname:6111/. * @param pIndication * The indication received. * @param pSenderIP * The internet address of the indication sender. */ public void indicationOccured(String pIndicationURL, CIMInstance pIndication, InetAddress pSenderIP); } |