📄 corbaconnection.java
字号:
/*------------------------------------------------------------------------------Name: CorbaConnection.javaProject: xmlBlaster.orgCopyright: xmlBlaster.org, see xmlBlaster-LICENSE fileComment: Helper to connect to xmlBlaster using IIOPAuthor: xmlBlaster@marcelruff.info------------------------------------------------------------------------------*/package org.xmlBlaster.client.protocol.corba;import org.xmlBlaster.client.protocol.I_XmlBlasterConnection;import java.util.logging.Logger;import java.util.logging.Level;import org.xmlBlaster.util.FileLocator;import org.xmlBlaster.util.Global;import org.xmlBlaster.client.qos.ConnectReturnQos;import org.xmlBlaster.util.XmlBlasterException;import org.xmlBlaster.util.def.ErrorCode;import org.xmlBlaster.util.qos.address.Address;import org.xmlBlaster.util.xbformat.I_ProgressListener;import org.xmlBlaster.util.plugin.I_Plugin;import org.xmlBlaster.util.plugin.PluginInfo;import org.xmlBlaster.util.protocol.corba.OrbInstanceFactory;import org.xmlBlaster.util.def.Constants;import org.xmlBlaster.util.MsgUnitRaw;import org.xmlBlaster.protocol.corba.serverIdl.Server;import org.xmlBlaster.protocol.corba.serverIdl.ServerHelper;import org.xmlBlaster.protocol.corba.authenticateIdl.AuthServer;import org.xmlBlaster.protocol.corba.authenticateIdl.AuthServerHelper;import org.omg.CosNaming.NamingContext;import org.omg.CosNaming.NamingContextExt;import org.omg.CosNaming.NameComponent;import org.omg.CosNaming.BindingHolder;import org.omg.CosNaming.BindingListHolder;import org.omg.CosNaming.BindingIteratorHolder;import java.applet.Applet;/** * This is a helper class, helping a Java client to connect to xmlBlaster * using IIOP (CORBA). * <p> * Please note that you don't need to use this wrapper, you can use the raw CORBA * interface as well. You can also hack your own little wrapper, which does exactly * what you want. * <p> * This class converts the Corba based exception<br /> * org.xmlBlaster.protocol.corba.serverIdl.XmlBlasterException<br /> * to<br /> * org.xmlBlaster.util.XmlBlasterException * <p> * There is a constructor for applets, and standalone Java clients. * <p /> * If you need a failsafe client, you can invoke the xmlBlaster CORBA methods * through this class as well (for example use corbaConnection.publish() instead of the direct * CORBA server.publish()). * <p /> * You should set jacorb.retries=0 in $HOME/.jacorb_properties if you use the failsafe mode * <p /> * If you want to connect from a servlet, please use the framework in xmlBlaster/src/java/org/xmlBlaster/protocol/http * <p /> * NOTE: JacORB 1.1 does not release the listener thread and the poa threads of the callback server * on orb.shutdown().<br /> * Therefor we recycle the ORB and POA instance to avoid a thread leak. * The drawback is that a client for the bug being can't change the orb behavior after the * first time the ORB is created.<br /> * This will be fixed as soon as possible. * * @see <a href="http://www.xmlBlaster.org/xmlBlaster/src/java/org/xmlBlaster/protocol/corba/xmlBlaster.idl" target="others">CORBA xmlBlaster.idl</a> * @author <a href="mailto:xmlBlaster@marcelruff.info">Marcel Ruff</a>. */public final class CorbaConnection implements I_XmlBlasterConnection, I_Plugin{ private String ME = "CorbaConnection"; private Global glob; private static Logger log = Logger.getLogger(CorbaConnection.class.getName()); private org.omg.CORBA.ORB orb; private NamingContextExt nameService; private AuthServer authServer; private Server xmlBlaster; private Address clientAddress; private String sessionId; private boolean verbose = true; private PluginInfo pluginInfo; /** * Called by plugin loader which calls init(Global, PluginInfo) thereafter. */ public CorbaConnection() { } /** * CORBA client access to xmlBlaster for <strong>applets</strong>. * <p /> * Use these environment settings for JacORB if you don't use this constructor! * <br /> * Example: * <pre> * <APPLET * CODEBASE = "http://localhost" * CODE = "DemoApplet.class" * NAME = "xmlBlaster demo" * WIDTH = 200 * HEIGHT = 200 * HSPACE = 0 * VSPACE = 0 * ALIGN = middle * > * <PARAM name=org.omg.CORBA.ORBClass value=org.jacorb.orb.ORB> * <PARAM name=org.omg.CORBA.ORBSingletonClass value=org.jacorb.orb.ORBSingleton> * <PARAM name=SVCnameroot value=xmlBlaster-Authenticate> * </APPLET> * </pre> * @param ap Applet handle */ public CorbaConnection(Global glob, Applet ap) { // try to force to use JacORB instead of builtin CORBA: String orbClassName = "org.jacorb.orb.ORB"; String orbSingleton = "org.jacorb.orb.ORBSingleton"; java.util.Properties props = new java.util.Properties(); props.put("org.omg.CORBA.ORBClass", orbClassName); props.put("org.omg.CORBA.ORBSingletonClass", orbSingleton); orb = org.omg.CORBA.ORB.init(ap, props); // for applets only init(glob, null); log.info("Using ORB=" + orbClassName + " and ORBSingleton=" + orbSingleton); } /** * Enforced by I_Plugin * @return "IOR" */ public String getType() { return getProtocol(); } /** Enforced by I_Plugin */ public String getVersion() { return "1.0"; } /** * This method is called by the PluginManager (enforced by I_Plugin). * @see org.xmlBlaster.util.plugin.I_Plugin#init(org.xmlBlaster.util.Global,org.xmlBlaster.util.plugin.PluginInfo) */ public void init(org.xmlBlaster.util.Global glob, PluginInfo pluginInfo) { this.glob = (glob == null) ? Global.instance() : glob; this.pluginInfo = pluginInfo; resetConnection(); log.info("Created '" + getProtocol() + "' protocol plugin to connect to xmlBlaster server"); } /** * Reset */ public void resetConnection() { if (log.isLoggable(Level.FINE)) log.fine("resetConnection():"); this.authServer = null; this.xmlBlaster = null; } /** * @return The connection protocol name "IOR" */ public final String getProtocol() { return "IOR"; } /** * Accessing the orb handle. * @return org.omg.CORBA.ORB */ public org.omg.CORBA.ORB getOrb() { return this.orb; } /** * Accessing the xmlBlaster handle. * For internal use, throws a COMMUNICATION XmlBlasterException if xmlBlaster==null * We use this for similar handling as org.omg exceptions. * @return Server */ private Server getXmlBlaster() throws XmlBlasterException { if (this.xmlBlaster == null) { if (log.isLoggable(Level.FINE)) log.fine("No CORBA connection available."); throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME, "The CORBA xmlBlaster handle is null, no connection available"); } return this.xmlBlaster; } /** * Locate the CORBA Name Service. * <p /> * The found name service is cached, for better performance in subsequent calls * @return NamingContextExt, reference on name service * @exception XmlBlasterException id="NoNameService" * CORBA error handling if no naming service is found */ NamingContextExt getNamingService() throws XmlBlasterException { if (log.isLoggable(Level.FINER)) log.finer("getNamingService() ..."); if (nameService != null) return nameService; if (orb == null) { log.severe("orb==null, internal problem"); Thread.dumpStack(); throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME, "orb==null, internal problem"); } // Get a reference to the Name Service, CORBA compliant: org.omg.CORBA.Object nameServiceObj = null; try { nameServiceObj = orb.resolve_initial_references("NameService"); } catch (Throwable e) { String text = "Can't access naming service, is there any running?\n" + " - try to specify '-dispatch/connection/plugin/ior/iorFile <fileName>' if server is running on same host (not using any naming service)\n" + " - try to specify '-bootstrapHostname <hostName> -bootstrapPort " + Constants.XMLBLASTER_PORT + "' to locate xmlBlaster (not using any naming service)\n" + " - or contact the server administrator to start a naming service"; if (this.verbose) log.warning(text); throw new XmlBlasterException(glob, ErrorCode.RESOURCE_UNAVAILABLE, "NoNameService", text); } if (nameServiceObj == null) { throw new XmlBlasterException(glob, ErrorCode.RESOURCE_UNAVAILABLE, "NoNameService", "Can't access naming service (null), is there any running?"); } // if (log.isLoggable(Level.FINE)) log.trace(ME, "Successfully accessed initial orb references for naming service (IOR)"); try { nameService = org.omg.CosNaming.NamingContextExtHelper.narrow(nameServiceObj); if (nameService == null) { log.severe("Can't access naming service (narrow problem)"); throw new XmlBlasterException(glob, ErrorCode.RESOURCE_UNAVAILABLE, "NoNameService", "Can't access naming service (narrow problem)"); } if (log.isLoggable(Level.FINE)) log.fine("Successfully narrowed handle for naming service"); return nameService; // Note: the naming service IOR is successfully evaluated (from a IOR), // but it is not sure that the naming service is really running } catch (Throwable e) { if (this.verbose) log.warning("Can't access naming service"); throw new XmlBlasterException(glob, ErrorCode.RESOURCE_UNAVAILABLE, "NoNameService", e.toString()); } } /** * Access the authentication service. * <p /> * There are several ways to bootstrap the authentication service: * <br /> * <ul> * <li>Give the authentication service string-IOR at command line, e.g.<br /> * <code> -dispatch/callback/plugin/ior/iorString "IOR:0000..."</code><br /> * or giving a file name<br /> * <code> -dispatch/connection/plugin/ior/iorFile yourIorFile</code></li> * <li>Give the xmlBlaster host and bootstrap port where xmlBlaster-Authenticate serves the IOR via http, give at command line e.g. * <code> -bootstrapHostname server.xmlBlaster.org -bootstrapPort 3412</code></li> * <li>Try to find a naming service which knows about 'xmlBlaster-Authenticate'</li>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -