Загрузить:
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}")