Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
77 views
in Technique[技术] by (71.8m points)

java - Use SharePoint as a kind of CMS using Spring Boot

I am using Spring Boot for storing files (of basically as many format as possible - but think along the lines of images, documents) in SharePoint for my application, which is deployed in SAP's Cloud Foundry. I have pretty much followed the steps mentioned in this post's answer (and copied all four files from there) and I got a github repo which pretty much implements the same thing. I've followed them but something is not working for me. (Please refer to the StackOverflow link for further reference of what I'm talking about)

The order of method calls in SharePointServiceCached.java is parseExecutionDateTime() -> receiveSecurityToken() -> getSignInCookies(securityToken) -> getFormDigestValue(cookies) I receive the security token (as I checked from my logs) but this is the error message I'm getting:

Document upload failed!org.springframework.web.client.HttpClientErrorException$Forbidden: 403 Forbidden: [403 FORBIDDEN]

Things I have tried for this:

  1. Added SSL part (see code at end of lists) to the request which only seemed to made it worse.
  2. Added user agent to headers which made no difference.
  3. Changed the endpoint domain from https://protected1.sharepoint.com/sites/protected2 to https://protected1.sharepoint.com/ which again, somehow made it worse. (Obviously, protected1 and protected2 are changed names)
  4. Made myself (the person whose credentials I'm passing) the owner of the site with all privileges.
  5. I checked the logs, the credentials are getting passed correctly.
    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder builder) 
    {
        CloseableHttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier())
                .build();
        HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
        requestFactory.setHttpClient(httpClient);
        RestTemplate rest = new RestTemplate(requestFactory);
        builder.configure(rest);
        return builder.build();
    }

Also, previously I was using a CMS for the same thing which returned a document ID associated with the uploaded file. I have enabled the option for document IDs in SharePoint and want to use it similarly, i.e. upload a file -> get a document ID and store it -> use that document ID to fetch the file when required. How can I do this?

Thank you in advance.

question from:https://stackoverflow.com/questions/66052843/use-sharepoint-as-a-kind-of-cms-using-spring-boot

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Got it. I just had to send the path where I want to store my files. https://protected1.sharepoint.com/sites/protected2/_api/web/GetFolderByServerRelativeUrl(%27Shared%20Documents/Another%20Folder%27)/files/add(url=%27" + documentID + "%27,overwrite=false)

I am now generating the documentID randomly.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...