title: Connection reset by peer: socket write error httpclient and geoserver
body: <p>I need to upload zipped shapefiles to <a href="http://geoserver.org/" rel="nofollow noreferrer">GeoServer</a> through REST. The GeoServer provides an example CURL <a href="https://docs.geoserver.org/latest/en/user/rest/stores.html" rel="nofollow noreferrer">command</a> to upload the shapefile zip as follows: </p>
  
  <pre><code>curl -v -u admin:geoserver -XPUT -H "Content-type: application/zip" --data-binary @data.zip http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/Murrindindi/file.shp
  </code></pre>
  
  <p>The above CURL command works fine. However, I want to do this upload in Java httpclient. I am a newbie to Java but I have written the following code to achieve this:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>import java.io.FileInputStream;
  import java.io.InputStream;
  
  import org.apache.http.HttpEntity;
  import org.apache.http.auth.AuthScope;
  import org.apache.http.auth.UsernamePasswordCredentials;
  import org.apache.http.client.CredentialsProvider;
  import org.apache.http.client.methods.CloseableHttpResponse;
  import org.apache.http.client.methods.HttpPut;
  import org.apache.http.entity.ContentType;
  import org.apache.http.entity.mime.MultipartEntityBuilder;
  import org.apache.http.impl.client.BasicCredentialsProvider;
  import org.apache.http.impl.client.CloseableHttpClient;
  import org.apache.http.impl.client.HttpClients;
  import org.apache.http.util.EntityUtils;
  
  public class QuickStart {
  
      public static void main(String[] args) throws Exception {
       String file="data.zip";       
          
          CredentialsProvider credsProvider = new BasicCredentialsProvider();
          credsProvider.setCredentials(
                  AuthScope.ANY,
                  new UsernamePasswordCredentials("admin", "geoserver"));
          
          CloseableHttpClient httpclient = HttpClients.custom()
                  .setDefaultCredentialsProvider(credsProvider)
                  .build();
          
          try {
              HttpPut httpPut = new HttpPut("http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/Murrindindi/file.shp");
              File file2 = new File("data.zip");                
              InputStream inputStream = new FileInputStream(file);          
              
  
              HttpEntity reqEntity = MultipartEntityBuilder.create()    
                      .addPart("file", new FileBody(file2, ContentType.DEFAULT_BINARY))                  
                      .addBinaryBody("upstream", inputStream, ContentType.create("application/zip"), "data.zip")
                      .build();
  
              httpPut.setEntity(reqEntity);
  
              System.out.println("executing request " + httpPost.getRequestLine());
              CloseableHttpResponse response = httpclient.execute(httpPut );
              try {
                  System.out.println("----------------------------------------");
                  System.out.println(response.getStatusLine());
                  HttpEntity resEntity = response.getEntity();
                  if (resEntity != null) {
                      System.out.println("Response content length: " + resEntity.getContentLength());
                  }
                  EntityUtils.consume(resEntity);
              } finally {
                  response.close();
              }
          } finally {
              httpclient.close();
          }
      }
  
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>When I run this code I get the following error:</p>
  
  <pre><code>INFO: I/O exception (java.net.SocketException) caught when processing request to {}-&gt;http://172.16.17.86:9090: 
  Connection reset by peer: socket write error
  Exception in thread "main" org.apache.http.client.ClientProtocolException
  </code></pre>
  
  <p>Any idea how this can be resolved? I have tested a POST with simple authentication and that works. However, there is an issue when I try to upload the zip file.</p>
  
  <p>The curl output is as follows:</p>
  
  <pre><code>curl -v -u admin:geoserver -XPUT -H "Content-type: application/zip" --data-binary @Murrindindi_OvalCorrected.zip http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/Murrindindi/file.shp
  
  * Trying 172.16.17.86...
  * TCP_NODELAY set
  * Connected to 172.16.17.86 (172.16.17.86) port 9090 (#0)
  * Server auth using Basic with user 'shapeuploader'
  &gt; PUT /geoserver/rest/workspaces/IDIRA6/datastores/Murrindindi/file.shp HTTP/1.1
  &gt; Host: 172.16.17.86:9090
  &gt; Authorization: Basic c2hhcGV1cGxvYWRlcjo2OHJpOURwazdJR001bEo=
  &gt; User-Agent: curl/7.63.0
  &gt; Accept: */*
  &gt; Content-type: application/zip
  &gt; Content-Length: 7022252
  &gt; Expect: 100-continue
  &gt;
  &lt; HTTP/1.1 100
  * We are completely uploaded and fine
  &lt; HTTP/1.1 201
  &lt; X-Frame-Options: SAMEORIGIN
  &lt; Content-Length: 0
  &lt; Date: Sat, 23 Mar 2019 23:04:27 GMT
  * Connection #0 to host 172.16.17.86 left intact
  </code></pre>