I am trying to create an asset in guvnor through rest api. but the asset is getting created as txt under other assets in guvnor.How can i make it rule asset or model asset. below is my code
Client client = ClientBuilder.newClient();
client.register(HttpAuthenticationFeature.basic("admin", "admin"));
client.register(MultiPartFeature.class);
final MultiPart multipart = new FormDataMultiPart();
File file = new File("C:\\assetfile.xml");
multipart.bodyPart(new FormDataBodyPart("asset",file,MediaType.APPLICATION_XML_TYPE));
final Response response = client.target("http://localhost:8080/guvnor-5.5.0.Final-tomcat-6.0/rest/packages/samplePackage/assets")
.request()
.post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE));
System.out.println(response.readEntity(String.class));
client.close();
my xml file is
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<asset>
<author>admin</author>
<description/>
<metadata>
<checkInComment/>
<disabled>false</disabled>
<format>brl<format>
<versionNumber>1</versionNumber>
</metadata>
<sourceLink>
http://localhost:8080/guvnor-5.5.0.Final-tomcat-6.0/rest/packages/samplePackage/assets/location1234/source
</sourceLink>
<title>location1234</title>
</asset>
According to https://simplesassim.wordpress.com/tag/drools-guvnor-rest-api/, it appears that you may also need to add your file content as a "binary" argument.
multipart.bodyPart(new FormDataBodyPart("asset",file,MediaType.APPLICATION_XML_TYPE));
multipart.bodyPart(new FormDataBodyPart("binary",file)); // Add this line
I hope that the above change helps.