我正在尝试连接到 activiti-rest 服务。我想用服务部署一个 bpmn 文件,所以我使用 jersey 创建了一个客户端,但是在我运行类之后,从服务接收到 500 消息。
package org.cacib.beans;
import java.io.File;
import java.net.URI;
import javax.rmi.CORBA.Stub;
import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
import com.sun.jersey.api.representation.Form;
import com.sun.jersey.multipart.BodyPart;
import com.sun.jersey.multipart.FormDataMultiPart;
import com.sun.jersey.multipart.MultiPart;
import com.sun.jersey.multipart.file.FileDataBodyPart;
public class ActivitiTest {
/**
* @param args
*/
/**
* @param args
*/
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
client.addFilter(new HTTPBasicAuthFilter("kermit", "kermit"));
WebResource service = client.resource(getBaseURI());
JSONObject json = new JSONObject();
Cookie c = new Cookie("succes","true");
FormDataMultiPart multiPart = new FormDataMultiPart();
File f = new File("C:/workspace-indigo/apurement/src/main/resources/diagrams/apurement.bpmn");
multiPart.bodyPart( new FileDataBodyPart("file", f,MediaType.APPLICATION_OCTET_STREAM_TYPE));
ClientResponse user = service.path("deployment").accept(MediaType.MULTIPART_FORM_DATA).type(MediaType.MULTIPART_FORM_DATA).header("Content-type",MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class,multiPart);
try {
System.out.println(user);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static URI getBaseURI() {
return UriBuilder.fromUri("http://192.168.1.6:8080/activiti-rest/service/").build();
}
}