<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    方槍槍的java世界

    不要因為風雨飄落就停止了你的腳步,真正的得失就在你的心中。 做喜歡做的事,不輕言放棄!

    03 一個簡單的HttpServer_Command_CommandImpl

    package com.tianhe.frm.http;

    public interface Command
    {
        public byte[] execute(String resource, char[] postData, String charset);
    }


    package com.tianhe.frm.http;

    import java.io.UnsupportedEncodingException;
    import java.util.Properties;

    import com.tianhe.frm.context.GlobalConfig;
    import com.tianhe.frm.utils.PropertiesUtil;
    import com.tianhe.frm.utils.StringUtil;

    public class CommandImpl implements Command
    {
        private String DEFAULT_RESPONSE;
       
        private String resultConfig = "response.properties";
       
        private Properties resultMapping;
       
        public CommandImpl()
        {
            init(resultConfig);
        }
       
        private void init(String resultConfig2)
        {
            try
            {
                if (StringUtil.isNotEmpty(resultConfig))
                {
                    this.resultMapping = PropertiesUtil.loadProperties(ProcessorImpl.class, resultConfig);
                }
               
                this.DEFAULT_RESPONSE = createDefaultResponse();
            }
            catch (Exception e)
            {
                System.err.println("ProcessorImpl.init failed, ignored!");
            }
        }
       
        protected String createDefaultResponse()
        {
            String defaultResponse = GlobalConfig.getString("ProcessorImpl.DEFAULT_RESPONSE",
                    "request url[%REQUEST_URL%] is not configured in reponse config!");
            return defaultResponse;
        }
       
        public byte[] execute(String resource, char[] postData, String charset)
        {
            String resKey = resource;
            resKey = resKey.replace("=", "__");
            resKey = resKey.replace(":", "--");
            resKey = resKey.replace("\"", "");
           
            byte[] resVal = createResultData(resource, resKey, charset);
           
            return resVal;
        }
       
        protected byte[] createResultData(String resource, String resKey, String charset)
        {
            String resVal = resultMapping.getProperty(resKey);
            if (StringUtil.isEmpty(resVal))
            {
                resVal = DEFAULT_RESPONSE.replaceAll("%REQUEST_URL%", resource);
            }
           
            byte[] resData = null;
            try
            {
                // resVal = URLEncoder.encode(resVal, charset);
                resData = resVal.getBytes(charset);
            }
            catch (UnsupportedEncodingException e)
            {
                e.printStackTrace();
            }
           
            return resData;
        }
       
        public static void main(String[] args)
        {
            CommandImpl s = new CommandImpl();
            Properties p = s.resultMapping;
            for (Object key : p.keySet())
            {
                System.out.println(key + "<->" + p.getProperty(key.toString()));
            }
        }
    }

    posted on 2012-07-09 22:14 做強大的自己 閱讀(190) 評論(0)  編輯  收藏 所屬分類: Socket

    主站蜘蛛池模板: 国产做床爱无遮挡免费视频| 一个人看的www免费在线视频| 国产成人AV片无码免费| 伊伊人成亚洲综合人网7777| 亚洲av成本人无码网站| 国产成人啪精品视频免费网| 亚洲av无码兔费综合| 国内大片在线免费看| 色窝窝亚洲AV网在线观看| 超pen个人视频国产免费观看| 亚洲爆乳大丰满无码专区 | 99无码人妻一区二区三区免费| 亚洲天堂久久精品| 精品免费久久久久久久| 亚洲五月综合网色九月色| 毛片a级毛片免费观看免下载| 亚洲午夜理论片在线观看| 日本视频免费在线| 久久www免费人成精品香蕉 | 亚洲免费视频观看| 成人无遮挡裸免费视频在线观看 | 亚洲国产夜色在线观看| 在线精品免费视频| 一级女性全黄久久生活片免费| 亚洲一区无码中文字幕| 久久国产精品免费视频| 亚洲videos| 久久亚洲国产成人影院网站| 国产精品免费福利久久| 天堂亚洲国产中文在线| 亚洲精品高清一二区久久| 久久青草免费91线频观看站街| 亚洲国产成人99精品激情在线| 免费成人午夜视频| 84pao强力永久免费高清| 亚洲人成网站在线播放2019| 亚洲中文字幕无码一久久区| 99久久99这里只有免费费精品| 色窝窝亚洲AV网在线观看| 久久精品7亚洲午夜a| 香蕉高清免费永久在线视频|