Guvnor为了创建模型和规则资产而drools 5.5 rest api

时间:2015-07-17 09:46:16

标签: drools-guvnor guvnor

我正试图通过rest api在guvnor中创建一个资产。但是资产在guvnor中的其他资产下被创建为txt。如何使其成为规则资产或模型资产。下面是我的代码

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();

我的xml文件是

<?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>

1 个答案:

答案 0 :(得分:0)

根据https://simplesassim.wordpress.com/tag/drools-guvnor-rest-api/,您可能还需要将文件内容添加为“二进制”参数。

multipart.bodyPart(new FormDataBodyPart("asset",file,MediaType.APPLICATION_XML_TYPE));
multipart.bodyPart(new FormDataBodyPart("binary",file)); // Add this line

我希望上述变化有所帮助。