Also when I execute this code, nothing in the simulator happens. Only in the MDS window do iI see .' I also get a content length of 0. Oh, and do I have to have A BES Server running as well ??
Quote:
import java.io.*;
import java.net.*;
public class CachePush
{
String MDSAddress = "localhost";
String MDSPort = "8080";
String deviceAddress = "2100000B";
String devicePort = "7874";
String pushType = "Browser-Content";
String contentUrl = "http://127.0.0.1/testpage";
String contentFile = "C:\\jakarta-tomcat-5.0.28\\webapps\\testpage\\sample.htm";
public void run()
{
try
{
// The format of the URL is http://<host>:<port>/push?DESTINATION =<user_email>&PORT=<browser_listen_port&g t;.
URL pushURL = new URL("http", MDSAddress, Integer.parseInt(MDSPort), "/push?DESTINATION="+deviceAddress+"&PORT="+devicePo rt+"&REQUESTURI=/");
HttpURLConnection conn = (HttpURLConnection)pushURL.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("x-rim-push-type", pushType);
conn.setRequestProperty("content-location", contentUrl);
conn.setDoOutput(true);
// For sending the data.
conn.setDoInput(true);
// For receiving the confirmation.
//Get data to push to cache
if (contentFile != null)
{
conn.setRequestProperty("content-type", "text/html");
FileInputStream fis = new FileInputStream(contentFile);
int length = fis.available();
byte[] input = new byte[length];
fis.read(input);
OutputStream os = conn.getOutputStream();
//Write out the file contents
os.write(input, 0, length);
}
else
{
byte[] input = new byte[0];
OutputStream os = conn.getOutputStream();
os.write(input, 0, 0);
}
// Read the response.
InputStream is = conn.getInputStream();
int contentLength = conn.getContentLength();
System.out.println("Content-Length [" + contentLength + "]");
if (contentLength > 0)
{
byte[] byteArray = new byte[contentLength];
DataInputStream dis = new DataInputStream(is);
dis.readFully(byteArray);
System.out.println(new String(byteArray));
}
}
catch (IOException iox)
{
System.err.println(iox);
}
}
public static void main(String[] args)
{
CachePush pushTest = new CachePush();
pushTest.run();
}
}
|