我在尝试使用swift设置对象时遇到异常:
org.jclouds.http.HttpResponseException: Incomplete output stream connecting to PUT http://xxx.xx.xx.xxx:8080/v1/AUTH_2c5c2fbbfe22422496d5ebf6861199f2/myContainer1/ HTTP/1.1
at org.jclouds.http.internal.BaseHttpCommandExecutorService.invoke(BaseHttpCommandExecutorService.java:162)
at org.jclouds.rest.internal.InvokeHttpMethod.invoke(InvokeHttpMethod.java:93)
at org.jclouds.rest.internal.InvokeHttpMethod.apply(InvokeHttpMethod.java:76)
at org.jclouds.rest.internal.InvokeHttpMethod.apply(InvokeHttpMethod.java:47)
at here`org.jclouds.reflect.FunctionalReflection$FunctionalInvocationHandler.handleInvocation(FunctionalReflection.java:117)
at com.google.common.reflect.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:79)
at $Proxy66.put(Unknown Source)
at com.cis.app.Appxkl.JCloudsSwift.uploadObjectFromString(JCloudsSwift.java:194)
at com.cis.app.Appxkl.JCloudsSwift.main(JCloudsSwift.java:51)
Caused by: java.io.IOException: Incomplete output stream
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at org.jclouds.http.internal.JavaUrlHttpCommandExecutorService.invoke(JavaUrlHttpCommandExecutorService.java:112)
at org.jclouds.http.internal.JavaUrlHttpCommandExecutorService.invoke(JavaUrlHttpCommandExecutorService.java:72)
at org.jclouds.http.internal.BaseHttpCommandExecutorService.invoke(BaseHttpCommandExecutorService.java:141)
... 8 more
代码是:
InputStream is = new ByteArrayInputStream(data.getBytes("UTF-8"));
Payload payload = new InputStreamPayload(is);
payload.getContentMetadata().setContentLength((long) 1000);
ObjectApi objectApi = swiftApi.objectApiInRegionForContainer("RegionOne", CONTAINER_NAME);
String str = "strName";
objectApi.put(str, payload);
PLZ任何人都会指导我如何解决这个问题
答案 0 :(得分:2)
您应该提供正确的内容长度而不是虚假的内容,例如,
byte[] input = data.getBytes("UTF-8");
InputStream is = new ByteArrayInputStream(input);
Payload payload = new InputStreamPayload(is);
payload.getContentMetadata().setContentLength(input.length);
您可以使用InputStream
完全跳过ByteArrayPayload
,byte[] input = data.getBytes("UTF-8");
Payload payload = new ByteArrayPayload(input);
自动设置长度,并提供可重复的有效负载,可以处理网络超时和其他故障:
{{1}}