【问题标题】:ServiceNow attachments in CamelCamel 中的 ServiceNow 附件
【发布时间】:2018-06-28 19:17:27
【问题描述】:

如何从骆驼连接器下载或上传附件到servicenow。该项目是在 maven 中使用 camel-servicenow (v2.21.0.fuse-000077-redhat-1) 设置的。工单的创建、检索和更新工作正常,但是无法使用附件资源下载任何附件。

【问题讨论】:

标签: apache-camel jbossfuse servicenow


【解决方案1】:

下载:

url = "https4://" 
        +  instance
        + ".service-now.com/api/now/v1/attachment?sysparm_query="
        + "table_name=" 
        + table 
        + "%5Etable_sys_id=" 
        + sysId
        + "&authenticationPreemptive=true&authUsername=" 
        + username 
        + "&authPassword="
        + password
        + "&authMethod=Basic";

在路由定义中:

from("direct:servicenowAttachmentDownload").setHeader(Exchange.HTTP_METHOD, constant("GET")).recipientList().simple("${header.url}")

上传:

url = "https4://"
        + instance
        + ".service-now.com/api/now/attachment/file?table_name="
        + table
        + "&table_sys_id="
        + sysId
        + "&file_name="
        + attachmentName
        + "&authenticationPreemptive=true&authUsername="
        + username
        + "&authPassword="
        + password
        + "&authMethod=Basic";

在路由定义中:

from("direct:servicenowAttachmentUpload").process(new Processor() {
        public void process(Exchange exchange) throws Exception {
            MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
            multipartEntityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
            multipartEntityBuilder.setContentType(ContentType.MULTIPART_FORM_DATA);

            String filename = (String) exchange.getIn().getHeader(Exchange.FILE_NAME);

            String filePath = (String) exchange.getIn().getHeader("filePath");
            String attachmentName = (String) exchange.getIn().getHeader("attachmentName");

            File file = new File(filePath);
            multipartEntityBuilder.addPart("upload",
                    new FileBody(file, ContentType.MULTIPART_FORM_DATA, attachmentName));
            exchange.getIn().setBody(multipartEntityBuilder.build());
        }
    }).removeHeaders("CamelHttp*").setHeader(Exchange.HTTP_METHOD, constant("POST")).recipientList()
            .simple("${header.url}")

【讨论】:

    猜你喜欢
    • 2014-12-05
    • 2017-08-09
    • 2017-11-13
    • 1970-01-01
    • 1970-01-01
    • 2020-05-28
    • 1970-01-01
    • 2011-11-06
    • 1970-01-01
    相关资源
    最近更新 更多