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 Contributor
Posts: 2
Registered: ‎09-28-2012
My Device: Blackberry Bold 9900
My Carrier: 11963530183

TLSIOException when uploading files to webservice

Hi friends,

 

first of all sorry my poor english.

 

I'm facing a problem when I try to upload files under SSL.
I opened a HttpsConnection and wrote the bytes of the file in the OutputStream of the connection, but, when I tried to get the responseCode an TLSIOException throws.

 

Here is my code...

 

HttpRequestUtil request = getDefaultRequest(uri)

.method(HttpRequestUtil.HTTP_POST)

.addProperty("Connection", "Keep-Alive")

.addProperty("Content-Type", "multipart/form-data; boundary=" + ApiConfigurations.BOUNDARY)

.addProperty("x-rim-transcode-content", "none")

.addProperty(HttpProtocolConstants.HEADER_CONTENT_TYPE, HttpProtocolConstants.CONTENT_TYPE_MULTIPART_FORM_DATA +";boundary=" + ApiConfigurations.BOUNDARY)

.addProperty(HttpProtocolConstants.HEADER_CONTENT_LENGTH, String.valueOf(bbFile.fileSize()));

 

request.openConnection();

 

/* First we need to open the socket to write on */

OutputStream outputStream = request.getConnection().openOutputStream();

 

/* Writting body header */

byte[] startBody = buildStartBody(bbFile.getName());

outputStream.write(startBody, 0, startBody.length);

 

/* Start to read file bytes and write in the output stream */

InputStream fileInputStream = bbFile.openInputStream();

 

int bytesRead = 0;

int bufferSize = fileInputStream.available() < BUFFER_LENGTH ? fileInputStream.available() : BUFFER_LENGTH;

if(bufferSize == 0) bufferSize = BUFFER_LENGTH;

 

byte[] buffer = new byte[bufferSize];

while ((bytesRead = fileInputStream.read(buffer)) != -1) {

outputStream.write(buffer, 0, bytesRead);

}

 

fileInputStream.close();

bbFile.close();

 

/* Writting body footer */

byte[] endBody = buildEndBody();

outputStream.write(endBody, 0, endBody.length);

outputStream.close();

 

/* At this moment I receive an exception */

request.getConnection().getResponseCode()


I would appreciate if you could help me in this trouble.

 

Thanks,

 

Developer
Posts: 152
Registered: ‎07-28-2011
My Device: Bold 9900
My Carrier: MTN

Re: TLSIOException when uploading files to webservice

Have a look at the following thread for a possible solution:

 

http://supportforums.blackberry.com/t5/Java-Development/TLSIOException-on-POSTs/td-p/1672663

New Contributor
Posts: 2
Registered: ‎09-28-2012
My Device: Blackberry Bold 9900
My Carrier: 11963530183

Re: TLSIOException when uploading files to webservice

Thansk a lot for your reply Dionysus, but I have tried the same and did not have success.