Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
190B
Posts: 14
Registered: ‎10-15-2008
My Device: Not Specified

IOException thrown from HTTP Push

I'm sending an HTTP Push to a BES (MDS_4.1.5.26) and everytime I try to send the push I am getting a 406 response code back:

 

 

java.io.IOException: Server returned HTTP response code: 406 for URL: http://123.456.789:8080/push?DESTINATION=email@address.com&PORT=6234&REQUESTURI=/

And this is the code that is calling it:

 

 

try { URL _pushURL = null; _pushURL = new URL("http", BES_IP, BES_PORT, "/push?DESTINATION="+ BB_PIN +"&PORT="+HANDHELD_PORT+"&REQUESTURI=/"); HttpURLConnection conn = (HttpURLConnection)_pushURL.openConnection(); conn.setDoInput(true); //for receiving the confirmation conn.setDoOutput(true); //for sending the data conn.setRequestMethod("POST"); //post the data to the BES conn.setRequestProperty("accept", "*/*"); OutputStream out = conn.getOutputStream(); String ServerSocketAddress = "socket://" + SERVER_IP + ":" + SERVER_PORT; String CriteriaConditions = ""; if(useCriteria) { CriteriaConditions = accuracy + "," + powerUsage + "," + allowCost; } else { CriteriaConditions = "none"; } System.out.println(ServerSocketAddress + "&" + CriteriaConditions); String pushString = ServerSocketAddress + "&" + CriteriaConditions; out.write(pushString.getBytes()); //write the data out.close(); // DO NOT REMOVE - Will not PUSH to MDS unless Input Stream is opened. InputStream in = null; conn.getErrorStream();"); in = conn.getInputStream(); byte[] byteArray = new byte[conn.getContentLength()]; DataInputStream dis = new DataInputStream(in); dis.readFully(byteArray); int i; while (-1 != (i = in.read())) { System.out.println(i); } in.close(); conn.disconnect(); System.out.println("Closed Push Connection"); } catch (MalformedURLException me) { System.err.println("ERROR! (Malformed)" + me.toString()); return; } catch (IOException e) { System.err.println("ERROR! (IOException)" + e.toString()); return; }

 

 I cannot determine what the reason for this error is, as on three other BES servers this issue does not arrise (same and different versions).

 

Also, does anyone know why you must create an InputStream form the HttpUrlConnection in order to send a push? If I remove that line (which is also throwing the exception) it won't send the push to the Blackberry device.

 

Thanks for your help.

 

 

Please use plain text.
Administrator
MSohm
Posts: 14,560
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

Re: IOException thrown from HTTP Push

What message is returned from the MDS Connection Service along with the 406 response code?
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.