Free Support Forum -

Viewer Java SDK requests sporadically returning


I’m using the GroupDocs Viewer Java SDK to preview documents in our web app. For some documents, I am sometimes (not always) receiving the following error from GroupDocs when I attempt to upload the document:

Jun 25 15:28:50 : com.sun.jersey.api.client.ClientHandlerException: Connection reset
Jun 25 15:28:50 : at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(
Jun 25 15:28:50 : at com.sun.jersey.api.client.Client.handle(
Jun 25 15:28:50 : at com.sun.jersey.api.client.WebResource.handle(
Jun 25 15:28:50 : at com.sun.jersey.api.client.WebResource.access$200(
Jun 25 15:28:50 : at com.sun.jersey.api.client.WebResource$
Jun 25 15:28:50 : at com.groupdocs.sdk.common.ApiInvoker.invokeAPI(
Jun 25 15:28:50 : at com.groupdocs.sdk.api.StorageApi.Upload(

This is the code snippet that is creating the error, taken almost exactly from your Java SDK samples:

ApiInvoker.getInstance().setRequestSigner( new GroupDocsRequestSigner( PRIVATE_KEY ));
final StorageApi storageApi = new StorageApi();
storageApi.setBasePath( PREVIEW_URL );
final FileStream fileStream = new FileStream( dataStream );
fileStream.setFileName( encodedFileName );
final UploadResponse uploadResponse = storageApi.Upload( CLIENT_ID, encodedFileName, null, null, fileStream );

I have tested this over and over with the same document. Sometimes it returns successfully and I am able to preview it, and other times I get the above SocketException. It seems to happen for certain documents more than others, but I haven’t yet been able to find a pattern. I’m having the same problem from your Java sample app code:

When I upload this same document and try to preview it there, sometimes it works and sometimes it doesn’t. Does anyone have any idea what might be causing this? If there was a problem with the document I would assume that it would never work, but this is not the case.


This query has been answered via email.

The final response from the customer is pasted below:

“Hi Derek,

I think I managed to resolve most of my issues with the SDK. That SocketException was being caused by something to do with the file name. Basically I have to create a temporary file, which I am then passing to your SDK as a FileInputStream. But the file name I was passing to this line:
final UploadResponse uploadResponse = storageApi.Upload( CLIENT_ID, file.getName(), null, null,
fileStream );

was NOT the name of the temporary file (as that was just being generated), but the name of the actual original file. When I changed this to the name of the temporary file, everything worked like I expected.