Page 1 of 1

RestDocumentClient.create() throws ResponseProcessingException while calling Rest from Java to create a document on DMS

Posted: Wed Jun 06, 2018 7:50 am
by vickyhukum
Hi,

I am trying to call LogicalDOC rest api to create document on DMS. I am invoking rest from java using RestDocumentClient.

When using RestDocumentClient.create(), it is throwing ResponseProcessingException because of which I get null object in return. I need to get document id from wsdocument object.

Anyone has any idea? I am using logical doc 7.6.4.

Here is my sample Code:
===========================================
RestDocumentClient restClient = new RestDocumentClient("http://localhost:8085/services/rest" + "/document",
"admin", "admin");

File file = new File("D:\\Vivek\\database_t2.properties");
WSDocument wsdocument = new WSDocument();
long docid = 5537792;
wsdocument.setFolderId(docid);
wsdocument.setFileName(file.getName());
WSDocument createdDoc = null;
try {
createdDoc = restClient.create(wsdocument, file);
System.out.println("Document ID is : >>" + createdDoc.getId());
} catch (ResponseProcessingException e) {
LOGGER.info("Letter ["+file.getName()+"] uploaded in DMS");
} catch (Exception e) {
LOGGER.error("Error occurred while uploading file [" + file.getName() + "] to DMS.");
}

==================================================

Re: RestDocumentClient.create() throws ResponseProcessingException while calling Rest from Java to create a document on

Posted: Wed Jun 13, 2018 2:56 pm
by agaspa
Try following this procedure

Code: Select all

	public static void main(String[] args) throws Exception {

		/**
		 * Performs the creation of a new document using the REST API (LD 8.0.x).
		 * The special feature of the REST API upload method allows the upload of large files
		 */
		
		//String base = "http://eva00:9080/services/rest";
		String base = "http://localhost:8080/services/rest";
		
		String username = "admin";
		String password = "admin";

		RestDocumentClient restClient = new RestDocumentClient(base + "/document", username, password);

			File file = new File("C:/tmp/InvoiceProcessing01-workflow.png");
			if (!file.exists()) {
				throw new Exception("upload File not found!");
			}
			
			// get the filesize in order to check
			long fsize = file.length();
			System.out.println("FileSize of the source file: " +fsize);								

			long folderID = 4L; // Default workspace folder
			
			WSDocument wsdocument = new WSDocument();
			wsdocument.setFolderId(folderID);
			wsdocument.setFileName(file.getName());
			
			WSDocument createdDoc = restClient.create(wsdocument, file);
										
			System.out.println("Operation completed");
			System.out.println("Document created with ID: " + createdDoc.getId());
			
			// Checks the filesize after the upload operation [OPTIONAL]
			System.out.println("FileSize of the created doc: " +createdDoc.getFileSize());
	}
See also the new examples for LogicalDOC 8.0 (they should also work for LD 7.7.x)
https://sourceforge.net/projects/logica ... p/download

Re: RestDocumentClient.create() throws ResponseProcessingException while calling Rest from Java to create a document on

Posted: Wed Jun 13, 2018 2:57 pm
by agaspa
One of the more important thing is to check that the folderId exist.
Because the system will try to create the new document in that folder and if the folder actually does not exists you will get an error