我想在JBPM中设置正文表单数据请求。我正在尝试来自邮递员的请求,并且它能正常工作...我已经使用Java完成了一个简单的示例,现在我需要在诸如邮递员这样的正文中发送文件。
如何为内容文件设置正文和键“文件”?
import java.util.Map;
import org.drools.core.process.instance.impl.WorkItemImpl;
import org.jbpm.process.workitem.rest.RESTWorkItemHandler;
import org.kie.api.runtime.process.WorkItem;
import org.kie.api.runtime.process.WorkItemHandler;
import org.kie.api.runtime.process.WorkItemManager;
public class test {
public static void main(String[] args) {
test t=new test();
System.out.println(t.uploadFile("xxx","xxx","xxx","xxx","filebase64"));
}
public String uploadFile(String user, String pwd, String site, String path, String file) {
String result = "Error uploadFile ";
try {
String Headers = "user=" + user + ";pwd=" + pwd + ";site=" + site; // Sending headers
RESTWorkItemHandler handler = new RESTWorkItemHandler();
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url",
"https://mywebsite.com/sharing/api/v1/files?path=" + path); //Sending parameters
workItem.setParameter("Method", "POST");
workItem.setParameter("ContentType", "application/json");
workItem.setParameter(RESTWorkItemHandler.PARAM_HEADERS, Headers);
workItem.setParameter("Body", file); // How send body ? base64?
InterfaceTestWorkItemManager manager = new InterfaceTestWorkItemManager(workItem);
handler.executeWorkItem(workItem, manager);
int responseCode = (Integer) workItem.getResult("Status");
if (responseCode == 200) {
result = (String) workItem.getResult("Result");
} else {
result += "responseCode " + responseCode;
}
} catch (Exception e) {
result += e.getMessage();
}
return result;
}
class InterfaceTestWorkItemManager implements WorkItemManager {
private WorkItem workItem;
TestWorkItemManager(WorkItem workItem) {
this.workItem = workItem;
}
@Override
public void completeWorkItem(long id, Map<String, Object> results) {
((WorkItemImpl)workItem).setResults(results);
}
@Override
public void abortWorkItem(long id) {}
@Override
public void registerWorkItemHandler(String workItemName, WorkItemHandler handler) {}
}
可以原始发送吗?