亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? abstractsitesession.java

?? jetspeed源代碼
?? JAVA
字號:
/*
 * Copyright 2000-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.jetspeed.services.webpage;

// java.io
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;

// java.util
import java.util.Iterator;
import java.util.Enumeration;
import java.util.HashMap;

// javax.servlet
import javax.servlet.http.*;

// java.net
import java.net.URL;
import java.net.URLConnection;
import java.net.HttpURLConnection;
import java.net.URLEncoder;

import org.apache.log4j.Logger;

/*
 * Abstract Base class for web page sessions.
 * Implements the primary dispatcher logic for getting and posting resources.
 *
 */

public abstract class AbstractSiteSession implements SiteSession
{    

    // the base url of the host being proxied
    protected String targetBase;

    // the base url the wps
    protected String proxyBase;

    // the cookies collection
    protected HashMap cookies = new HashMap();
        
    // counters
    protected int hitCount = 0;
    protected int cacheCount = 0;

    // the log file singleton instance
    static Logger log = Logger.getLogger(AbstractSiteSession.class);

    /**
     * Create a NetElementSession, which maintains sessions with one network element.
     * 
    * @param targetBase the target host's base URL
    * @param proxyBase the proxy server host URL base address.     
     */    
    public AbstractSiteSession(String targetBase, String proxyBase)
    {
        this.proxyBase  = proxyBase;
        this.targetBase = targetBase;
    }

    /**
     * Given a URL, returns the content from that URL in a string.  
     * All HTTP hyperlinks(HREFs) are rewritten as proxied-referenced hyperlinks.
     * All relative references to web resources (images, stylesheets, ...) are 
     * rewritten as absolute references, but are not proxied.
     * Determines if we are logged on to the target site. If not,
     * calls logon(), which is a implementation specific 'POST' exchange
     *
     * @see logon(String, HttpServletRequest, HttpServletResponse)     
     *
     * @param url the proxied resource address.
     * @param data the rundata
     *
     * @exception IOException a servlet exception.
     */    

    public void dispatch(String url, ProxyRunData data)
                 throws IOException
    {                    
        try 
        {
            Configuration config = Configuration.getInstance();
                
            log.debug("=== Dispatching =" + url);
            
            // open a pooled HTTP connection
            //URL u = new URL(url);
            URL u = new URL(null, url, new sun.net.www.protocol.http.Handler() );
            HttpURLConnection con = (HttpURLConnection)u.openConnection();  
    
            //if (con instanceof HttpURLConnection) 
            con.setDoInput(true);
            con.setDoOutput(true);
            con.setAllowUserInteraction(false);        
            con.setFollowRedirects(false);
    
            if (data.getPosting()) {
                con.setRequestMethod("POST");
            }
        
            // are there any cookies in our current session?
            if (cookies.isEmpty()) 
            {
                // there are no cookies, must be a new session, so lets logon
                    log.debug("... no session id provided. Logging on...");
    
                if (false == logon(data))
                    return;   
    
            }        
    
            // send the cookies (session ids) back to the NE
            Iterator it = cookies.values().iterator();
            Cookie cookie;
            while (it.hasNext()) {
                cookie = (Cookie)it.next();
                String sessionID = WebPageHelper.buildCookieString(cookie);
                con.setRequestProperty("Cookie", sessionID);
                log.debug("... Sending Session ID: " + sessionID );
            }            
    
            // we have to get the post parameters from the servlet container,
            // and then re-encode them. i wish i could find out how to keep
            // the servlet container from reading them, because now i have to
            // parse them out, and then re-encode
            if (data.getPosting()) {
    
                // get the post params 
                StringBuffer postParams = new StringBuffer();
                int count = 0;
                Enumeration e = data.getRequest().getParameterNames();
                while (e.hasMoreElements())
                {
    
                    String name = (String) e.nextElement();
                    if (name.equals(config.getSID()) ||
                        name.equals(config.getURL())) {
                        continue;
                    }                                      
    
                    String values[] = data.getRequest().getParameterValues(name);
                    if (values != null) 
                    {
                        for (int i = 0; i < values.length; i++) {
                            if (count > 0) {
                                postParams.append("&");
                            }
                            postParams.append(name);
                            postParams.append("=");
                            postParams.append(URLEncoder.encode(values[i]));
                            count++;
                        }
                    }
                }
                String  postString = postParams.toString();            
                con.setRequestProperty("Content-length", String.valueOf(postString.length()) );
                // write directly to the output stream            
                DataOutputStream dos = new DataOutputStream(con.getOutputStream());            
    
                log.debug("... POST: " + postString);
                dos.writeBytes(postString);
                dos.close();
            }
           
            int rc = con.getResponseCode();
    
            // Get the Session Information from Headers
            int contentType = WebPageHelper.getContentType(con.getHeaderField("content-type"), u.toString());
            String location = con.getHeaderField("Location");
            
            if ((rc == con.HTTP_MOVED_PERM || rc == con.HTTP_MOVED_TEMP) && null != location) 
            {
                log.debug("+++ REDIRECT = " + location);
                location = WebPageHelper.concatURLs(targetBase, location);
                dispatch(location , data);
                return;
            }
    
            // get cookies set from server
            String cookieString = con.getHeaderField("Set-Cookie");
            if (null != cookieString) 
            {
                log.debug("... new SessionID found: " + cookieString);
                WebPageHelper.parseCookies(cookieString, this);            
            }
    
            if (contentType == WebPageHelper.CT_IMAGE || 
                contentType == WebPageHelper.CT_BINARY ||
                contentType == WebPageHelper.CT_APPLICATION) {
                // wasn't in the cache, get it from host
                getBinaryContent(con, data.getResponse());
                return;
            }
        
            rewriteContent(data, con, contentType, url);
    
        }
        catch (IOException ex)
        {
            log.error("*** PROXY DISPATCH EXCEPTION = " + ex);
                throw ex;
        }

    }

    /**
     * Gets the HTML content from the URL Connection stream and returns it
     * in a string
     *
     * @param con The URLConnection to read from.
     * @param resource The full URL of the resource.
     * @return The HTML Content from the stream.
     *
     * @exception IOException a servlet exception.
     */
    public String getHTMLContent(URLConnection con, 
                                 ProxyRunData data,
                                 String resource) throws IOException 
    {

        int CAPACITY = 4096;

        InputStream is = con.getInputStream();
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        
        Configuration config = Configuration.getInstance();
        FileOutputStream fos = null;
        boolean logging = config.getEnableContentLog();
        if (logging) 
        {
            if (data != null)
            {
                String fileName = data.getServlet().getServletContext().getRealPath(
                                        config.getLogLocation() );
                fos = new FileOutputStream(fileName, true);
                WebPageHelper.writeHeader(fos, resource);
            }
        }
        
        //now process the InputStream...
        
        byte[] bytes = new byte[CAPACITY];

        int readCount = 0;
        int total = 0;

        while( ( readCount = is.read( bytes )) > 0 ) 
        {                                        
            buffer.write( bytes, 0, readCount);
            if (logging)
            {
                fos.write( bytes, 0, readCount);
            }
            total += readCount;
        }     
        if (logging) 
        {
            fos.close();
        }
        is.close();

        return buffer.toString();
    }

    /**
     * Gets the HTML content from the URL Connection stream and writes it to respones
     *
     * @param con The URLConnection to read from.
     *
     * @exception IOException a servlet exception.
     */
    public void getBinaryContent(URLConnection con,
                                 HttpServletResponse response) throws IOException 
    {

        int CAPACITY = 4096;


        InputStream is = con.getInputStream();

       // FileOutputStream fos = new FileOutputStream("/test.fw", true);

        //now process the InputStream...
        
        byte[] bytes = new byte[CAPACITY];

        int readCount = 0;
        while( ( readCount = is.read( bytes )) > 0 ) {
                                        
            response.getOutputStream().write(bytes, 0, readCount);
            //fos.write( bytes, 0, readCount);
        }        
        
        //fos.close();
        is.close();

    }

    /**
      * Given a cookie, it first checks to see if that cookie is already
      * managed in this session. If it is, it means that the session has
      * timed out and that the network element has now created a new session.
      * In that case, replace the cookie, and re-establish the session (logon)
      * If its a new cookie, we will still need to logon, and and the cookie to
      * the managed cookies collection for this session.
      *
      * @param cookie new cookie returned from target server.
      * @return true when a new cookie added, false when updated.
      *
      */
    public boolean addCookieToSession(Cookie cookie)
    {
        boolean added = (null == cookies.get(cookie.getName()));
        cookies.put(cookie.getName(), cookie); // adds or updates        
        return added;
    }

    /*
     * Gets the hitcount for this session.
     *
     * @return the hitcount for this session.
     */
    public int getHitCount()
    {
        return hitCount;
    }

    /*
     * Increments the hitcount for this session.
     *
     */
    public void incHitCount()
    {
        hitCount++;
    }

    /*
     * Gets the cache count for this session.
     *
     * @return the cache count for this session.
     */
    public int getCacheCount()
    {
        return cacheCount;
    }

    /*
     * Increments the hitcount for this session.
     *
     */
    public void incCacheCount()
    {
        cacheCount++;
    }


}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品乡下勾搭老头1| 狠狠狠色丁香婷婷综合久久五月| 久久 天天综合| 色乱码一区二区三区88| 久久精品欧美一区二区三区不卡| 亚洲一区二区三区国产| 大尺度一区二区| 日韩欧美三级在线| 午夜久久久久久| 亚洲精品日韩一| 一本一道综合狠狠老| 日韩黄色免费电影| 一本到不卡精品视频在线观看| 久久久综合网站| 日韩影院在线观看| 日本韩国精品在线| 久久先锋影音av鲁色资源| 午夜激情一区二区| 在线观看一区二区精品视频| 亚洲欧洲日韩女同| 成人的网站免费观看| 国产喂奶挤奶一区二区三区| 蓝色福利精品导航| 欧美一区二区高清| 日韩高清不卡在线| 欧美精品自拍偷拍| 亚洲国产日韩一级| 欧美视频日韩视频| 亚洲精品v日韩精品| 91网站最新网址| 国产精品萝li| www.性欧美| 国产精品乱码一区二三区小蝌蚪| 国产黑丝在线一区二区三区| 精品久久久久久久久久久久包黑料 | 经典一区二区三区| 日韩免费看的电影| 美腿丝袜一区二区三区| 日韩欧美中文字幕制服| 奇米影视在线99精品| 日韩写真欧美这视频| 奇米影视在线99精品| 日韩欧美国产高清| 国内精品在线播放| 久久综合成人精品亚洲另类欧美 | 日韩二区三区在线观看| 欧美美女一区二区三区| 亚洲成人777| 在线综合视频播放| 美女视频黄 久久| 日韩精品影音先锋| 国产精品一区二区91| 国产欧美一区二区三区网站 | 午夜精品免费在线| 欧美高清视频www夜色资源网| 天堂精品中文字幕在线| 亚洲动漫第一页| 欧美三日本三级三级在线播放| 亚洲第一福利一区| 欧美一区二区三区免费在线看| 久久国产日韩欧美精品| 久久―日本道色综合久久| 成人av电影在线| 曰韩精品一区二区| 日韩视频免费直播| 国产成人综合亚洲网站| 亚洲人精品一区| 在线91免费看| 国产精品亚洲成人| 亚洲黄色av一区| 日韩欧美国产综合一区| 成人高清在线视频| 亚洲18影院在线观看| 欧美tk—视频vk| 成人a免费在线看| 亚洲va欧美va国产va天堂影院| 精品欧美乱码久久久久久1区2区| 国产91精品欧美| 亚洲成av人片一区二区梦乃| 欧美xxxxx牲另类人与| 99热国产精品| 日韩高清欧美激情| 国产精品国产三级国产三级人妇| 欧美性猛交xxxxxx富婆| 国模大尺度一区二区三区| 最新中文字幕一区二区三区| 欧美男人的天堂一二区| 国产麻豆精品在线| 亚洲一区二区三区在线| 精品国产伦一区二区三区免费 | 久久狠狠亚洲综合| |精品福利一区二区三区| 91精品国产综合久久久久久久| 国产v综合v亚洲欧| 亚洲一区二区三区爽爽爽爽爽 | 精品视频1区2区| 国产精品456露脸| 亚洲午夜免费福利视频| 久久久国产一区二区三区四区小说 | 石原莉奈在线亚洲三区| 久久久久久久久久久久久女国产乱| 色妞www精品视频| 韩国一区二区三区| 亚洲高清视频的网址| 国产视频一区在线观看 | 99在线视频精品| 免费在线观看日韩欧美| 亚洲欧洲国产日本综合| 精品国产自在久精品国产| 一本色道久久综合精品竹菊| 国产在线国偷精品产拍免费yy| 亚洲国产精品欧美一二99| 久久女同互慰一区二区三区| 欧美日韩成人综合天天影院| 丁香亚洲综合激情啪啪综合| 日本欧美久久久久免费播放网| 亚洲人成小说网站色在线| 久久综合中文字幕| 欧美一级在线免费| 欧洲精品一区二区三区在线观看| 国产成人精品一区二| 丝袜诱惑制服诱惑色一区在线观看| 国产精品久久久久久久久图文区| 日韩欧美国产一区二区三区| 欧美艳星brazzers| 92精品国产成人观看免费| 国产成人亚洲精品狼色在线| 久久99久久久久| 日韩电影在线免费观看| 亚洲自拍偷拍九九九| 自拍视频在线观看一区二区| 国产午夜精品在线观看| 亚洲精品在线观| 91精品啪在线观看国产60岁| 欧美三级资源在线| 色综合久久综合| 91日韩精品一区| 99精品热视频| 99精品视频中文字幕| 粉嫩13p一区二区三区| 国产伦精品一区二区三区免费迷 | 日韩色在线观看| 欧美日韩亚洲另类| 在线日韩av片| 在线精品视频一区二区三四| 成人的网站免费观看| 成人18精品视频| 大胆亚洲人体视频| 成人av资源网站| 99在线热播精品免费| 成人激情视频网站| 成人黄色网址在线观看| 大陆成人av片| 成人免费观看男女羞羞视频| 国产成人av一区| 成人久久视频在线观看| av亚洲精华国产精华精华| 99精品国产99久久久久久白柏| 成人app软件下载大全免费| 成av人片一区二区| 94-欧美-setu| 欧美三级资源在线| 欧美高清视频www夜色资源网| 欧美一区二区免费视频| 欧美哺乳videos| 久久久久久久久久久久电影 | 精品国产一区二区亚洲人成毛片 | 久久久久久久精| 国产精品素人一区二区| 国产精品成人免费| 伊人夜夜躁av伊人久久| 亚洲图片自拍偷拍| 日韩成人一级片| 极品美女销魂一区二区三区| 国产成人在线影院| 色综合中文字幕国产 | 99国内精品久久| 亚洲福中文字幕伊人影院| 日韩午夜小视频| av不卡在线观看| 日本中文一区二区三区| 亚洲一区二区三区四区在线免费观看| 欧美在线啊v一区| 国产精品一级二级三级| 亚洲最新视频在线观看| 国产亚洲一区字幕| 日韩欧美成人一区| 国产精品天美传媒沈樵| 国产精品久久久久三级| 一二三四社区欧美黄| 蜜桃久久精品一区二区| 岛国精品在线观看| 在线观看三级视频欧美| 日韩女优av电影在线观看| 国产欧美久久久精品影院| 一区二区三区免费看视频| 日韩—二三区免费观看av| 国产激情91久久精品导航| 色欧美日韩亚洲| 日韩欧美卡一卡二|