Troubleshooting guide

230
BlackBerry Java Development Environment Development Guide
getContentPane().add(_panel);
_panel.setBounds(0, 0, 300, 450);
}//GEN-END:initComponents
private void sendButtonMouseClicked(java.awt.event.MouseEvent evt)
{//GEN-FIRST:event_sendButtonMouseClicked
String text =_textArea.getText();
if(_rimButton.isSelected()) postData(text);
else if(_papButton.isSelected()) papPush(text);
}//GEN-LAST:event_sendButtonMouseClicked
/**
* <p>posts the specified data to the device
* <p>The URL is hardcoded for the purposes of this demo, and takes the form:
* http://&lt;host&gt;:&lt;port&gt;/push?DESTINATION=&ltdevice
pin&gt;&PORT=&lt;device_port&gt;&REQUESTURI=&lt;post uri&gt;
* param data the data to post
*
*/
private void postData(String data)
{
String pushId=”pushID:”+random.nextInt();
setupNotifyThread();
try {
URL url = getPushURL(_pinField.getText());
System.out.println(_resources.getString(“HTTPPushServer.status.sendingToString”) +
url.toString());
//open the connection using the static member...
HttpURLConnection conn =(HttpURLConnection)url.openConnection();
conn.setDoInput(true);//For receiving the confirmation
conn.setDoOutput(true);//For sending the data
conn.setRequestMethod(“POST”);//Post the data to the proxy
conn.setRequestProperty(“X-RIM-PUSH-ID”, pushId);
conn.setRequestProperty(“X-RIM-Push-NotifyURL”, notifyURL);
conn.setRequestProperty(“X-RIM-Push-Reliability-Mode”,”APPLICATION”);
//Write the data
OutputStream out = conn.getOutputStream();
out.write(data.getBytes());
out.close();
InputStream ins =conn.getInputStream();
int contentLength =conn.getContentLength();
System.out.println(
_resources.getString(“HTTPPushServer.status.contentLengthDescription”)+ contentLength);
if (contentLength > 0)
{
byte[] someArray = new byte [contentLength];
DataInputStream dins = new DataInputStream(ins);
dins.readFully(someArray);