title: HttpURLConnection Already connected
body: <p>I'm trying to replicate this, <a href="http://developer.openstack.org/api-ref-objectstorage-v1.html#copyObject" rel="noreferrer">the copy sentence from openstack swift v1</a> (which works just fine):</p>
  
  <pre><code>curl -i $publicURL/GXPrueba/StorageAPI/PruebaStorageCopy.png -X PUT -H "X-Auth-Token:  $token" -H "X-Copy-From: /GXPrueba/StorageAPI/PruebaStorage.png" -H "Content-Length: 0"
  </code></pre>
  
  <p>Like this:</p>
  
  <pre><code>private void copy(String originContainer, String origin, String destinationContainer, String destination) {
      try {
          URL url = new URL(storageUrl + DELIMITER + destinationContainer + DELIMITER + destination);
          HttpURLConnection conn = (HttpURLConnection) url.openConnection();
          conn.setDoInput(true);
          conn.setDoOutput(true);
          conn.setRequestMethod("PUT");
          conn.setRequestProperty("X-Auth-Token", authToken);
          conn.setRequestProperty("X-Copy-From", DELIMITER + originContainer + DELIMITER + origin);
          conn.setRequestProperty("Content-Length", "0");
  
          if (conn.getResponseCode() != HttpURLConnection.HTTP_CREATED) {
              System.err.println("Error while copying the object: " + conn.getResponseCode());
          }
          conn.disconnect();
  
      } catch (MalformedURLException e) {
          System.err.println("Error while copying the object: " + e.getMessage());
      } catch (IOException e) {
          System.err.println("Error while copying the object: " + e.getMessage());
      }
  }
  </code></pre>
  
  <p>And I keep getting <code>java.lang.IllegalStateException: Already connected</code> exception at different lines everytime.
  I already tried the other solutions I found (like removing the <code>setDoInput</code>) but nothing seems to work.</p>
  
  <p>Here is the stack trace</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalStateException: Already connected
      at java.net.URLConnection.setDoOutput(URLConnection.java:900)
      at sun.net.www.protocol.https.HttpsURLConnectionImpl.setDoOutput(HttpsURLConnectionImpl.java:455)
      at javaapplication3.ExternalProviderBluemix.copy(ExternalProviderBluemix.java:212)
      at javaapplication3.ExternalProviderBluemix.copy(ExternalProviderBluemix.java:202)
      at javaapplication3.JavaApplication3.main(JavaApplication3.java:39)
  C:\Users\lsarni\AppData\Local\NetBeans\Cache\8.1\executor-snippets\debug.xml:83: Java returned: 1
  BUILD FAILED (total time: 24 seconds)
  </code></pre>