Skip to content

Instantly share code, notes, and snippets.

@brunogasparetto
Last active December 14, 2022 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunogasparetto/cb5350ee3f28c46f3e487fadd6e8adcc to your computer and use it in GitHub Desktop.
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
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