OfficeDev / Office-365-SDK-for-Java

Office 365 client for Java
Other
48 stars 39 forks source link

DocLibClient error on call of createFolder method HTTP Error 411 --. The request must be chunked or have a content length #17

Open adelinor opened 7 years ago

adelinor commented 7 years ago

Hi,

Using:

<dependency>
    <groupId>com.microsoft.services</groupId>
    <artifactId>sharepoint-services-java</artifactId>
    <version>1.0.0</version>
</dependency>

to create a folder:

DocLibClient client = newClient(); // authenticate and create client;
ListenableFuture<FileSystemItem> handle = client.createFolder("sample", "Filestore");

Fails with the following error:

java.util.concurrent.ExecutionException: java.lang.Exception: Invalid status code 411: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Length Required</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Length Required</h2>
<hr><p>HTTP Error 411. The request must be chunked or have a content length.</p>
</BODY></HTML>

    at com.google.common.util.concurrent.AbstractFuture$Sync.getValue(AbstractFuture.java:299)
    at com.google.common.util.concurrent.AbstractFuture$Sync.get(AbstractFuture.java:286)
    at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:116)
    at mytest.samples.sharepoint.CreateFolderTest.testCreateFolder(CreateFolderTest.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.Exception: Invalid status code 411: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Length Required</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Length Required</h2>
<hr><p>HTTP Error 411. The request must be chunked or have a content length.</p>
</BODY></HTML>

    at com.microsoft.services.sharepoint.SharePointClient$1.onSuccess(SharePointClient.java:105)
    at com.microsoft.services.sharepoint.SharePointClient$1.onSuccess(SharePointClient.java:86)
    at com.google.common.util.concurrent.Futures$6.run(Futures.java:1319)
    at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:457)
    at com.google.common.util.concurrent.ExecutionList.executeListener(ExecutionList.java:156)
    at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:145)
    at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:185)
    at com.google.common.util.concurrent.SettableFuture.set(SettableFuture.java:53)
    at com.microsoft.services.sharepoint.http.NetworkRunnable.run(NetworkRunnable.java:66)
    at java.lang.Thread.run(Thread.java:745)

The error occurs in the method SharePointClient.getFormDigest(). Logs from sharepoint-services-java library output:

2017-05-10T22:22:36,883 DEBUG mytest.samples.sharepoint.CreateFolderTest - Created DocLibClient
2017-05-10T22:22:36,886 DEBUG mytest.samples.sharepoint.CreateFolderTest - Generate request for getFormDigest
2017-05-10T22:22:36,886 DEBUG mytest.samples.sharepoint.CreateFolderTest - URL: https://mycompany.sharepoint.com/sites/mysite/_api/contextinfo
2017-05-10T22:22:36,886 DEBUG mytest.samples.sharepoint.CreateFolderTest - VERB: POST
2017-05-10T22:22:36,886 DEBUG mytest.samples.sharepoint.CreateFolderTest - Header Authorization: Bearer skipped
2017-05-10T22:22:36,887 DEBUG mytest.samples.sharepoint.CreateFolderTest - Header X-ClientService-ClientTag: SDK-JAVA
2017-05-10T22:22:36,887 DEBUG mytest.samples.sharepoint.CreateFolderTest - Header Accept: application/json;odata=verbose
2017-05-10T22:22:36,887 DEBUG mytest.samples.sharepoint.CreateFolderTest - Header Content-Length: 0

Could this be addressed, please?

adelinor commented 7 years ago

I could fix the issue by overriding the method SharePointClient.getFormDigest() to add a dummy content so that the request is not empty:

request.setUrl(getSiteUrl() + "_api/contextinfo");
request.setContent("-"); //Adding this dummy content works around the issue
prepareRequest(request);