Atitit.实现反向代理(1)----url rewrite 配置and内容改写 and -绝对路径链接改写 java php
Atitit.实现反向代理(1)----url rewrite 配置and内容改写 and -绝对路径链接改写 java php
3. ---------反向代理rewrite 配置mode_rewrite 1
4. 排除自身(apache_mode_rewrite) 2
4. Abs url 2 /app/http://xxxxxx.jpg 4
1. 代理的实现:::普通代理and反向代理??
普通代理设置麻烦的,韩式反向代理容易的实现..
反向代理使用流程:: localhost/vod/ >>url rewrite >>>内容更改
2. url rewrite 的框架选型
Php的mode_rewrite好的...java的org.tuckey.web.filters.urlrewrite.UrlRewriteFilter 不太好使用,,,子好嘎自实现兰...
作者::老哇的爪子Attilax艾龙,EMAIL:1466519819@qq.com
转载请注明来源:http://blog.csdn.net/attilax
3. ---------反向代理rewrite 配置mode_rewrite
RewriteCond %{REQUEST_URI} !=/process.php
RewriteRule ^(.*)$ /process.php?file=http://www.budejie.com/$1&noext=1 [L] [L]
1. Java的实现
<!--o8j2 -->
<filter>
<filter-name>urlrwt</filter-name>
<filter-class>com.attilax.net.urlRewriteFilterAti</filter-class>
</filter>
<filter-mapping>
<filter-name>urlrwt</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- end o8j2-->
RequestDispatcher requestDispatcher = request.getRequestDispatcher("/spr/txtrwt?url="+url+"&urlNoHost="+url_noHost2);
requestDispatcher.forward(request, response);//
4. 排除自身(apache_mode_rewrite)
RewriteCond %{REQUEST_URI} !=/process.php
RewriteCond %{REQUEST_URI} !^.*(\.js|\.gif|\.png|\.jpg|\.jpeg|\.xml|\.ico|\.css)
#other pic css js proxy
RewriteCond %{REQUEST_URI} !=/process.php
RewriteCond %{REQUEST_URI} !=/lensyaohwer/basic.png
RewriteRule ^(.*)$ http://lengxiaohua.com/$1 [P,L]
2. Java的实现 排除自身
//except
if(requestURI.contains("spr/txtrwt"))
{
chain.doFilter(request, response);
return;
}
5. 内容改写(php mode_rwt)
a.文本正则表达式方式
$content=preg_replace('/百思不得姐/', '哈米', $content);
$content=str_replace('http://img.spriteapp.cn/ws/www/img/layout/logo.png', 'http://img.spriteapp.cn/ws/www/img/layout/logoxx.png', $content);
$content=str_replace('不得姐', '哈米', $content);
b.html dom 方式
//nbp
require_once "simple_html_dom.php";
$html = str_get_html($content);
$arr= $html->find('.web_content_right .web_right_down',0) ;
$arr->innertext='a2';
echo $html ;
3. Java 内容改写
@RequestMapping(value = "/txtrwt", produces = "text/plain;charset=gb2312")
// @ResponseBody
public Object process(HttpServletRequest request,
HttpServletResponse response) throws Exception {
core.log("=========process.json");
String url = "" + request.getParameter("url");// +"?"+request.getQueryString();
String url_no_host=request.getParameter("urlNoHost");
// System.out.println(); request.getParameter("tid")
System.out.println(request.getQueryString());
if (url.endsWith("jpg") || url.endsWith("jpeg") || url.endsWith("gif")) {
if(url_no_host.startsWith("/http://"))
{
String url3=url_no_host.replaceAll("/http://", "http://");
byte[] ba = websitex.WebpageContent_Bin(url3);
if( !isLjJpg(ba) )
outputImg(response, url);
}
else
outputImg(response, url);
}
//
else
outputTxt(response, url,request);
return null;
}
6. 内容改写---绝对路径链接改写
4. Abs url 2 /app/http://xxxxxx.jpg
private void outputTxt(HttpServletResponse response, String url, HttpServletRequest request)
throws UnsupportedEncodingException, IOException {
Map<String, String> headProps = Mapx
.<String, String> $()
.add("Cookie",
"lastfid=0; lastvisit=9271%091408838229%09%2Fread.php%3Ftid%3D1715718%26fpage%3D2; ol_offset=32204; ipstate=1408836660; __utma=99888095.1396678057.1405101634.1408806230.1408837132.29; __utmz=99888095.1405101634.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmc=99888095; pin6=done; __utmb=99888095.3.10.1408837132")
.toMap() ;
String txt=websitex.WebpageContentO8f (url,"gbk",headProps);
txt=txt.replaceAll("http://", pathx.webAppPath_webfmt(request)+ "/http://");
5. Filter 二次导航
if(url_noHost.startsWith("/http://"))
{
String url5=url_noHost.substring(1, url_noHost.length());
String url5_encode= URLEncoder.encode(url5);
RequestDispatcher requestDispatcher = request.getRequestDispatcher("/spr/imgrwt_abspath?url="+url5_encode+"&urlNoHost="+url_noHost2);
requestDispatcher.forward(request, response);//
return;
}
6. 判断and代替改写
@RequestMapping(value = "/imgrwt_abspath")
// @ResponseBody
public Object process_imgrwt_abspath(HttpServletRequest request,
HttpServletResponse response) {
core.log("=========process.json");
String url = "" + request.getParameter("url");// +"?"+request.getQueryString();
String url_no_host = request.getParameter("urlNoHost");
// System.out.println(); request.getParameter("tid")
System.out.println(request.getQueryString());
byte[] ba = websitex.WebpageContent_Bin(url);
if (!isLjJpg(ba))
outputImg(response, url);
if(isLjJpg(ba))
outputImg_garfile_holder(response );
return null;
}
/**
@author attilax 老哇的爪子
\t@since Aug 23, 2014 8:48:02 PM$
* @param response
*/
private void outputImg_garfile_holder(HttpServletResponse response) {
// attilax 老哇的爪子 8:48:02 PM Aug 23, 2014
{
String url = pathx.classPath() + "/com/attilax/clr/def.jpg";
byte[] ba = filex.readImageData(url);
outputImg(response, url, ba);
}
}
7. 引用
paip.基于urlrewrite的反向代理以及内容改写
相关文章
- java实现蔬菜价格计算
- java实现第七届蓝桥杯凑平方数
- java实现第七届蓝桥杯阶乘位数
- Java中Collections类详细用法
- Java操作MongoDB
- Java数据库篇4——表的约束
- 【面试题】Java基础
- Java 1.8中的Metaspace总结
- Atitit 业务流程执行引擎的实现 目录 1.1. 引擎实现语言java js php等1 1.2. 流程语言 xml sql js等 业务流程定义语言规范总结1 1.3. 实体方法定义2
- Atitit.常见的异常分类 目录 1. 双元分类法1 1.1. 按照语言分 java js c# php等1 1.2. 通用常见异常vs 特定异常1 1.3. Runtime ex vs c
- Atitit.http httpclient实践java c# .net php attilax总结
- Atitit.excel导出 功能解决方案 php java C#.net版总集合.doc
- Atitit. 注册表操作查询 修改 api与工具总结 java c# php js python 病毒木马的原理
- Atitit.http代理的实现 代码java php c# python
- Atitit.面向接口的web 原理与设计重写 路由启动绑定配置url router rewriting urlpage mvc mvp的 java c#.net php js
- Atitit. 数据库-----catalog与schema的设计区别以及在实际中使用 获取数据库所有库表 java jdbc php c#.Net
- atitit.http get post的原理以及框架实现java php
- atitit.激活一个窗口总结 swing java .net php
- Atitit.异步编程 java .net php python js 的比较
- atitit. 集合groupby 的实现(2)---自定义linq查询--java .net php
- paip.截取字符串byLastDot方法总结uapi python java php c# 总结
- paip.复制文件 文件操作 api的设计uapi java python php 最佳实践
- paip.函数方法回调机制跟java php python c++的实现
- Java的泛型中,通配符可以设置上限和下限
- elasticsearch java客户端api使用(一)
- GcExcel for java 6.0 简单例子 -jar has been cracked
- 产生 java.lang.NoClassDefFoundError 的另一种意外情况:jar包部分的物理性损坏
- Java-小技巧-002-String 转 long,进制转换
- atitit.软件开发GUI 布局管理优缺点总结java swing wpf web html c++ qt php asp.net winform
- Java刷题面试系列习题(十九)