Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
abhijeet_mukkawar
Active Contributor
0 Kudos

Most of the organizations have SharePoint as content / document management and intranet platform. Hence, the master data governance processes enabled with SAP must be able to post the data on SharePoint for wider distribution.

For the landscape with PI and FTP (or similar tools), it’s a cake-walk and can easily be implemented without much hassle. In few cases, where we cannot go with above method, COPY web service provided by SharePoint can be consumed in SAP system to satisfy the need. However, when there are some challenges owing the stringent and only NTLM authentication asked by SharePoint and you don’t expect any SharePoint developer’s support, the requirement is bit tricky.

We have struggled a bit to get past the similar scenario where NW BPM governed financial master data is required to post on SharePoint for wider distribution . We have our business process running on CE 7.2 SP5. We have tried few options and struck a dead end as;

1.      PI: Cannot be used as FTP is forbidden and installing similar software will cause additional costs.

2.      Copy Web Service: Failed to configure NTLM authentication in WS calls.

After going through the various authentication scenarios in SAP, we got to know that SAP doesn’t support NTLM authentication (please correct me if this is not the case). Also we didn’t have any support from SharePoint team; hence, the going was bit tougher.

Finally, we have completed the requirement by using Apache HTTP APIs. So, detailing the same in case anyone is struggling with the same scenario.

Scenario:

For the purpose of this document, we will go through a simple scenario that will read file from designated folder of your CE file system and upload it on specified SharePoint library. SharePoint in the scenario uses NTLM authentication scheme.

The code snippet posts the file in .xls format. However, this can be modified to deal with any file type. The method call for this scenario accepts a single parameter as a path on CE server and will return a simple string message which is response of Http reqeust to SharePoint server.

Prerequisite:

Document library on SharePoint where you will post the file must be created. This will be accessed from you code to save the file. If SSO is configured for SharePoint intranet site, a service user account must be created for the scenario.

You will need below JARs for this scenario:

Commons-codes-1.6.jar

httpClient-4.3.1.jar

httpclient-cache-4.3.1.jar

httpcore-4.3.jar

httpmime-4.3.1.jar

fluent-hc-4.3.1.jar

You can get them from : http://hc.apache.org/downloads.cgi

Implementation:

1.      Create external library Dc with above JARs

2.      Create a JAVA web module project and define dependency on library DC created above

3.      Create a Java class and a method which will read file from CE and post to SharePoint. The method accepts a parameter – filePath - which is a file location on CE server,

4.      Paste below code in the method which will read file entity from CE and post it on specified location on SharePoint.

public String httpCall(String filePath){

                               

      String strReturn =  "" ;

         

            // CloseableHttpClient provides HTTPClient interface for executing HTTP methods.

            // Execution of HTTP method involves one or more HTTP requests/response exchanges

            // which is handled by HTTP Client interface. We provide the request object which

            // will be executed by HttpClient to transmit request to target server and gets the response back.

         

            CloseableHttpClient httpclient = HttpClients.createDefault();

            CloseableHttpResponse response1 = null;

            CloseableHttpResponse response2 = null;

            URI uri = null;

            File file = null;

            try{

               

                  // Credentials providers are intended to maintain a set of user credentials

                  // and to be able to produce user credentials for a particular authentication scope.

                  // When registering credentials with the credentials provider one can provide a

                  // wild card (any host, any port, any realm, any scheme) instead of a concrete attribute value.

               

                  CredentialsProvider credsProvider = new BasicCredentialsProvider();

                  credsProvider.setCredentials(AuthScope.ANY,

                              new NTCredentials(<userID>, <password>, <workstation>, <domain>));

               

                  HttpHost target = new HttpHost(<SharePoint Host name>, <port>);

                  // Creates context for stateful connection with SharePoint which is used to execute

                  // logically related requests

                  HttpClientContext context = HttpClientContext.create();

                  context.setCredentialsProvider(credsProvider);             

                                 

                  // Creates URI which is a SharePoint path to post the document to

                  uri = new URIBuilder()

              .setScheme("http")

              .setHost(<SharePoint Host name>)

              .setPath(<Library path>)

              .build();

                  // Creates a file object for the file from CE system and fetch the name if you wish to give

                  // same name to the file when posted on SharePoint

                  file = new File(filePath);

                  String fileName = filePath.substring(filePath.lastIndexOf("/"),filePath.lastIndexOf("."));

               

                  FileEntity entity = new FileEntity(file);

                  entity.setChunked(true);

               

                  // In the below line of code the filename specifies the name of the

                  // file to be written on SharePoint. The PUT method requests that the

                  // enclosed entity be stored under the supplied Request-URI. If the Request-URI

                  // refers to an already existing resource, the enclosed entity SHOULD be

                  // considered as a modified version of the one residing on the origin server.

               

                  HttpPut httpput = new HttpPut(uri+fileName+".xls");

                  // Enclose the request entity with the method

                  httpput.setEntity(entity);

               

                  try {

                        // Execute the method and gets the response entity back

                        response2 = httpclient.execute(target, httpput, context);

                        HttpEntity entity2 = response2.getEntity();

                        // This is a simple string attribute used to read the status message from HTTP execution

                        strReturn = strReturn+" "+response2.getStatusLine();

                  } catch(Exception e){

                        strReturn = strReturn+" "+"Inner try , expensive call: "+e.getLocalizedMessage();

                        e.printStackTrace();

                  }finally {

                        response2.close();  

                  }

            }catch(Exception e){

                  strReturn = strReturn+" "+"Outer try :"+e.getLocalizedMessage();

                  e.printStackTrace();

            }

            return strReturn ;

      }

5.      The return string will get the success/failure response of the HTTP Method. So, for successful creation of the file on SharePoint, it will return 201 CREATED.

6.      For testing purpose, I have created a wrapper web service using EJB that can be executed from WS Navigator by supplying the file path on CE server. This will retrieve response in a string message.

7.      A file specified by the path in above WS call can be seen uploaded on SharePoint as designated library structure.

Though we will rarely need this method for SharePoint connectivity, this provides a way when landscape is surrounded by stringent restrictions on technology usage.

Labels in this area