public DesignDTO uploadDesign(Svg svg)
throws Exception {
Object obj = jaxbContext.createUnmarshaller()
.unmarshal(this.getClass().getResourceAsStream("/design.xml"));
// create design data using xml
HttpCallCommand createDesignCommand =
commandFactory.createJaxbHttpCallCommand(designUrl, HttpMethod.POST, null);
createDesignCommand.setInput(obj);
createDesignCommand.setApiKeyProtected(true);
createDesignCommand.execute();
if (createDesignCommand.getStatus() >= 400) {
throw new Exception("Could not create design xml!");
}
// get created design xml
HttpCallCommand getDesignCommand =
commandFactory.createJaxbHttpCallCommand(createDesignCommand.getLocation(), HttpMethod.GET, null);
getDesignCommand.execute();
if (createDesignCommand.getStatus() >= 400) {
throw new Exception("Could not retrieve design xml from " + createDesignCommand.getLocation() + "!");
}
DesignDTO design = (DesignDTO) ((JAXBElement) getDesignCommand.getOutput()).getValue();
// determine upload location
String uploadUrl = design.getResources().getResource().get(0).getHref();
uploadUrl = uploadUrl.replace("3128", "2302");
// upload image
HttpCallCommand uploadDesignCommand =
commandFactory.createSvgUploadCommand(uploadUrl, HttpMethod.PUT, null);
uploadDesignCommand.setInput(svg);
uploadDesignCommand.setApiKeyProtected(true);
uploadDesignCommand.execute();
if (uploadDesignCommand.getStatus() >= 400) {
log.error(uploadDesignCommand.getErrorMessage());
throw new Exception("Status above 400 expected but status was " + uploadDesignCommand.getStatus() + "!");
}
return design;
}