net.sf.j2s.ajax
Class HttpRequest

java.lang.Object
  extended bynet.sf.j2s.ajax.HttpRequest

public final class HttpRequest
extends java.lang.Object

This class is a Java implementation of browser's XMLHttpRequest object. This class can be considered as a bridge of Java's AJAX programming and JavaScript/Browser's AJAX programming.

Author:
josson smith 2006-2-11

Constructor Summary
HttpRequest()
           
 
Method Summary
 int getReadyState()
          Return read state of XMLHttpRequest.
 int getResponseCode()
          Return respose code.
 java.lang.String getResponseHeader(java.lang.String key)
          Get response header with given key.
 java.lang.String getResponseText()
          Return response raw text of XMLHttpRequest
 org.w3c.dom.Document getResponseXML()
          Return the parsed XML document of the response of XMLHttpRequest.
 void open(java.lang.String method, java.lang.String url)
          Open connection for HTTP request with given method and URL synchronously.
 void open(java.lang.String method, java.lang.String url, boolean async)
          Open connection for HTTP request with given method, URL and mode.
 void registerOnReadyStateChange(IXHRCallback onreadystatechange)
          Register XMLHttpRequest callback.
 void send()
          Send the HTTP request without extra content.
 void send(java.lang.String str)
          Send the HTTP request with given content.
 void setRequestHeader(java.lang.String key, java.lang.String value)
          Set request header with given key and value.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpRequest

public HttpRequest()
Method Detail

getReadyState

public int getReadyState()
Return read state of XMLHttpRequest.

Returns:
int ready state

getResponseText

public java.lang.String getResponseText()
Return response raw text of XMLHttpRequest

Returns:
String response text. May be null if the request is not sent or an error happens.

getResponseXML

public org.w3c.dom.Document getResponseXML()
Return the parsed XML document of the response of XMLHttpRequest.

Returns:
Document XML document. May be null if the response text is not a valid XML document.

getResponseCode

public int getResponseCode()
Return respose code.

Returns:
int response code. For more information please read about HTTP protocol.

registerOnReadyStateChange

public void registerOnReadyStateChange(IXHRCallback onreadystatechange)
Register XMLHttpRequest callback.

Parameters:
onreadystatechange - IXHRCallback callback

setRequestHeader

public void setRequestHeader(java.lang.String key,
                             java.lang.String value)
Set request header with given key and value.

Parameters:
key - String request header keyword. For more information please read about HTTP protocol.
value - String request header value

getResponseHeader

public java.lang.String getResponseHeader(java.lang.String key)
Get response header with given key.

Parameters:
key - String header keyword. For more information please read about HTTP protocol.
Returns:
String the reponse header value.

open

public void open(java.lang.String method,
                 java.lang.String url)
Open connection for HTTP request with given method and URL synchronously.

Parameters:
method - String "POST" or "GET" usually.
url - String remote URL. Should always be absolute URL.

open

public void open(java.lang.String method,
                 java.lang.String url,
                 boolean async)
Open connection for HTTP request with given method, URL and mode.

Parameters:
method - String "POST" or "GET" usually.
url - String remote URL. Should always be absolute URL.
async - boolean whether send request asynchronously or not.

send

public void send()
Send the HTTP request without extra content.


send

public void send(java.lang.String str)
Send the HTTP request with given content.

Parameters:
str - String HTTP request content. May be null.