HttpHeaders httpHeaders = setHeader(MediaType.APPLICATION_JSON.toString(),MediaType.MULTIPART_FORM_DATA.toString(), “admin”, “test”);
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add(“file”, mpFile);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, httpHeaders);
ResponseEntity response = new RestTemplate().postForEntity(serverUrl, requestEntity, String.class);
<>
getting the below error
“status”: 500,
“error”: “Internal Server Error”,
“message”: "Type definition error: [simple type, class java.util.logging.ErrorManager]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class java.util.logging.ErrorManager and no properties discovered to create BeanSerializer
(to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
Not sure what your setHeader(String, String, String, String) method accomplishes. I’m hoping it takes that APPLICATION_JSON media type and applies it to the “Accept” header, but it’s hard to know without the source code.
This works for me (multi-tenant variant):
private void deployWorkflow(final String tenantId, final String workflowFileName) throws Exception {
LOG.debug("Deploying the process [{}] for tenant [{}]", workflowFileName, tenantId);
// Read the process file and replace the tenant ID token
final Path path = Path.of(ClassLoader.getSystemResource(workflowFileName).toURI());
final String content = Files.readString(path);
final ByteArrayResource contentResource = new ByteArrayResource(content.replace("{{tenantId}}", tenantId)
.getBytes(StandardCharsets.UTF_8)) {
@Override
public String getFilename() {
return workflowFileName;
}
};
contentResource.getFilename();
// Post the workflow to the workflow engine
final String workflowUrl = properties.getWorkflowEngine().getUrl() + "process-api/repository/deployments";
final MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("file", contentResource);
body.add("tenantId", tenantId);
final RequestEntity<MultiValueMap<String, Object>> request = RequestEntity
.post(new URI(workflowUrl))
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.MULTIPART_FORM_DATA)
.body(body);
final ResponseEntity<Map<String, Object>> response = restTemplate.exchange(request,
new ParameterizedTypeReference<>() {});
if (response.getStatusCode() == HttpStatus.CREATED) {
LOG.debug("Created workflow deployment [{}]", response.getBody());
} else {
LOG.error("Error creating workflow deployment [{}]", response.getStatusCode());
}
}
Since I’m using a ByteArrayResource, I had to override getFilename() in order to add the filename to the content disposition: