Free Support Forum - groupdocs.com

Viewer Java SDK requests sporadically returning java.net.SocketException


#1

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: java.net.SocketException: Connection reset
Jun 25 15:28:50 : at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:151)
Jun 25 15:28:50 : at com.sun.jersey.api.client.Client.handle(Client.java:648)
Jun 25 15:28:50 : at com.sun.jersey.api.client.WebResource.handle(WebResource.java:680)
Jun 25 15:28:50 : at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
Jun 25 15:28:50 : at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:568)
Jun 25 15:28:50 : at com.groupdocs.sdk.common.ApiInvoker.invokeAPI(ApiInvoker.java:218)
Jun 25 15:28:50 : at com.groupdocs.sdk.api.StorageApi.Upload(StorageApi.java:196)


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:
http://groupdocs-java-samples.herokuapp.com/sample23

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.

#2

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.

Thanks”