📄 corbaconnection.java
字号:
* </ul> * <p /> * @return a handle on the AuthServer IDL interface * @exception XmlBlasterException id="NoAuthService" * */ public AuthServer getAuthenticationService(Address address) throws XmlBlasterException { if (log.isLoggable(Level.FINER)) log.finer("getAuthenticationService() ..."); if (this.authServer != null) { return this.authServer; } address = (address == null) ? new Address(glob) : address; if (this.pluginInfo != null) address.setPluginInfoParameters(this.pluginInfo.getParameters()); try { // 0) Check if programmer has given the IOR hardcoded if (address.getRawAddress() != null && address.getRawAddress().length() > 2) { String authServerIOR = address.getRawAddress(); this.authServer = AuthServerHelper.narrow(orb.string_to_object(authServerIOR)); if (this.verbose) log.info("Accessing xmlBlaster using your given IOR string in Address.getRawAddress()"); return this.authServer; } // 1) check if argument -IOR at program startup is given "-dispatch/connection/plugin/ior/iorString" String authServerIOR = address.getEnv("iorString", (String)null).getValue(); if (authServerIOR != null) { this.authServer = AuthServerHelper.narrow(orb.string_to_object(authServerIOR)); if (this.verbose) log.info("Accessing xmlBlaster using your given IOR string"); return this.authServer; } if (log.isLoggable(Level.FINE)) log.fine("No -dispatch/connection/plugin/ior/iorString ..."); String authServerIORFile = glob.getProperty().get("dispatch/connection/plugin/ior/iorFile", (String)null); // -dispatch/connection/plugin/ior/iorFile IOR string is given through a file if (authServerIORFile != null) { try { authServerIOR = FileLocator.readAsciiFile(authServerIORFile); } catch (XmlBlasterException e) { log.warning("Accessing xmlBlaster given IOR file '" + authServerIORFile + "' failed, please check 'dispatch/connection/plugin/ior/iorFile'"); } this.authServer = AuthServerHelper.narrow(orb.string_to_object(authServerIOR)); log.info("Accessing xmlBlaster using your given IOR file " + authServerIORFile); return this.authServer; } if (log.isLoggable(Level.FINE)) log.fine("No -dispatch/connection/plugin/ior/iorFile ..."); // 2) check if argument -bootstrapHostname <hostName or IP> -bootstrapPort <number> at program startup is given // To avoid the name service, one can access the AuthServer IOR directly // using a http connection. try { authServerIOR = glob.accessFromInternalHttpServer(address, "AuthenticationService.ior", this.verbose); if (System.getProperty("java.version").startsWith("1") && !authServerIOR.startsWith("IOR:")) { authServerIOR = "IOR:000" + authServerIOR; // hack for JDK 1.1.x, where the IOR: is cut away from ByteReader ??? !!! log.warning("Manipulated IOR because of missing 'IOR:'"); } this.authServer = AuthServerHelper.narrow(orb.string_to_object(authServerIOR)); log.info("Accessing xmlBlaster AuthServer IOR using builtin http connection to " + address.getBootstrapUrl()); return this.authServer; } catch(XmlBlasterException e) { ; } catch(Throwable e) { if (this.verbose) { log.severe("XmlBlaster not found with internal HTTP download"); e.printStackTrace(); } } if (log.isLoggable(Level.FINE)) log.fine("No -bootstrapHostname / -bootstrapPort for " + address.getBootstrapUrl() + " ..."); String contextId = glob.getProperty().get("NameService.context.id", "xmlBlaster"); if (contextId == null) contextId = ""; String contextKind = glob.getProperty().get("NameService.context.kind", "MOM"); if (contextKind == null) contextKind = ""; String clusterId = glob.getProperty().get("NameService.node.id", glob.getStrippedId()); if (clusterId == null) clusterId = ""; String clusterKind = glob.getProperty().get("NameService.node.kind", "MOM"); if (clusterKind == null) clusterKind = ""; String text = "Can't access xmlBlaster Authentication Service, is the server running and ready?\n" + " - try to specify '-dispatch/connection/plugin/ior/iorFile <fileName>' if server is running on same host\n" + " - try to specify '-bootstrapHostname <hostName> -bootstrapPort " + Constants.XMLBLASTER_PORT + "' to locate xmlBlaster\n" + " - or start a naming service '" + contextId + "." + contextKind + "/" + clusterId + "." + clusterKind + "'"; // 3) asking Name Service CORBA compliant boolean useNameService = address.getEnv("useNameService", true).getValue(); // -plugin/ior/ns default is to ask the naming service if (useNameService) { if (this.verbose) log.info("Trying to find a CORBA naming service ..."); try { // NameService entry is e.g. "xmlBlaster.MOM/heron.MOM" // where "xmlBlaster.MOM" is a context node and // "heron.MOM" is a subnode for each running server (containing the AuthServer POA reference) NamingContextExt namingContextExt = getNamingService(); NameComponent [] nameXmlBlaster = new NameComponent[] { new NameComponent(contextId, contextKind) }; if (log.isLoggable(Level.FINE)) log.fine("Query NameServer -ORBInitRef NameService=" + glob.getProperty().get("ORBInitRef","") + ((System.getProperty("ORBInitRef.NameService") != null) ? System.getProperty("ORBInitRef.NameService") : "") + " to find the xmlBlaster root context " + OrbInstanceFactory.getString(nameXmlBlaster)); org.omg.CORBA.Object obj = namingContextExt.resolve(nameXmlBlaster); NamingContext relativeContext = org.omg.CosNaming.NamingContextExtHelper.narrow(obj); if (relativeContext == null) { throw new Exception("Can't resolve CORBA NameService"); } NameComponent [] nameNode = new NameComponent[] { new NameComponent(clusterId, clusterKind) }; AuthServer authServerFirst = null; String tmpId = ""; // for logging only String tmpServerName = ""; // for logging only String firstServerName = ""; // for logging only int countServerFound = 0; // for logging only String serverNameList = ""; // for logging only try { this.authServer = AuthServerHelper.narrow(relativeContext.resolve(nameNode)); } catch (Exception ex) { if (log.isLoggable(Level.FINE)) log.fine("Query NameServer to find a suitable xmlBlaster server for " + OrbInstanceFactory.getString(nameXmlBlaster) + "/" + OrbInstanceFactory.getString(nameNode)); BindingListHolder bl = new BindingListHolder(); BindingIteratorHolder bi = new BindingIteratorHolder(); relativeContext.list(0, bl, bi); //for (int i=0; i<bl.value.length; i++) { // bl.value.length should be 0 // String id = bl.value[i].binding_name[0].id; // String kind = bl.value[i].binding_name[0].kind; // process the remaining bindings if an iterator exists: if (this.authServer == null && bi.value != null) { BindingHolder bh = new BindingHolder(); int i = 0; while ( bi.value.next_one(bh) ) { String id = bh.value.binding_name[0].id; String kind = bh.value.binding_name[0].kind; NameComponent [] nameNodeTmp = new NameComponent[] { new NameComponent(id, kind) }; tmpId = id; countServerFound++; tmpServerName = OrbInstanceFactory.getString(nameXmlBlaster)+"/"+OrbInstanceFactory.getString(nameNodeTmp); if (i>0) serverNameList += ", "; i++; serverNameList += tmpServerName; if (clusterId.equals(id) && clusterKind.equals(kind)) { try { if (log.isLoggable(Level.FINE)) log.fine("Trying to resolve NameService entry '"+OrbInstanceFactory.getString(nameNodeTmp)+"'"); this.authServer = AuthServerHelper.narrow(relativeContext.resolve(nameNodeTmp)); break; // found a matching server } catch (Exception exc) { log.warning("Connecting to NameService entry '"+tmpServerName+"' failed: " + exc.toString()); } } if (authServerFirst == null) { if (log.isLoggable(Level.FINE)) log.fine("Remember the first server"); try { firstServerName = tmpServerName; if (log.isLoggable(Level.FINE)) log.fine("Remember the first reachable xmlBlaster server from NameService entry '"+firstServerName+"'"); authServerFirst = AuthServerHelper.narrow(relativeContext.resolve(nameNodeTmp)); } catch (Exception exc) { log.warning("Connecting to NameService entry '"+tmpServerName+"' failed: " + exc.toString()); } } } } } if (this.authServer == null) { if (authServerFirst != null) { if (countServerFound > 1) { String str = "Can't choose one of " + countServerFound + " avalailable server in CORBA NameService: " + serverNameList + ". Please choose one with e.g. -NameService.node.id " + tmpId; log.severe(str); throw new Exception(str); } log.info("Choosing only available server '" + firstServerName + "' in CORBA NameService -ORBInitRef NameService=" + System.getProperty("ORBInitRef")); this.authServer = authServerFirst; return authServerFirst; } else { throw new Exception("No xmlBlaster server found in NameService"); } } log.info("Accessing xmlBlaster using a naming service '" + nameXmlBlaster[0].id + "." + nameXmlBlaster[0].kind + "/" + nameNode[0].id + "." + nameNode[0].kind + "' on " + System.getProperty("ORBInitRef")); return this.authServer; } catch(Throwable e) { throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME, text, e); } } if (log.isLoggable(Level.FINE)) log.fine("No -plugin/ior/useNameService ..."); throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME, text); } finally { this.verbose = false; } } /** * Login to the server. * <p /> * @param connectQos The encrypted connect QoS * @exception XmlBlasterException if login fails */ public String connect(String connectQos) throws XmlBlasterException { if (connectQos == null) throw new XmlBlasterException(glob, ErrorCode.INTERNAL_ILLEGALARGUMENT, ME, "Please pass a valid QoS for connect()"); this.ME = "CorbaConnection"; if (log.isLoggable(Level.FINER)) log.finer("connect(xmlBlaster="+this.xmlBlaster+") ..."); try { AuthServer remoteAuthServer = getAuthenticationService(this.clientAddress); if (log.isLoggable(Level.FINE)) log.fine("Got authServer handle, trying connect ..."); return remoteAuthServer.connect(connectQos); } catch(XmlBlasterException e) { throw e; } catch(org.xmlBlaster.protocol.corba.serverIdl.XmlBlasterException e) { XmlBlasterException xmlBlasterException = OrbInstanceFactory.convert(glob, e); //xmlBlasterException.changeErrorCode(ErrorCode.COMMUNICATION_NOCONNECTION); throw xmlBlasterException; // Wrong credentials } catch(Throwable e) { XmlBlasterException xmlBlasterException = XmlBlasterException.convert(glob, ME, "Login failed", e); xmlBlasterException.changeErrorCode(ErrorCode.COMMUNICATION_NOCONNECTION); throw xmlBlasterException; } } /** * @see I_XmlBlasterConnection#connectLowlevel(Address) */ public void connectLowlevel(Address address) throws XmlBlasterException { if (log.isLoggable(Level.FINER)) log.finer("connectLowlevel() ..."); this.clientAddress = address; if (this.orb == null) { this.orb = OrbInstanceFactory.createOrbInstance(this.glob,(String[])null, glob.getProperty().getProperties(), this.clientAddress); } getAuthenticationService(this.clientAddress); if (log.isLoggable(Level.FINE)) log.fine("Success, connectLowlevel()"); } /** * @see I_XmlBlasterConnection#setConnectReturnQos(ConnectReturnQos) */ public void setConnectReturnQos(ConnectReturnQos connectReturnQos) throws XmlBlasterException { try { this.sessionId = connectReturnQos.getSecretSessionId(); String xmlBlasterIOR = connectReturnQos.getServerRef().getAddress(); this.xmlBlaster = ServerHelper.narrow(orb.string_to_object(xmlBlasterIOR)); this.ME = "CorbaConnection-"+connectReturnQos.getSessionName().toString(); if (log.isLoggable(Level.FINE)) log.fine("setConnectReturnQos(): xmlBlaster=" + this.xmlBlaster); } catch(Throwable e) { this.xmlBlaster = null; XmlBlasterException xmlBlasterException = XmlBlasterException.convert(glob, ME, "Login failed", e); xmlBlasterException.changeErrorCode(ErrorCode.COMMUNICATION_NOCONNECTION); throw xmlBlasterException; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -