Skip to content

Instantly share code, notes, and snippets.

@yehara
Created September 28, 2011 03:16
Show Gist options
  • Save yehara/1246901 to your computer and use it in GitHub Desktop.
Save yehara/1246901 to your computer and use it in GitHub Desktop.
Questetra BPM Suite のメッセージ開始イベントを起動するサンプルコードのファイル型データ対応(Java)
package com.questetra;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
public class MessageStartFileClient {
public static void main(String[] args) {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("https://s.questetra.net/00000000/System/Event/MessageStart/start");
Charset charset = Charset.forName(HTTP.UTF_8);
MultipartEntity params = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null, charset);
try {
params.addPart("processModelInfoId", new StringBody("1", charset));
params.addPart("nodeNumber", new StringBody("0", charset));
params.addPart("key", new StringBody("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", charset));
// 件名
params.addPart("title", new StringBody("件名です", charset));
// 文字型
params.addPart("data[0].input", new StringBody("文字型です", charset));
// 数値型
params.addPart("data[1].input", new StringBody("12345", charset));
// 選択型
params.addPart("data[2].selects", new StringBody("2", charset));
params.addPart("data[2].selects", new StringBody("3", charset));
// 日付型
params.addPart("data[3].input", new StringBody("2011-09-26", charset));
// 日時型
params.addPart("data[4].input", new StringBody("2011-09-26", charset));
params.addPart("data[4].time", new StringBody("12:34", charset));
// ファイル型
params.addPart("data[5].upload", new FileBody(new File("sample.png"), "image/png"));
// ユーザ型
params.addPart("data[6].email", new StringBody("[email protected]", charset));
// 掲示板型
params.addPart("data[7].console", new StringBody("掲示板型です", charset));
// テーブル型
params.addPart("data[9].input", new StringBody("<list><row><col>文字</col><col>54321</col></row></list>",
charset));
post.setEntity(params);
HttpResponse response = client.execute(post);
int statusCode = response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
switch (statusCode) {
case 200 :
// 成功
System.out.println("プロセス開始に成功しました。");
break;
default :
// エラー応答が返ってきた場合
System.out.println("プロセス開始に失敗しました。 status: " + statusCode);
System.out.println(EntityUtils.toString(entity));
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment