Summarizing files with GroupDocs.Rewriter SDK
Leave feedback
Learn more
Although you can directly call the GroupDocs.Rewriter Cloud REST API to send file and fetch the result, there is a much easier way to implement required functionality in your applications. We provide software development kits (SDKs) for all popular programming languages. They wrap up all routine operations such as establishing connections, sending API requests, and parsing responses into a few simple methods. It makes interaction with GroupDocs.Rewriter Cloud services much easier, allowing you to focus on business logic rather than technical details.
packagecom.groupdocs;// Import classes:
importcom.groupdocs.model.*;importorg.openapitools.client.api.SummarizeApi;importorg.openapitools.client.api.FileApi;importjava.io.File;publicclassDemo{publicstaticvoidmain(String[]args){// Get Client Id and Client Secret from https://dashboard.groupdocs.cloud
StringbasePath="https://api.groupdocs.cloud/v2.0/rewriter";StringcliendId="YOUR_CLIENT_ID";StringclientSecret="YOUR_CLIENT_SECRET";ApiClientdefaultClient=newApiClient(basePath,cliendId,clientSecret,null);// Upload file
FileApifileApi=newFileApi(defaultClient);StringfileName="FILE_PATH";FilefileToUpload=newFile(fileName);Stringfile_url=null;try{Stringfile_url=fileApi.fileUploadPost("FILE_FORMAT",fileToUpload);}catch(ApiExceptione){System.err.println("Exception when calling FileApi#fileUploadPost");System.err.println("Status code: "+e.getCode());System.err.println("Reason: "+e.getResponseBody());System.err.println("Response headers: "+e.getResponseHeaders());e.printStackTrace();}// Create instance of the SummarizeApi if the file was uploaded successfully
if(file_url!=null){SummarizeApiapiInstance=newSummarizeApi(defaultClient);SummarizationFileRequestfileRequest=newSummarizationFileRequest();fileRequest.setLanguage("en");fileRequest.setFormat(SummarizationSupportedFormats.DOCX);fileRequest.setOutputFormat(SupportedConversionsFormats.DOCX);fileRequest.setSavingMode(FileSavingMode.FILES);fileRequest.setUrl(file_url);fileRequest.setOrigin("");try{StatusResponseresponse=apiInstance.summarizeDocumentPost(fileRequest);Stringresponse_id=response.getId();if(!response.getStatus().toString().equals("BadRequest")){while(true){SummarizationFileResponsesummarizeResponse=apiInstance.summarizeDocumentRequestIdGet(response_id);if(summarizeResponse.getStatus().toString().equals("OK")){System.out.println(summarizeResponse);break;}try{Thread.sleep(2000);}catch(InterruptedExceptione){e.printStackTrace();}}}}catch(ApiExceptione){System.err.println("Exception when calling SummarizeApi#summarizeDocumentPost");System.err.println("Status code: "+e.getCode());System.err.println("Reason: "+e.getResponseBody());System.err.println("Response headers: "+e.getResponseHeaders());e.printStackTrace();}}}}