⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mx4jadaptor.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
         return buf.toString();      }          private String getTemplate(HttpInputStream is) {         String query = is.getQueryString();         if (query == null)            return null;         final String template = "template=";         final int length = template.length();         int pos = query.indexOf(template);         if (pos < 0)            return null;         String end = query.substring(pos + length);         pos = end.indexOf('&');         if (pos < 0)            return end;         return end.substring(0, pos);      }            private String extractUserName(HttpInputStream is) throws IOException {         String authentication = is.getHeader("authorization");         if (authentication == null)            return null;                  if (this.authMethod.equals("basic")) {            authentication = authentication.substring(5, authentication.length());            String decodeString = new String(Base64Codec.decodeBase64(authentication.getBytes()));            if (decodeString.indexOf(":") > 0) {               try {                  StringTokenizer tokens = new StringTokenizer(decodeString, ":");                  return tokens.nextToken(); // username               }               catch (Exception ex) {                  ex.printStackTrace();                  return null;               }            }         }         return null;      }            public void writeResponse(HttpOutputStream outputStream, HttpInputStream inputStream, Document doc) throws IOException {         // log.severe(debug(inputStream));         Element el = doc.getDocumentElement();         Attr admin = doc.createAttribute(ADMIN_ROLE);         Attr initiator = doc.createAttribute(INITIATOR_ROLE);         Attr user = doc.createAttribute(USER_ROLE);         if (this.authMethod != null) {            String userName = extractUserName(inputStream);            if (userName == null)               userName = "";            String roles = (String)this.roles.get(userName);            if (roles == null) {               admin.setValue("false");               initiator.setValue("false");               user.setValue("false");            }            else if (roles.indexOf(ADMIN_ROLE) > -1) {               admin.setValue("true");               initiator.setValue("true");               user.setValue("true");            }            else if (roles.indexOf(INITIATOR_ROLE) > -1) {               admin.setValue("false");               initiator.setValue("true");               user.setValue("true");            }            else {               admin.setValue("false");               initiator.setValue("false");               user.setValue("true");            }         }         else {            admin.setValue("true");            initiator.setValue("true");            user.setValue("true");         }         el.setAttributeNode(admin);         el.setAttributeNode(initiator);         el.setAttributeNode(user);         // outputStream.setHeader("Cache-Control", "no-cache");         // outputStream.setHeader("Content-Type", "text/xml");         super.writeResponse(outputStream, inputStream, doc);      }   }      public MX4JAdaptor() {      super((Set)null);      this.roles = new HashMap();   }      private final HttpAdaptor instantiateAdaptor(Global global) throws Exception {            int port = getInt("port", 9999);      String host = get("host", "0.0.0.0");      String adaptorName = get("adaptorName", "HttpAdaptorMX4J");      MBeanServer server = global.getJmxWrapper().getMBeanServer();      HttpAdaptor adapter = new HttpAdaptor();      this.name = new ObjectName("Adaptor:name=" + adaptorName);      server.registerMBean(adapter, name);      adapter.setHost(host);      adapter.setPort(port);      this.authMethod = get("authenticationMethod", null);      log.info("Authentication Method is '" + this.authMethod + "'");      if (this.authMethod != null) {         this.authMethod = this.authMethod.trim();         if ("basic".equals(this.authMethod))            adapter.setAuthenticationMethod(this.authMethod);         else            log.warning("Authentication method '" + authMethod + "' not recognized, will switch to 'basic'");         log.info("Authentication Method is '" + this.authMethod + "'");         Map users = InfoHelper.getPropertiesStartingWith("replication.monitor.user.", this, null);         if (users != null && users.size() > 0) {            Iterator iter = users.entrySet().iterator();            while (iter.hasNext()) {               Map.Entry entry = (Map.Entry)iter.next();               String name = (String)entry.getKey();               String val = (String)entry.getValue();               log.fine("name='" + name + "' value='" + val + "'");               int pos = val.indexOf(':');               String pwd = null;               String roles = USER_ROLE;               if (pos > -1) {                  pwd = val.substring(0, pos);                  roles = val.substring(pos+1);               }               else                  pwd = val;               log.fine("registering monitor user '" + name + "' having roles : " + roles + "'");               adapter.addAuthorization(name, pwd);               this.roles.put(name, roles);            }         }         else            log.info("No Users found for the monitor");      }            String xsltProcessor = get("xsltProcessor", null);      ObjectName processorName = null;      if (xsltProcessor != null) {         ContextNode contextNode = new ContextNode(ContextNode.CONTRIB_MARKER_TAG, "jmx" + ContextNode.SEP + xsltProcessor,               this.global.getContextNode());         processorName = new ObjectName(JmxWrapper.getObjectNameLiteral(this.global, contextNode));                  // XSLTProcessor processor = new XSLTProcessor();         ContribXsltProcessor processor = new ContribXsltProcessor(this.roles, this.authMethod);                  server.registerMBean(processor, processorName);                  // set it to use a dir         String xsltPath = get("xsltPath", null); // can be a directory or a jar file         String xsltPathInJar = null;         if (xsltPath != null) {            processor.setFile(xsltPath);         }         boolean xsltCache = getBoolean("xsltCache", true);         processor.setUseCache(xsltCache);         // set not to use cache         String xsltLocale = get("xsltLocale", null);         if (xsltLocale != null) {         }         // adds a mime type         // server.invoke(processorName, "addMimeType", new Object[] {".pdf", "application/pdf"}, new String[] {"java.lang.String", "java.lang.String"});         log.info("Xslt Processor: " + xsltProcessor + "' on xsltPath='" + xsltPath + "' and xsltPathInJar='" + xsltPathInJar + "' and xsltCache='" + xsltCache + "' and xsltLocale='" + xsltLocale + "'");         adapter.setProcessorName(processorName);      }            adapter.start();      log.info("The adaptor '" + adaptorName + "' is running. You can access it at 'http://" + host + ":" + port + "'");      return adapter;   }   private final void stopAdaptor() throws Exception {      MBeanServer server = this.global.getJmxWrapper().getMBeanServer();      server.unregisterMBean(this.name);      this.adaptor.stop();   }      /**    * @see org.xmlBlaster.contrib.GlobalInfo#doInit(org.xmlBlaster.util.Global, org.xmlBlaster.util.plugin.PluginInfo)    */   protected void doInit(Global global, PluginInfo pluginInfo)         throws XmlBlasterException {      try {         this.adaptor = instantiateAdaptor(this.global);      }      catch (Throwable e) {         e.printStackTrace();         throw new XmlBlasterException(this.global, ErrorCode.RESOURCE_CONFIGURATION, "ReplManagerPlugin", "init failed", e);       }   }   public void shutdown() throws XmlBlasterException {      try {         stopAdaptor();      }      catch (Throwable e) {         throw new XmlBlasterException(this.global, ErrorCode.RESOURCE_CONFIGURATION, "ReplManagerPlugin", "shutdown failed", e);       }      super.shutdown();   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -