1

Ich versuche, dies zu replizieren, the copy sentence from openstack swift v1 (das funktioniert gut):HttpURLConnection verbunden Bereits

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" 

So:

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()); 
    } 
} 

Und ich halte java.lang.IllegalStateException: Already connected Ausnahme auf verschiedenen Linien jedes Mal bekommen. Ich habe bereits die anderen Lösungen ausprobiert, die ich gefunden habe (wie das Entfernen der setDoInput), aber nichts scheint zu funktionieren. Hier

ist der Stack-Trace

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) 
+0

Bitte legen Sie einen Stack-Trace bereit. Warum schickst du nichts? – EJP

+0

@EJP Ich habe die Stack-Trace hinzugefügt. Ich sende nichts, weil ich eine Kopie eines Objekts erstellen möchte, das sich bereits im Container befindet. – moondaisy

+0

Sie sollten versuchen, den Eingabestream der Verbindung zu schließen. Normalerweise müssen Sie die Inhaltslänge nicht festlegen. – EJP

Antwort

1

ich die Lösung für dieses Problem fand heraus, war das, was @Sharcoux posted here, die erklärt, warum manchmal wäre es gut funktionieren.

Um dies während des Debuggens auf NetBeans zu lösen, müssen Sie alle Ausdrücke entfernen, die conn verwenden (wie conn.setDoOutPut() usw.).

Verwandte Themen