/* * @(#)UselessHttpFilter * * Copyright (C) 2004 John Comeau * * Uses classes obtainable from Research in Motion Limited * see Blackberry Application Developer Guide, Version 4.0, * Vol. 2, Advanced Topics * * Subclassible example of HTTP filter Protocol class */ package com.jcomeau.blackberry; import java.io.*; // for the Stream definitions (see below) import javax.microedition.io.*; // for Connection and HttpConnection import net.rim.device.api.io.FilterBaseInterface; /* this really ought to be an abstract class, but I'm a big * fan of testing at each stage... sosumi :^) */ public class UselessHttpFilter implements FilterBaseInterface, HttpConnection { public Connection openFilter(String url, int mode, boolean timesOut) { System.err.println("url: " + url + ", mode: " + mode + ", timesOut: " + timesOut); /* this shows you how the URL is passed into your filter from the API: * url: //test-blackberry.jcomeau.com/;UsePipe=true; ... (cont'd next line * DeviceSide=false;ConnectionSetup=delayed;ConnectionUID=s 00000, * mode: 3, timesOut: true */ return null; } /* these methods all have to exist in order to implement HttpConnection... * prove it by commenting any of them out and watch the compiler barf * or find the javax.microedition.io sources or docs online: * http://j2medevices.com/documentation/midp1.0/ */ // following methods may be only be invoked before connection to server public void setRequestMethod(String method) { ; } public void setRequestProperty(String key, String value) { ; } // following methods cause transition to Connected state public InputStream openInputStream() throws IOException { return null; } public OutputStream openOutputStream() throws IOException { return null; } public DataInputStream openDataInputStream() throws IOException { return null; } public DataOutputStream openDataOutputStream() throws IOException { return null; } public long getLength() { return 0L; } public String getType() { return null; } public String getEncoding() { return null; } public String getHeaderField(String key) { return null; } public int getResponseCode() { return 0; } public String getResponseMessage() { return null; } public int getHeaderFieldInt(String key, int defaultValue) { return defaultValue; } public long getHeaderFieldDate(String key, long defaultValue) { return defaultValue; } public long getExpiration() { return 0L; } public long getDate() { return 0L; } public long getLastModified() { return 0L; } // my experimentation shows that these two must be implemented early on: public String getHeaderField(int index) { return null; } public String getHeaderFieldKey(int index) { return null; } // these following may be invoked while the connection is open public void close() { ; } public String getRequestMethod() { return null; } public String getRequestProperty(String key) { return null; } public String getURL() { return null; } public String getProtocol() { return null; } public String getHost() { return null; } public String getFile() { return null; } public String getRef() { return null; } public int getPort() { return 0; } public String getQuery() { return null; } }