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

📄 mx4jadaptor.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*------------------------------------------------------------------------------Name:      MX4JAdaptor.javaProject:   xmlBlaster.orgCopyright: xmlBlaster.org, see xmlBlaster-LICENSE file------------------------------------------------------------------------------*/package org.xmlBlaster.contrib.jmx;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.net.URL;import java.net.URLClassLoader;import java.util.Enumeration;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.Map;import java.util.Set;import java.util.StringTokenizer;import java.util.logging.Logger;import javax.management.MBeanServer;import javax.management.ObjectName;import mx4j.tools.adaptor.http.HttpAdaptor;import mx4j.tools.adaptor.http.HttpInputStream;import mx4j.tools.adaptor.http.HttpOutputStream;import mx4j.tools.adaptor.http.XSLTProcessor;import mx4j.util.Base64Codec;import org.w3c.dom.Attr;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.xmlBlaster.contrib.GlobalInfo;import org.xmlBlaster.contrib.InfoHelper;import org.xmlBlaster.util.Global;import org.xmlBlaster.util.XmlBlasterException;import org.xmlBlaster.util.admin.extern.JmxWrapper;import org.xmlBlaster.util.context.ContextNode;import org.xmlBlaster.util.def.ErrorCode;import org.xmlBlaster.util.plugin.PluginInfo;/** * MX4JAdaptor * @author <a href="mailto:michele@laghi.eu">Michele Laghi</a> */public class MX4JAdaptor extends GlobalInfo {   public class XblHttpAdaptor extends HttpAdaptor {      public XblHttpAdaptor() {         super();      }   }      private static Logger log = Logger.getLogger(MX4JAdaptor.class.getName());   private final static String USER_ROLE = "user";   private final static String ADMIN_ROLE = "admin";   private final static String INITIATOR_ROLE = "initiator";   private ObjectName name;   private Map roles;   private String authMethod;   private HttpAdaptor adaptor;      public class ContribXsltProcessor extends XSLTProcessor {            private String prefix;      private Set warnings;      private String authMethod;       private Map roles;            public ContribXsltProcessor(Map roles, String authMethod) {         super();         this.warnings = new HashSet();         this.roles = roles;         this.authMethod = authMethod;      }            public void setFile(String prefix) {         this.prefix = prefix;      }            public String getFile(){         return this.prefix;      }            private boolean isPathAbsolute(String path) {         if (path == null)            return false;         File test = new File(path.trim());         return test.isAbsolute();      }            /**       *       * Note on the classpath: to find a resource it has to be according to java nomenclature,       * it will not find a document specified with '\'.       * @param path       * @param cl       * @param fixFileSeparator       * @return       */      private InputStream getInputStream(String path, ClassLoader cl, boolean fixFileSeparator) {         log.fine("using classloader '" + cl.getClass().getName() + "'");         if (path == null)            log.severe("ContribXsltProcessor.getInputStream: no filename specified");         // path = this.prefix + File.separatorChar + path;         log.fine("Requesting path '" + path + "'");         if (!path.startsWith(File.separator) && !path.startsWith("/"))         // if (!isPathAbsolute(path))             // path = File.separator + path;            path = "/" + path;                        path = this.prefix + path;         if (fixFileSeparator)            path = path.replace('/', File.separatorChar);         log.fine("Requesting path (after cleaning) '" + path + "'");                  InputStream ret = null;         try {            Enumeration enm = cl.getResources(path);            if(enm.hasMoreElements()) {               URL url = (URL)enm.nextElement();               String urlTxt = "loading file '" + url.getFile() + "'";               log.fine(urlTxt);               try {                  ret = url.openStream();               }               catch(IOException ex) {                  log.warning("init: could not read properties from '" + url.getFile() + "' : " + ex.getMessage());               }               while(enm.hasMoreElements() && !this.warnings.contains(path)) {                  this.warnings.add(path);                  url = (URL)enm.nextElement();                  log.warning(urlTxt + ". An additional matching file has been found in the classpath at '"                     + url.getFile() + "' please check that the correct one has been loaded (see info above)."                  );               }            }            else {               StringBuffer buf = new StringBuffer();               if (cl instanceof URLClassLoader) {                  URL[] urls = ((URLClassLoader)cl).getURLs();                  for (int i=0; i < urls.length; i++)                      buf.append(urls[i].toString()).append("\n");               }               else {                  buf.append(" not an URLClassLoader (can not get list of files found) ");               }               log.warning("no file found with the name '" + path + "'" /*+ "' : " + (buf.length() > 0 ? " classpath: " + buf.toString() : ""*/);               log.fine("no file found with the name '" + path + "'" + " classpath: '" + buf.toString() + "'");            }         }         catch(IOException e) {            log.severe("an IOException occured when trying to load property file '" + name + "'" + e.getMessage());         }         return ret;      }      protected InputStream getInputStream(String path) {         boolean fixFileSeparator = false;         InputStream ret = null;         if (ret == null)            ret = getInputStream(path, this.getClass().getClassLoader(), fixFileSeparator);         /*         if (ret == null)            ret = getInputStream(path, ClassLoader.getSystemClassLoader(), fixFileSeparator);         fixFileSeparator = true;         */         /*         if (ret == null)            ret = getInputStream(path, this.getClass().getClassLoader(), fixFileSeparator);         if (ret == null)            ret = getInputStream(path, ClassLoader.getSystemClassLoader(), fixFileSeparator);         return ret;         */         return ret;      }      private String debug(HttpInputStream is) throws IOException {         Map headers = is.getHeaders();         Iterator iter = headers.entrySet().iterator();         StringBuffer buf = new StringBuffer(1024);         buf.append("headers: \n");         while (iter.hasNext()) {            Map.Entry entry = (Map.Entry)iter.next();            String key = (String)entry.getKey();            String val = (String)entry.getValue();            buf.append("   ").append(key).append("\t: ").append(val).append("\n");         }         buf.append("\n");         buf.append("method\t: ").append(is.getMethod()).append("\n");         buf.append("path  \t: ").append(is.getPath()).append("\n");         buf.append("query\t: ").append(is.getQueryString()).append("\n");         buf.append("query\t: ").append(is.getQueryString()).append("\n");         buf.append("query\t: ").append(is.getQueryString()).append("\n");         Map variables  = is.getHeaders();         iter = variables.entrySet().iterator();         buf.append("variables: \n");         while (iter.hasNext()) {            Map.Entry entry = (Map.Entry)iter.next();            String key = (String)entry.getKey();            String val = (String)entry.getValue();            buf.append("   ").append(key).append("\t: ").append(val).append("\n");         }         buf.append("\n");

⌨️ 快捷键说明

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