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
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: ConnectionClosedException when POSTing images via HTTPS

To reiterate my previous post:

 

This condition is not an error!  Put try {...} catch (ConnectionClosedException ...) { ... } around your code; check the total number of bytes posted when you catch it, and if your file posting is complete (happened on the last write), ignore it.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
Developer
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: ConnectionClosedException when POSTing images via HTTPS

[ Edited ]

arkadyz wrote:

... it is probably benign - the server accepted the last expected bytes and closed the connection.  Some servers just do that.  ... I talked to our server people and they claim that HTTP servers sometimes do just that to save going back and forth...


Perhaps I'm being unfair, but it sounds like your server people don't want to be bothered with fixing something that should be fixed. HTTP (HTTPS is just HTTP+SSL/TSL) is a request/response protocol, not request/hope-for-the-best. Servers are required to send a response. If a server is closing a connection without sending a response, it is not in compliance with the HTTP protocol.

 

An app should not ignore premature connection closures. From RFC2616 (section 8.2.4, if your server people ask):

If an HTTP/1.1 client sends a request which includes a request body, but which does not include an Expect request-header field with the "100-continue" expectation, and if the client is not directly connected to an HTTP/1.1 origin server, and if the client sees the connection close before receiving any status from the server, the client SHOULD retry the request.

For the record (since lyhoanghai asked): we have successfully POSTed over HTTPS (although for some still-unexplained reason we have had trouble using HTTPS at all with some Tour devices operating on Verizon).




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Please use plain text.
Contributor
demaniak
Posts: 34
Registered: ‎07-05-2011
My Device: Various
My Carrier: Generic

Re: ConnectionClosedException when POSTing images via HTTPS

At last. Somebody who has my EXACT same problem.

Except, I'm trying to use POST over SSL to perform authentication (login).

 

So I absolutely MUST receive the response the server IS actually providing.

 

In any case, if the auth call is tested with something like RESTClient (a firefox addon), every thing works precisely as expected).

 

Of the call is made without SSL (on real device), all is well.

If done on a simulator,with SSL,, all is well,

 

BUT, on real device, WITH SSL - crash-boom-bang ConnectionClosedException the moment I try to read from the server.

 

WTF?

 

So, has ANYBODY been able to resolve this?????

Please use plain text.
Contributor
demaniak
Posts: 34
Registered: ‎07-05-2011
My Device: Various
My Carrier: Generic

Re: ConnectionClosedException when POSTing images via HTTPS

[ Edited ]

MINOR update.

I added "Connection:keep-alive" header, and changed my login POST to a GET.

This is working now - but I still have to determine which change was the magic....will try to remember to update here when I know.

 

(Oh, and obviously changing to a GET will not work for all)

 

Please use plain text.
Contributor
demaniak
Posts: 34
Registered: ‎07-05-2011
My Device: Various
My Carrier: Generic

Re: ConnectionClosedException when POSTing images via HTTPS

OK.

Adding "Connection:keep-alive" to my headers seemed to resolve my problems.

 

Just some more information:

  • Using GlassFish 3.1 server
  • mostly over WiFi connection
  • NO BES server present
  • Using SSL
  • HTTP POST was resulting in the connection being closed when I try to read the response - resolved by adding "Connection:keep-alive" header.

Hope this helps somebody out there.

 

Cheers!

 

Please use plain text.