?? wapptr.java~349~
字號:
FileType.equals("JAD")) {
if (CheckJar(payload) == 1) {
LogStr[11] = "df" + dstr + "." + FileType;
wbfile = currentdir + "\\df" + dstr + "." + FileType;
wmlfile = currentdir + "\\df" + dstr + "." + FileType;
} else {
wmlflag = 1;
if (xhtml_wml == 1) {
LogStr[11] = "df" + dstr + ".wbxml";
} else {
LogStr[11] = "df" + dstr + ".wml";
}
wbfile = currentdir + "\\df" + dstr + ".wbxml";
wmlfile = currentdir + "\\df" + dstr + ".wml";
}
} else {
LogStr[11] = "df" + dstr + "." + FileType;
wbfile = currentdir + "\\df" + dstr + "." + FileType;
wmlfile = currentdir + "\\df" + dstr + "." + FileType;
}
}
try {
FileOutputStream wapContent = new FileOutputStream(wbfile);
wapContent.write(payload);
wapContent.close();
} catch (Exception exp) {
//exp.printStackTrace();
System.out.println("寫文件失敗");
System.exit(1);
}
// Decode the bytes in WBXML file to get wml file
if (xhtml_wml == 1) {
waitfor = 1;
}
if (wmlflag == 1) {
if (xhtml_wml == 1) {
return;
}
FileInputStream tokenStream1;
try {
tokenStream1 = new FileInputStream(wbfile);
//check if 2.0 =================================
BufferedReader reader = null;
reader = new BufferedReader(new InputStreamReader(
tokenStream1, "UTF-8"));
String oneline;
StringBuffer sb = new StringBuffer("");
int i = 0;
while ((oneline = reader.readLine()) != null) {
if (!oneline.equals("")) {
sb.append(oneline.toUpperCase());
i++;
if (i > 4) {
break;
}
}
}
reader.close();
tokenStream1.close();
int pos1 = sb.indexOf("<!DOCTYPE");
if (pos1 >= 0) {
int pos2 = sb.indexOf(">", pos1);
if (pos2 > pos1) {
String txt = sb.substring(pos1, pos2 + 1);
int pos3 = txt.indexOf("HTMLL 4.01");
int pos4 = txt.indexOf("XHTML");
if (pos3 >= 0 || pos4 >= 0) {
flag20 = 1;
LogStr[11] = "df" + dstr + ".wbxml";
}
}
} else {
int pos51 = sb.indexOf("HTML");
if (pos51 >= 0) {
flag20 = 1;
LogStr[11] = "df" + dstr + ".wbxml";
}
}
//=============================================
if (flag20 == 1) {
//FileOutputStream wapContent20 = new FileOutputStream(htmlfile);
//wapContent20.write(payload);
//wapContent20.close();
} else {
FileInputStream tokenStream = new FileInputStream(wbfile); ;
FileOutputStream xmlStream = new FileOutputStream(wmlfile);
Document document = WBXMLDecoder.getInstance().decode(
tokenStream);
if (!document.hasChildNodes()) {
LogStr[11] = "df" + dstr + ".wbxml";
return;
}
OutputFormat of = new OutputFormat(document);
XMLSerializer serial = new XMLSerializer(xmlStream, of);
serial.setOutputByteStream(xmlStream);
serial.setOutputFormat(of);
serial.asDOMSerializer();
serial.serialize(document);
xmlStream.close();
tokenStream.close();
}
} catch (Exception e) {
//e.printStackTrace();
System.out.println("寫wml文件異常");
}
}
if (xhtml_wml == 1) {
waitfor = 1;
}
}
// -----------------------------------------------------------
private class UpperLayerImpl implements IWSPUpperLayer2 {
// Connection established
public void s_connect_cnf() {
complete(sessionLock, CONNECTED);
}
public void s_disconnect_ind(short reason) {
if (log.isDebugEnabled()) {
log.debug("s_disconnect_ind(" + reason + ")");
}
complete(sessionLock, "DISCONNECTED: " + reason);
session = null;
}
public void s_disconnect_ind(CWSPSocketAddress[] redirectInfo) {
complete(sessionLock, redirectInfo);
}
public void s_methodResult_ind(CWSPResult result) {
//writeBytesToFile(result.getPayload());
if (Sendflg == 1) {
} else {
if (CWTPStatue.GetResultState() == 32) {
if (result.getPayload().equals("") ||
result.getPayload().length == 0) {
downloadflg = 0;
} else {
writeBytesToFile(result.getPayload());
downloadflg = 1;
}
} else {
//System.out.println("下載失敗");
downloadflg = 0;
//System.exit(1);
}
}
Response response = new Response(result);
CWSPMethodManager mgr = result.getMethodManager();
// Acknowledge reception (TODO: arg should not be null)
mgr.s_methodResult(null);
complete(mgr, response);
}
public void s_suspend_ind(short reason) {
if (reason == 1000) {
downtime = System.currentTimeMillis();
} else {
if (log.isDebugEnabled()) {
log.debug("s_suspend_ind(" + reason + ")");
}
}
}
public void s_resume_cnf() {
log.debug("s_resume_cnf()");
}
public void s_disconnect_ind(InetAddress[] redirectInfo) {
}
public void s_methodResult_ind(byte[] payload, String contentType,
boolean moreData) {
if (xhtml_wml == 1) {
if (Sendflg == 1) {
waitfor = 1;
} else {
if (payload.equals("") || payload.length == 0 ||
payload.equals("下載失敗") || !moreData) {
waitfor = 2;
downloadflg = 0;
} else {
writeBytesToFile(payload);
downloadflg = 1;
}
}
} else {
/* if (Sendflg == 1) {
return;
} else {
if (CWTPStatue.GetResultState() == 32) {
if (payload.equals("") || payload.length == 0) {
downloadflg = 0;
} else {
writeBytesToFile(payload);
downloadflg = 1;
}
} else {
//System.out.println("下載失敗");
downloadflg = 0;
//System.exit(1);
}
}*/
}
}
}
private class UpperLayerHttp implements HttpUpperLayer {
public void tr_result(int pcode, byte[] poly) {
if (pcode == -1) {
waitfor = 2;
} else {
writehttpfile(poly);
}
}
public void tr_abort(short abortReason) {
}
public void tr_download(int pcode) {
}
}
public static void main(String[] args) throws FileNotFoundException,
UnknownHostException, IOException, IllegalStateException,
SocketException {
if (args.length < 4) {
System.err.println(USAGE);
System.exit(1);
}
String wapGW = "10.0.0.172";
int wapPort = 9201;
int argp = 0;
String method = args[argp];
String userAgent = null;
String output = null;
boolean showHeaders = false;
String contentType = null;
String input = null;
String url = null;
String locaddr = null;
InetAddress la = null;
int lp = CWTPSocket.DEFAULT_PORT;
long tc = DEFAULT_CONNECT_TIMEOUT;
long tx = DEFAULT_EXEC_TIMEOUT;
int WorkMode;
String ConfFile;
String Logfilename;
WorkMode = Integer.parseInt(args[0]);
ConfFile = args[1];
Logfilename = args[2];
if (!FileWork.FW_ChkMakdir("JwapMsgLog")) {
log.error("創建JwapMsgLog目錄失敗!");
System.exit(1);
}
WapPtr wapptr = new WapPtr(la,
lp, 0);
if (!wapptr.filework.FW_ChkMakdir("downloadforder")) {
log.error("創建downloadforder目錄失?。?quot;);
System.exit(1);
}
if (!wapptr.filework.FW_ChkMakdir("threadlog")) {
log.error("創建threadlog目錄失??!");
System.exit(1);
}
Request request = null;
OutputStream out = null;
if (output == null || "-".equals(output)) {
out = System.out;
} else {
out = new FileOutputStream(output);
}
if ("POST".equals(method)) {
if (contentType == null) {
System.err.println(
"Warning: no content-type specified, assuming " +
DEFAULT_CONTENT_TYPE);
contentType = DEFAULT_CONTENT_TYPE;
}
byte[] postData = null;
try {
postData = readPostData(input);
} catch (IOException ex1) {
}
PostRequest preq = new PostRequest(url);
request = preq;
preq.setContentType(contentType);
preq.setRequestBody(postData);
} else {
request = new GetRequest(url);
}
try {
wapptr.connect(tc);
Response response = wapptr.execute(request, tx);
if (out == System.out) {
System.out.println("");
}
if (showHeaders || !response.isSuccess()) {
out.write(("Status: " + response.getStatus() + " " +
response.getStatusText() + "\n").getBytes());
for (Enumeration e = response.getHeaderNames();
e.hasMoreElements(); ) {
String key = (String) e.nextElement();
for (Enumeration e2 = response.getHeaders(key);
e2.hasMoreElements(); ) {
String val = e2.nextElement().toString();
out.write((key + ": " + val + "\n").getBytes());
}
}
out.write("\n".getBytes());
}
out.write(response.getResponseBody());
} finally {
wapptr.disconnect();
if (out != null && out == System.out) {
out.close();
}
}
System.exit(0);
}
/**
* ReadJwapConf
*/
public boolean ReadJwapConf() {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -