4

We have built java based REST Webservices for the mobile app to interact with Sharepoint server. We are hosting webservices on weblogic server. Textual data is transferred in JSON format and file assets are transferred to iPad application as a binary stream. We are using HTTP GET to retrieve the file asset from the sharepoint. We have been noticing issues while trying to retrieve file assets which are greater than 20MB and only in production environment.

For files greater than 20MB, we have been noticing java.net.SocketException:Connection reset or java.net.SocketException: Socket closed depending on when the socket is closed.

We are using Apache HTTPClient 4.2 as http client and apache commons IO library for copy the output stream.

Below is the code -

  public org.apache.http.HttpEntity getAssetEntity(final String uri) {


    DefaultHttpClient client = new DefaultHttpClient();
    client.getParams().setParameter("http.connection.stalecheck", new Boolean(true));
    authProvider.addAuthentication(client);

    // Encode only special chars and not the whole URI
    String repURI = "";
    try {
        URL url = new URL(uri);
        URI httpURI = new URI(url.getProtocol(), url.getUserInfo(),
                url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());
        repURI = httpURI.toString();
    } catch (Exception e) {
        throw new SharePointClientException(e);
    }

    LOGGER.debug("Requesting OutputStream from URL:" + repURI);
    HttpGet httpget = new HttpGet(repURI);
    HttpResponse response = null;
    try {
        response = client.execute(httpget);
        org.apache.http.HttpEntity ent = response.getEntity();
        return ent;
    } catch (IOException e) {
        throw new SharePointClientException(e);
    }

}

protected StreamingOutputDetails getStreamingOutputForChapterAsset(final String assetURL) throws AuthorizationException {
    final HttpEntity assetEntity = getClient().getAssetEntity(assetURL);
    final StreamingOutputDetails streamingOutputDetails = new StreamingOutputDetails();
    streamingOutputDetails.setOutputSize((int) assetEntity
            .getContentLength());
    streamingOutputDetails.setStreamingOutput(new StreamingOutput() {
        @Override
        public void write(OutputStream output) throws IOException {
            try {
                getClient().streamFileAsset(assetEntity, output);
            } catch (SharePointClientException e) {
                // since write() throws IOException, we need to throw a
                // checked exception,
                // so wrap the current exception in an IOException
                throw new IOException(e);
            } catch (SharePointResourceException e) {
                // since write() throws IOException, we need to throw a
                // checked exception,
                // so wrap the current exception in an IOException
                throw new IOException(e);
            } catch (AuthorizationException e) {
                throw new IOException(e);
            }
        }
    });
    return streamingOutputDetails;  
}

   @Override
public void streamFileAsset(org.apache.http.HttpEntity assetEntity,
        OutputStream output) {

    InputStream contentStream = null;
    CloseShieldInputStream closeShieldInputStream = null;
    int bytes = 0;
    try {

        contentStream = assetEntity.getContent();
        closeShieldInputStream = new CloseShieldInputStream(contentStream);
        bytes = IOUtils.copy(closeShieldInputStream, output);
        EntityUtils.consume(assetEntity);

    } catch (IOException e) {
        throw new SharePointClientException(e);
    } finally {

        LOGGER.debug("bytes copied to output stream:" + bytes);
        if(null != closeShieldInputStream) {
            IOUtils.closeQuietly(closeShieldInputStream);
        }
        if (null != contentStream) {
            IOUtils.closeQuietly(contentStream);
        }
    }

}

This is only happening in production and uat environments where we cannot have wireshark installed to debug this further. Have validated the sharepoint setting and weblogic settings and they are same as other environments.

Below is the stack trace of the error -

Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at org.apache.http.impl.io.AbstractSessionInputBuffer.read(AbstractSessionInputBuffer.java:204)
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:182)
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:204)
at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:155)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1792)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1769)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:1744)
at com.test.client.SharePointServerListClient.streamFileAsset(SharePointServerListClient.java:217)

Thanks!

1
  • how long the connection last before the reset? Commented Jan 15, 2014 at 17:36

1 Answer 1

3

The peer closed the connection, then you wrote to it, then it issued a reset, then you tried a read. This is an application protocol error of some kind. Probably you sent it something invalid to make it close.

1
  • > Probably you sent it something invalid to make it close: quite likely there is a cap on the max request length Commented Jan 16, 2014 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.