Troubleshooting guide

222
BlackBerry Java Development Environment Development Guide
Write a server-side push application
To create a push application, you can use any programming language that can establish an HTTP connection . The
following sections use standard Java™ to demonstrate a server-side push application.
Task Steps
Specify a port. If you create a client/server push application, you must make sure that the server-side application
uses a port number other than 80, 443, 7874, and 8080 to deliver push data.
> To specify a different port number, in the application, include the X-Rim-Push-Dest-Port
header with the port value.
Connect to the BlackBerry® MDS™
Connection Service.
> Establish a connection using the fully qualified computer name or IP address.
Construct the push URL. > To create a push request, perform one of the following actions:
Create a RIM push request using the following format:
/push?DESTINATION=<destination>&PORT=<port>&REQUESTURI=<uri>
<headers>
<content>
Create a PAP push request using the following format:
/pap
See “Create a RIM push request” on page 225 for more information about RIM push requests.
See “Create a PAP push request” on page 226 for more information about PAP push requests.
Connect to the BlackBerry Enterprise
Server.
1. Invoke openConnection() on the push URL.
2. Cast the object that url.openConnection() returns as an HttpURLConnection. An
HttpURLConnection represents a connection to a remote object.
HttpURLConnection conn =(HttpURLConnection)url.openConnection();
Set properties for the HTTP POST
request.
1. Create a POST request.
conn.setRequestMethod("POST"); // Post to the BlackBerry Enterprise
Server.
2. To receive confirmation, set the parameter in setDoInput(Boolean) to true to indicate
that the application intends to read data from the URL connection.
conn.setDoInput(true);
3. To send data, set the parameter in setDoOutput(Boolean) to true to indicate that the
application intends to send data to the URL connection.
conn.setDoOutput(true);
Write data to the server connection. 1. To access an output stream, invoke getOutputStream().
OutputStream out = conn.getOutputStream();
2. Write data to the output stream.
out.write(data);
3. Close the output stream.
out.close();