Getting started

To get started with jWAP, add "jWAP.jar" to your classpath. For simple WAP GET/POST requests, you might use the class net.sourceforge.jwap.WAPClient.

jWAP communicates with a WAP gateway. You may try out a public WAP gateway like waptunnel or install your own WAP gateway (e.g. Kannel).

The example below demonstrates how to send a GET request using the WAPClient. It uses a locally running WAP gateway listening on port 9201:

import java.net.SocketException;
import java.net.UnknownHostException;

import net.sourceforge.jwap.GetRequest;
import net.sourceforge.jwap.Request;
import net.sourceforge.jwap.Response;
import net.sourceforge.jwap.WAPClient;

/**
 * Sample program that shows how to send a WAP GET request using jWAP
 */
public class WAPTest 
{
  public static void main(String[] args) 
    throws UnknownHostException, SocketException, IllegalStateException 
  {
      // Create a WAP client communicating with a WAP gateway running on localhost
      WAPClient client = new WAPClient("localhost", 9201);
      
      client.connect(60000); // Connect to the WAP gateway (timeout: 60 seconds)
      
      try {
        // Create a GET request
        Request req = new GetRequest("http://www.gnu.org/licenses/lgpl.txt");
        
        // Execute the Request (wait max 30 seconds for response)
        Response resp = client.execute(req,30000);
        
        System.out.println(resp);
        System.out.println(new String(resp.getResponseBody()));
        
      } finally {
        // Disconnect from the WAP gateway
        client.disconnect();
      }
  }
}

This is what it looks like when running the sample above (Note that the output has been truncated):

mcdmx@myhost:~$ java -cp lib/jWAP.jar:. WAPTest
Status          : 200 - OK
ContentType     : text/plain
ContentLength   : 26430
Headers         :
   Date: Thu, 28 Apr 2005 13:01:11 CEST
   Server: Apache/1.3.31 (Debian GNU/Linux) mod_python/2.7.10 Python/2.3.4
   Last-Modified: null
   Etag: null
   Accept-Ranges: null
   Content-Length: 26430
                  GNU LESSER GENERAL PUBLIC LICENSE
                       Version 2.1, February 1999

 Copyright (C) 1991, 1999 Free Software Foundation, Inc.
     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

[This is the first ...

Requirements

jWAP 1.1 requires JDK/JRE Version 1.2 or higher. To use the WBXML parser, a SAX parser implementing the Java API for XML Processing (JAXP) must be accessible:

  • Starting with Java Version 1.4, an implementation of the JAXP-API is already included in the JRE.
  • For previous Java versions, you must add a SAX parser and the JAXP-API classes to the classpath. We recommend using the Apache Xerces XML Parser which is freely available at xml.apache.org

Debugging

If available, jWAP uses the Log4j Logging framework. Just add the Log4j library to your classpath and configure log4j (as described in the Log4j manual) and jWAP will use it.