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

📄 requestdumpervalve.java

📁 valvae的方法实现类,有效处理较严
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 1999-2001,2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.catalina.valves;import java.io.IOException;import java.util.Enumeration;import javax.servlet.ServletException;import javax.servlet.http.Cookie;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.catalina.HttpRequest;import org.apache.catalina.HttpResponse;import org.apache.catalina.Logger;import org.apache.catalina.Request;import org.apache.catalina.Response;import org.apache.catalina.ValveContext;import org.apache.catalina.util.StringManager;import javax.xml.parsers.*;import java.io.File;import org.w3c.dom.Document;import org.w3c.dom.Node;import java.util.Map;import org.w3c.dom.NodeList;import java.util.HashMap;import com.alphatele.xms.common.ecas2ecs.pertain.SourceMessageProcessor;import javax.naming.*;import java.util.*;import java.lang.reflect.Method;import javax.ejb.EJBHome;import java.io.BufferedReader;import java.io.ByteArrayOutputStream;import com.alphatele.xms.common.ecas2ecs.SourceMessage;import com.alphatele.xms.common.util.TimeZoneUtil;/** * <p>Implementation of a Valve that logs interesting contents from the * specified Request (before processing) and the corresponding Response * (after processing).  It is especially useful in debugging problems * related to headers and cookies.</p> * * <p>This Valve may be attached to any Container, depending on the granularity * of the logging you wish to perform.</p> * * @author Craig R. McClanahan * @version $Revision: 1.1 $ $Date: 2006/10/20 06:29:36 $ */public class RequestDumperValve    extends ValveBase {private static Map configMap=new HashMap();private final static String ECS_HOME="ecs.home";private final static String CONFIG_FILE="ecs-config.xml";private void readXML(){    if(configMap.size()>0){        return;    }    String ecs_home=System.getProperty(ECS_HOME);    System.out.println("ecs_home:"+ecs_home);       if(ecs_home==null){           ecs_home="";       }       else{           ecs_home=ecs_home+File.separator;       }    String confFileName=ecs_home+"conf"+File.separator+CONFIG_FILE;    File ecs_config=new File(confFileName);    if(!ecs_config.exists()){        return;    }    DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();    try{        DocumentBuilder db = dbf.newDocumentBuilder();        Document document=db.parse(ecs_config);        NodeList nodeList=document.getElementsByTagName("ecs-config");        Node node=nodeList.item(0);        NodeList ecs_configList=node.getChildNodes();        for(int i=0;i<ecs_configList.getLength();i++){            Node _node=ecs_configList.item(i);            if("ecas-server".equals(_node.getNodeName())){                NodeList _nodeList=_node.getChildNodes();                for(int j=0;j<_nodeList.getLength();j++){                    Node targetNode=_nodeList.item(j);                    if("jndi_name".equals(targetNode.getNodeName())){                        Node jndi_nameText=targetNode.getFirstChild();                        if("ECSFacade".equals(jndi_nameText.getNodeValue())){                            for(int core=0;core<_nodeList.getLength();core++){                                Node coreProcessNode=_nodeList.item(core);                                if("jndi_name".equals(coreProcessNode.getNodeName())){                                     Node coreTextNode=coreProcessNode.getFirstChild();                                     configMap.put("jndi_name",coreTextNode.getNodeValue());                                }                                if("provider_url".equals(coreProcessNode.getNodeName())){                                     Node coreTextNode=coreProcessNode.getFirstChild();                                     configMap.put("provider_url",coreTextNode.getNodeValue());                                }                                if("context_factory".equals(coreProcessNode.getNodeName())){                                     Node coreTextNode=coreProcessNode.getFirstChild();                                     configMap.put("context_factory",coreTextNode.getNodeValue());                                }                                if("is_remote".equals(coreProcessNode.getNodeName())){                                     Node coreTextNode=coreProcessNode.getFirstChild();                                     configMap.put("is_remote",coreTextNode.getNodeValue());                                }                            }                        }                    }                }            }            else if("system".equals(_node.getNodeName())){                NodeList _nodeList=_node.getChildNodes();                for(int sys=0;sys<_nodeList.getLength();sys++){                    Node targetNode=_nodeList.item(sys);                    if("source-message-used".equals(targetNode.getNodeName())){                        Node smuNode=targetNode.getFirstChild();                        configMap.put("smu_enable",smuNode.getNodeValue());                    }                }            }        }        System.out.println("configMap:"+configMap);    }    catch(Exception pcEx){        pcEx.printStackTrace();        //("XMS_ECS excpetion when parse the xml, the message :"+pcEx);    }}private Object getEJBObject() throws Exception   {       InitialContext ctx;           Properties prop = new Properties();           prop.put(InitialContext.PROVIDER_URL, (String)configMap.get("provider_url"));           prop.put(InitialContext.INITIAL_CONTEXT_FACTORY, (String)configMap.get("context_factory"));           ctx = new InitialContext(prop);       Object ref = ctx.lookup((String)configMap.get("jndi_name"));       ref = javax.rmi.PortableRemoteObject.narrow(ref, EJBHome.class);       Method method = ref.getClass().getDeclaredMethod("create",null);       return method.invoke(ref,null);    }private SourceMessageProcessor getSourceMessageProcessor()throws Exception{    return (SourceMessageProcessor)getEJBObject();}private boolean isSourceMessageRecord(){    readXML();    return "true".equals(configMap.get("smu_enable"));}    // ----------------------------------------------------- Instance Variables    /**     * The descriptive information related to this implementation.     */    private static final String info =        "org.apache.catalina.valves.RequestDumperValve/1.0";    /**     * The StringManager for this package.     */    protected static StringManager sm =        StringManager.getManager(Constants.Package);    // ------------------------------------------------------------- Properties    /**     * Return descriptive information about this Valve implementation.     */    public String getInfo() {        return (info);    }    // --------------------------------------------------------- Public Methods    private void invokeECS(Request request, Response response,                       ValveContext context)        throws IOException, ServletException{                readXML();       HttpRequest hrequest = (HttpRequest) request;       HttpResponse hresponse = (HttpResponse) response;       HttpServletRequest hreq =           (HttpServletRequest) hrequest.getRequest();       HttpServletResponse hres =           (HttpServletResponse) hresponse.getResponse();      BufferedReader bReader=null;      SourceMessageProcessor smp=null;      Map requestMap=null;      SourceMessage requestSM=new SourceMessage();      try{

⌨️ 快捷键说明

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