?? httpsession.java~44~
字號:
package net.sourceforge.jwap.http;
/**
* <p>Title: </p>
*
* <p>Description: nbpt</p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author chen
* @version 1.0
*/
import java.net.*;
import java.util.*;
import net.sourceforge.jwap.util.*;
import net.sourceforge.jwap.wsp.*;
public class HttpSession implements HttpUpperLayer {
// SESSION states
public static final short STATE_NULL = 0;
public static final short STATE_CONNECTING = 1;
public static final short STATE_CONNECTED = 2;
public static final short STATE_SUSPENDED = 3;
public static final short STATE_RESUMING = 4;
// Abort reason code assignments
// Table 35 in spec.
public static final short ABORT_PROTOERR = 0xE0;
public static final short ABORT_DISCONNECT = 0xE1;
public static final short ABORT_SUSPEND = 0xE2;
public static final short ABORT_RESUME = 0xE3;
public static final short ABORT_CONGESTION = 0xE4;
public static final short ABORT_CONNECTERR = 0xE5;
public static final short ABORT_MRUEXCEEDED = 0xE6;
public static final short ABORT_MOREXCEEDED = 0xE7;
public static final short ABORT_PEERREQ = 0xE8;
public static final short ABORT_NETERR = 0xE9;
public static final short ABORT_USERREQ = 0xEA;
public static final short ABORT_USERRFS = 0xEB;
public static final short ABORT_USERPND = 0xEC;
public static final short ABORT_USERDCR = 0xED;
public static final short ABORT_USERDCU = 0xEE;
static Logger logger = Logger.getLogger(HttpSession.class);
public String[] states = {
"STATE_NULL", "STATE_CONNECTING",
"STATE_CONNECTED", "STATE_SUSPENDED",
"STATE_RESUMING"
};
private boolean isSuspended = false;
private short suspendCode;
private boolean isDisconnected = false;
private short disconnectCode;
/**
* the actual session state
*/
private short state = STATE_NULL;
/**
* the acual transaction concering the session management
*/
/**
* the Layer below
*/
private HSocket socket;
/**
* Holds all pending CWSPMethodManagers of this session
*/
private Vector methods = new Vector();
/**
* Holds all pending CWSPPushManagers of this session
*/
private Vector pushes = new Vector();
//////////////////////////////////////////////////////////////////////////////
////////////////////////////// Protocol parameters and variables - sect. 7.1.3
/**
* Maximum Receive Unit (sect. 7.1.3.1)
*/
private int MRU = 1024;
/**
* Maximum Outstanding Method Requests (sect. 7.1.3.2)
*/
private int MOM = 1;
/**
* Maximum Outstanding Push Requests (sect. 7.1.3.3)
*/
private int MOP = 1;
/**
* keeps track of the number of push transactions in process in the client
* (sect. 7.1.4.2)
*/
// pushs.size();
/**
* saves the session identifier (sect. 7.1.4.3)
* We will get this from the ConnectReply by the Server
*/
private long session_id = 0;
/**
* do we use IWSPUpperLayer2 or
*/
private byte version = 0;
private IWSPUpperLayer upperlayer;
public HttpSession() {
}
public HttpSession(InetAddress toAddress, int toPort,
InetAddress localAddress, int localPort,
IWSPUpperLayer upperLayer, boolean verbose) {
this.upperlayer = upperLayer;
try {
this.socket = new HSocket(toAddress, toPort, localAddress,
localPort, this);
socket.SetSocketTimeout(90000);
} catch (Exception ex) {
this.socket = null;
}
}
public static void main(String[] args) {
HttpSession httpsession = new HttpSession();
}
public void tr_result(int pcode, byte poly[]) {
boolean flag=false;
if(pcode==-1)
{
flag=false;
}
else
{
flag=true;
}
upperlayer.s_methodResult_ind(poly, "", flag);
}
/**
* TR-Abort.ind
* @param abortReason The abort reason
*/
public void tr_abort(short abortReason) {
}
public void tr_download(int pcode)
{
short mm=1000;
upperlayer.s_suspend_ind(mm);
}
/**
* Sconnect
*/
public int Sconnect(InetAddress toAddress, int toPort) {
int ret = 5;
// socket.Sconnect(toAddress,toPort,1000);
if (socket != null) {
ret = 5;
} else {
ret = 7;
}
return ret;
}
public int Sconnect() {
int ret = 5;
socket.Sconnect();
if (socket != null) {
ret = 5;
} else {
ret = 7;
}
return ret;
}
//////////////////////////////////////////////////////////////////////////////
public synchronized int s_get(String headers, String uri) {
int ret = -1;
socket.setBaseHeads(headers);
socket.Seturl(uri);
socket.start();
/*ret = socket.GET(uri);
InputStream byteStream = socket.getInputStream();
int len = 0;
if(ret==-1)
{
ret=-1;
return ret;
}
try {
len = byteStream.available();
byte outdata[] = new byte[len + 1];
byteStream.read(outdata);
upperlayer.s_methodResult_ind(outdata, "", false);
} catch (IOException ex) {
ret=-1;
}*/
return ret;
}
public synchronized int s_post(String headers, byte[] data,
String contentType,
String uri) {
int ret = -1;
socket.setBaseHeads(headers);
socket.Seturl(uri);
socket.SetGet_Post(1);
socket.SetPostData(data);
socket.start();
return ret;
}
/**
* ThreadClose
*/
public void pThreadClose() {
socket.stop();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -