Last active
December 14, 2022 22:54
-
-
Save brunogasparetto/cb5350ee3f28c46f3e487fadd6e8adcc to your computer and use it in GitHub Desktop.
Fluig: enviar um documento do GED para um WS externo como chunked post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fluigUsername = "username"; | |
var fluigPassword = "password"; | |
var fluigEmpresa = 1; | |
var documentId = 0; | |
var documentVersion = "1000"; | |
var documentDescription = "arquivo.pdf"; | |
var mimeType = "application/pdf"; | |
var ECMDocumentServiceProvider = ServiceManager.getServiceInstance("ECMDocumentService"); | |
var ECMDocumentServiceLocator = ECMDocumentServiceProvider.instantiate("com.totvs.technology.ecm.dm.ws.ECMDocumentServiceService"); | |
var documentService = ECMDocumentServiceLocator.getDocumentServicePort(); | |
var documentContent = documentService.getDocumentContent( | |
fluigUsername, | |
fluigPassword, | |
fluigEmpresa, | |
documentId, | |
getValue("WKUser"), | |
documentVersion, | |
documentDescription | |
); | |
var reqEntity = new org.apache.http.entity.InputStreamEntity( | |
java.io.ByteArrayInputStream(documentContent), | |
-1, | |
org.apache.http.entity.ContentType.APPLICATION_OCTET_STREAM | |
); | |
reqEntity.setChunked(true); | |
var client = org.apache.http.impl.client.HttpClients.createDefault(); | |
var url = "http://url.com.br"; | |
var post = new org.apache.http.client.methods.HttpPost(url); | |
post.addHeader("Content-Disposition", "attachment;filename=" + documentDescription); | |
post.addHeader("Content-type", mimeType); | |
post.setEntity(reqEntity); | |
var responseApi = client.execute(post); | |
var responseJson = JSON.parse(org.apache.http.util.EntityUtils.toString(responseAPi.getEntity())); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment