*/
public void run() {
String result = "";
OutputStream os = null;
InputStream is = null;
final Connection connection = _connectionDescriptor.getConnection();
try {
// Check if URL starts with "socket", "tls", or "ssl" protocols.
// In this case send a HTTP GET request before opening
// InputStream
if (_url.startsWith("socket://") || _url.startsWith("tls://")
|| _url.startsWith("ssl://")) {
// Send HTTP GET to the server
final OutputConnection outputConn =
(OutputConnection) connection;
os = outputConn.openOutputStream();
final String getCommand =
"GET " + "/" + " HTTP/1.0\r\n\r\n";
os.write(getCommand.getBytes());
os.flush();
}
// Get InputConnection and read the server's response
final InputConnection inputConn = (InputConnection) connection;
is = inputConn.openInputStream();
final byte[] data =
net.rim.device.api.io.IOUtilities.streamToBytes(is);
result = new String(data);
is.close();
_renderBtn.setEnabled(true);
} catch (final Exception e) {
result = "ERROR fetching content: " + e.toString();
_renderBtn.setEnabled(false);
} finally {
// Close OutputStream
if (os != null) {
try {
os.close();
} catch (final IOException e) {
}
}
// Close InputStream
if (is != null) {
try {
is.close();
} catch (final IOException e) {
}
}
// Close InputStream
try {
connection.close();
} catch (final IOException ioe) {
}
}
// Show a response received from a connection or an error