Wednesday, January 14, 2015

How to connect Java Sharepoint Integration and rest api 2010 and 2013

Authenticating SharePoint 2010 and 2013 using Rest API.

SharePoint supports various Authentication mechanism including the Federated Login, legacy authentication model like Kerbos, Cliams based.
If someone who worked on integrating the third party Apps using Oauth 2.0 or Oauth 1.0, definately they are not going to get impressed with the SharePoint Authentication , including me. I have integrated my apps with public storages like Google Drive, Dropbox, Box .,including hosted storages like ECM's especially Alfresco, Documentum 7.1 , CMIS.

Lets get into the SharePoint 2010 & 2013 integrating with Java Client. We will take example with PasswordAuthenticaion from java.net package and connect the sharepoint url by passing the UserName and Password. This is like a BasicAuthentication.


public class SharepointAuthenticator extends Authenticator{
   
private Properties properties;
public SharepointAuthenticator(Properties props){
properties = props;
}
    public PasswordAuthentication getPasswordAuthentication () {
    return new java.net.PasswordAuthentication (properties.getProperty("username"),properties.getProperty("password").toCharArray());
}
}

Thats it. its Simple BasicAuthentication.
Next step, how to connect to any of the Sharepoint Rest Api. In our example, we will take SharePoint List and SharePoint delete functions.




Tuesday, January 13, 2015

Sardine Webdav configuration issues.

Java Sardine WebDav Connecting Issue


Here is the Most frequent problem while setting up the Sardine  (GitHub)Java WebDav connecting issues.

We Solved below issue by using configuring the correct version of httpclient with the combination of Sardine version. This is because of improper ConnectionKeepAliveStrategy loading while making http connection 

httpclient-4.3.1.jar

Maven Entry:
version=4.3.1
groupId=org.apache.httpcomponents

artifactId=httpclient

Sometimes ,JDK 7.41x above will help us in resolving the issue. I took more than 3 hours to get the bottom line issue. 
All the best.

Issue Type 1:
java.lang.NoSuchMethodError: org.apache.http.impl.client.AbstractHttpClient.execute(Lorg/apache/http/client/methods/HttpUriRequest;Lorg/apache/http/protocol/HttpContext;)Lorg/apache/http/client/methods/CloseableHttpResponse;
at com.github.sardine.impl.SardineImpl.execute(SardineImpl.java:857)
at com.github.sardine.impl.SardineImpl.get(SardineImpl.java:640)
at com.github.sardine.impl.SardineImpl.get(SardineImpl.java:627)
at com.github.sardine.impl.SardineImpl.get(SardineImpl.java:133)
at com.company.connectors.webdav.WebdavConnector.downloadFile(WebdavConnector.java:153)
at com.company.cloud.connectors.WebdavCloudConnector.getFileContentStream(WebdavCloudConnector.java:745)
at com.company.cloud.rest.FileFolderMgmtService.downloadContent(FileFolderMgmtService.java:1173)
at com.company.cloud.rest.FileFolderMgmtWebdavTest.testDownLoadFile(FileFolderMgmtWebdavTest.java:317)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

ConnectionKeepAliveStrategy  httpclient-4.3.1.jar

version=4.3.1
groupId=org.apache.httpcomponents
artifactId=httpclient


Issue Type 2:
java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:56)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterFactory.java:46)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:72)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:84)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientConnectionFactory.java:59)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingHttpClientConnectionManager.java:487)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:147)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:136)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:112)
at com.github.sardine.impl.SardineImpl.createDefaultConnectionManager(SardineImpl.java:937)
at com.github.sardine.impl.SardineImpl.configure(SardineImpl.java:875)
at com.github.sardine.impl.SardineImpl.<init>(SardineImpl.java:183)
at com.github.sardine.SardineFactory.begin(SardineFactory.java:44)
at com.github.sardine.SardineFactory.begin(SardineFactory.java:34)
at com.company.connectors.webdav.WebdavConnector.login(WebdavConnector.java:48)
at com.company.cloud.connectors.WebdavCloudConnector.getSession(WebdavCloudConnector.java:82)
at com.company.cloud.connectors.WebdavCloudConnector.getFileContentStream(WebdavCloudConnector.java:744)
at com.company.cloud.rest.FileFolderMgmtService.downloadContent(FileFolderMgmtService.java:1173)
at com.company.cloud.rest.FileFolderMgmtWebdavTest.testDownLoadFile(FileFolderMgmtWebdavTest.java:318)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)