NEW 20080721: Code based on Firefox 3.0.1, fix some bugs.
20080621: Code based on Firefox 3.0.
20080609: Code based on Firefox 3.0rc2, provide seacatctl command, fix some bugs.
20080524: Code based on Firefox 3.0rc1, use thread pool technology.
service seacat start
service seacat stop
service seacat status
usage: seacatctl command where command is: 1) list list current settings 2) set [port|rcj|vxsmin|vxsmax|pictureHome|captureWaitTime|waterMark] value set config 3) proxy [ on <IP> <PORT> | off ] set or clear proxy setting 4) help print this help info
Example 1: seacatctl list List current settings. Example 2: seacatctl set port 4444 Set Seacat listen on 4444 port. Example 3: seacatctl set rcj 4444-5555-6666 Set register code to 4444-5555-6666. Example 4: seacatctl set vxsmin 5 Start 5 virtual browser when Seacat starts. Example 5: seacatctl set pictureHome /root Default picture storage home is /root. Example 6: seacatctl set captureWaitTime 1500 Set wait time before capture to 1500ms. Example 7: seacatctl set waterMark zhuatang.com Set watermark text to zhuatang.com. Example 8: seacatctl proxy on 192.168.28.91 8080 Set proxy : 192.168.28.91, port 8080. Example 9: seacatctl proxy off Clear proxy. Note:vxsmax not used.
usage: capture [-h host] [-p port] [-f] [-s WWWxHHH...] [-w timeToWait] [-o imageFormat] url1 url2 ...
Options: -h host which Seacat listens on, default: localhost -p port which Seacat listens, default: 5060 -f enable full page snapshot -s specify various thumnail sizes, such as "400x300 800x600" -w wait time before capture (unit: milliseconds) -o image output format, default: png. url1 url2... URLs you want to take snapshot on.
Output:
<url> {+++|---} <scid>
+++ capture OK
--- capture failed
Example1: capture www.zhuatang.com www.wenwenba.com Example2: capture -s "109x82 330x220" www.zhuatang.com www.wenwenba.com Example3: capture -f -s "82x78 400x300" www.zhuatang.com www.zaobao.com
Default listen on port: 5060
Request - client send snapshot request as follows (Each line ends with <LF>, <LF> stands for new line character, request ends with blank line)
GET <url> <LF>
thumb-sizes: <size1> <size2> ... <LF>
enable-full: 0|1 <LF>
picture-home: <pictureHome> <LF>
prefix: <prefix> <LF>
suffix: <suffix> <LF>
rename-to: <renameTo> <LF>
content-length: <length> <LF>
<LF>
<contents>
Note:<url> is url you'll take snapshot on, it's a must; <sizeN> is thumbnail size, it's format: WWWxHHH, WWW is snapshot width, HHH is snapshot height. Take full page snapshot when enable-full is 1; <pictureHome> is directory of image storage; <prefix> specify prefix of snapshot file; <suffix> specify suffix of snapshot file; <renameTo> can rename snapshot file; When you want send/post some data or arguments to specified url, you must specify <length> and <contents>.
Response message (Snapshot OK)
SEACAT/3.8 200 OK <LF>
SCID: <SCID> <LF>
<LF>
Note: <SCID> is prefix of snapshot file (including path), snapshot filename format is <SCID>-WWWxHHH.<suffix>, full page snapshot filename format is <SCID>-full.<suffix>. <suffix> is image format, default png. If request has rename-to option, snapshot filename will be <SCID>.<suffix>.
Response message(Snapshot failed)
SEACAT/3.8 <code> <message><LF>
<LF>
package com.syntimes.commons;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.util.StringTokenizer;
import org.apache.commons.lang.math.NumberUtils;
/**
* seacat capture
* @author zhsoft88
* @since 2008-4-13
*/
public class Seacat {
public static final int PORT = 5060;
/**
* capture result
* @author zhsoft88
* @since 2008-4-13
*/
public static class SeacatResult {
private int status;
private String scid;
private long time;
public SeacatResult(int status,String scid,long time) {
this.status = status;
this.scid = scid;
this.time = time;
}
public long getTime() {
return time;
}
public int getStatus() {
return status;
}
public String getScid() {
return scid;
}
@Override
public String toString() {
return "[status="+status+",scid="+scid+",time="+time+"]";
}
}
/**
* capture configuration
* @author zhsoft88
* @since 2008-4-13
*/
public static class SeacatConf {
private String url;
private String thumbSizes;
private int waitTime;
private boolean enableFull;
private String pictureHome;
private String prefix;
private String suffix;
private String renameTo;
private String postData;
public SeacatConf() {
waitTime = -1;
enableFull = false;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getThumbSizes() {
return thumbSizes;
}
public void setThumbSizes(String thumbSizes) {
this.thumbSizes = thumbSizes;
}
public int getWaitTime() {
return waitTime;
}
public void setWaitTime(int waitTime) {
this.waitTime = waitTime;
}
public boolean isEnableFull() {
return enableFull;
}
public void setEnableFull(boolean enableFull) {
this.enableFull = enableFull;
}
public String getPictureHome() {
return pictureHome;
}
public void setPictureHome(String pictureHome) {
this.pictureHome = pictureHome;
}
public String getPrefix() {
return prefix;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public String getSuffix() {
return suffix;
}
public void setSuffix(String suffix) {
this.suffix = suffix;
}
public String getRenameTo() {
return renameTo;
}
public void setRenameTo(String renameTo) {
this.renameTo = renameTo;
}
public String getPostData() {
return postData;
}
public void setPostData(String postData) {
this.postData = postData;
}
}
private String host;
private int port;
public Seacat() {
this("localhost");
}
public Seacat(String host) {
this(host,PORT);
}
public Seacat(String host,int port) {
this.host = host;
this.port = port;
}
/**
* capture web page
* @param conf
* @return
* @throws Exception
*/
public SeacatResult capture(SeacatConf conf) throws Exception {
long t1 = System.currentTimeMillis();
Socket socket = new Socket(host,port);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
if (conf.getUrl()!=null) {
bw.write("get "+conf.getUrl()+"\r\n");
}
if (conf.getThumbSizes()!=null) {
bw.write("thumb-sizes: "+conf.getThumbSizes()+"\r\n");
}
bw.write("enable-full: "+(conf.isEnableFull()?"1":"0")+"\r\n");
if (conf.getWaitTime()!=-1) {
bw.write("wait-time: "+conf.getWaitTime()+"\r\n");
}
if (conf.getPictureHome()!=null) {
bw.write("picture-home: "+conf.getPictureHome()+"\r\n");
}
if (conf.getPrefix()!=null) {
bw.write("prefix: "+conf.getPrefix()+"\r\n");
}
if (conf.getSuffix()!=null) {
bw.write("suffix: "+conf.getSuffix()+"\r\n");
}
if (conf.getRenameTo()!=null) {
bw.write("rename-to: "+conf.getRenameTo()+"\r\n");
}
if (conf.getPostData()!=null&&conf.getPostData().length()>0) {
bw.write("content-length: "+conf.getPostData().length()+"\r\n");
}
bw.write("\r\n");
if (conf.getPostData()!=null&&conf.getPostData().length()>0) {
bw.write(conf.getPostData());
}
bw.flush();
BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream(),"utf-8"));
String line = br.readLine();
int status = -1;
StringTokenizer st = new StringTokenizer(line," ");
st.nextToken();
status = NumberUtils.toInt(st.nextToken());
String scid = null;
while ((line=br.readLine())!=null) {
if (line.length()==0) break;
if (line.startsWith("SCID: ")) {
scid = line.substring(6);
}
}
socket.close();
long t2 = System.currentTimeMillis();
return new SeacatResult(status,scid,t2-t1);
}
}
package com.syntimes.commons.tests;
import com.syntimes.commons.Seacat;
import com.syntimes.commons.Seacat.SeacatConf;
import com.syntimes.commons.Seacat.SeacatResult;
public class TestSeacat {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
Seacat seacat = new Seacat();
SeacatConf conf = new SeacatConf();
conf.setUrl("http://localhost:8080/docs/");
conf.setThumbSizes("160x120 1027x768");
conf.setWaitTime(1000);
// NameValuePair[] pairs = {
// new NameValuePair("name","zzz"),
// new NameValuePair("age","23"),
// };
// String charset = "gb2312";
// conf.setPostData(EncodingUtil.formUrlEncode(pairs, charset));
SeacatResult result = seacat.capture(conf);
System.out.println(result);
}
}