1

我正在尝试通过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>
4

1 回答 1

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

我希望上述更改有所帮助。

于 2015-08-20T18:38:16.510 回答