net.sourceforge.jwap
Class WAPClient

java.lang.Object
  |
  +--net.sourceforge.jwap.WAPClient

public class WAPClient
extends java.lang.Object

This class represents a WSP "User-Agent" which can be used for executing WSP GET and POST methods.

Example

 WAPClient client = new WAPClient("localhost", 9201);
 Request request = new GetRequest("http://localhost/");
 client.connect();
 Response response = client.execute(request);
 client.disconnect();
 

Author:
Michel Marti

Field Summary
static long DEFAULT_CONNECT_TIMEOUT
          Default connect/disconnect timeout in milliseconds: 30000
static long DEFAULT_EXEC_TIMEOUT
          Default execute timeout in milliseconds: 180000
 
Constructor Summary
WAPClient(java.net.InetAddress wapGateway, int port)
          Construct a new WAP Client
WAPClient(java.net.InetAddress wapGateway, int wapPort, java.net.InetAddress localAddress, int localPort)
          Construct a new WAP Client
WAPClient(java.lang.String wapGateway, int port)
          Construct a new WAP Client
 
Method Summary
 void connect()
          Connect to the WAP gateway.
 void connect(CWSPHeaders headers, long timeout)
          Connect to the WAP gateway.
 void connect(long timeout)
          Connect to the WAP gateway.
 void disconnect()
          Disconnect from the WAP gateway.
 Response execute(Request request)
          Execute a request.
 Response execute(Request request, long timeout)
          Execute a request.
 boolean isConnected()
          Check if the client is currently connected to the WAP gateway
static void main(java.lang.String[] args)
          Execute a WSP GET request.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CONNECT_TIMEOUT

public static final long DEFAULT_CONNECT_TIMEOUT
Default connect/disconnect timeout in milliseconds: 30000

DEFAULT_EXEC_TIMEOUT

public static final long DEFAULT_EXEC_TIMEOUT
Default execute timeout in milliseconds: 180000
Constructor Detail

WAPClient

public WAPClient(java.lang.String wapGateway,
                 int port)
          throws java.net.UnknownHostException
Construct a new WAP Client
Parameters:
wapGateway - hostname of the WAP gateway to use
port - port-number
Throws:
java.net.UnknownHostException - if the hostname cannot be resolved

WAPClient

public WAPClient(java.net.InetAddress wapGateway,
                 int port)
Construct a new WAP Client
Parameters:
wapGateway - the address of the WAP gateway to use
port - the WAP gateway port number

WAPClient

public WAPClient(java.net.InetAddress wapGateway,
                 int wapPort,
                 java.net.InetAddress localAddress,
                 int localPort)
Construct a new WAP Client
Parameters:
wapGateway - the addresss of the WAP gateway to use
wapPort - the WAP gateway port number
localAddress - the local address to bind to
localPort - the local port to bind to (0 to let the OS pick a free port)
Method Detail

execute

public Response execute(Request request)
                 throws java.net.SocketException,
                        java.lang.IllegalStateException
Execute a request. The client must be connected to the gateway.
Parameters:
request - the request to execute
Returns:
the response
Throws:
java.net.SocketException - if a timeout occurred
java.lang.IllegalStateException - if the client is not connected

execute

public Response execute(Request request,
                        long timeout)
                 throws java.net.SocketException,
                        java.lang.IllegalStateException
Execute a request. The client must be connected to the gateway.
Parameters:
request - the request to execute
timeout - timeout in milliseconds
Returns:
the response
Throws:
java.net.SocketException - if a timeout occurred
java.lang.IllegalStateException - if the client is not connected

connect

public void connect()
             throws java.net.SocketException,
                    java.lang.IllegalStateException
Connect to the WAP gateway. Before requests can be executed, this method must be called.
Throws:
java.net.SocketException - if the connection could not be established
java.lang.IllegalStateException - if the client is already connected

connect

public void connect(long timeout)
             throws java.net.SocketException,
                    java.lang.IllegalStateException
Connect to the WAP gateway. Before requests can be executed, this method must be called.
Parameters:
timeout - timeout in milliseconds
Throws:
java.net.SocketException - if the connection could not be established
java.lang.IllegalStateException - if the client is already connected

connect

public void connect(CWSPHeaders headers,
                    long timeout)
             throws java.net.SocketException,
                    java.lang.IllegalStateException
Connect to the WAP gateway. Before requests can be executed, this method must be called.
Parameters:
timeout - timeout in milliseconds
headers - WSP headers used for connect or null objects. The headers will be encoded using the default WAP codepage.
Throws:
java.net.SocketException - if the connection could not be established
java.lang.IllegalStateException - if the client is already connected

disconnect

public void disconnect()
Disconnect from the WAP gateway. This releases used resources as well.

isConnected

public boolean isConnected()
Check if the client is currently connected to the WAP gateway
Returns:
true if the client is connected, false otherwise

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Execute a WSP GET request.
 Usage: WAPClient <WAP-Gateway-address[:port]> [GET/POST] [options] <URL>
   if method (GET/POST) is unspecified, GET is assumed
 
   Common options:
   -u    The User-Agent (defaults to jWAP/1.x)
   -o          write response to file
   -v                show response-headers
 
 POST options:
   -c  The content-type  of the response body
   -p          A file containing the post data, use '-' to read the post data from standard input