Thomas Setiabudi [
https://community.jboss.org/people/thomas.setiabudi] created the
discussion
"Re: Process Parameters through REST API?"
To view the discussion, visit:
https://community.jboss.org/message/752814#752814
--------------------------------------------------------------
Hi Franck,
Finally Made It! :)
so here is how to do it.
first, you have to render the form
something like this
responseString = requestGetService(
"
http://localhost:8080/gwt-console-server/rs/form/process/
http://localhost:8080/gwt-console-server/rs/form/process/"
+ "com.sample.evaluation" + "/render", null, false);
if (responseString.contains("<html>")) {
responseString = authenticate(address, "krisv", "krisv");
responseString = requestGetService(
"
http://localhost:8080/gwt-console-server/rs/form/process/
http://localhost:8080/gwt-console-server/rs/form/process/"
+ "com.sample.evaluation" + "/render", null, false);
}
ok. this will get you the input form
then call the form process complete like this
String address = "
http://localhost:8080/gwt-console-server/rs/form/process/com.sample.evalu...
http://localhost:8080/gwt-console-server/rs/form/process/com.sample.evalu...;
String responseString = "";
Map<String, Object> map = new HashMap<String, Object>();
map.put("employee", "thomas");
map.put("reason", "theReason");
responseString = requestPostMultipartService(address, map);
if (responseString.contains("<html>")) {
responseString = authenticate(address, "krisv", "krisv");
responseString = requestPostMultipartService(address, map);
}
the result should be:
<div style='font-family:sans-serif; padding:10px;'><h3>Successfully
processed input</h3><p/>You can now close this window.</div>
:)
and for the functions that I use are:
private String requestPostMultipartService(String url,
Map<String, Object> parameters) {
String responseString = "";
try {
HttpPost httpPost = new HttpPost(url);
if (parameters == null)
parameters = new HashMap<String, Object>();
MultipartEntity entity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
Set<String> keys = parameters.keySet();
for (Iterator<String> keysIterator = keys.iterator(); keysIterator
.hasNext();) {
String keyString = keysIterator.next();
String value = parameters.get(keyString).toString();
entity.addPart(keyString, new StringBody(value));
}
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost);
responseString = this.getRequestString(response);
} catch (Exception e) {
}
return responseString;
}
and
private String getRequestString(HttpResponse response) throws Exception {
InputStreamReader inputStreamReader = null;
BufferedReader bufferedReader = null;
String req = "";
InputStream inputStream = response.getEntity().getContent();
inputStreamReader = new InputStreamReader(inputStream);
bufferedReader = new BufferedReader(inputStreamReader);
StringBuilder stringBuilder = new StringBuilder();
String line = bufferedReader.readLine();
while (line != null) {
stringBuilder.append(line);
line = bufferedReader.readLine();
}
req = stringBuilder.toString();
return req;
}
just give it a try and let me know if it works for you :)
Regards,
Thomas Setiabudi
--------------------------------------------------------------
Reply to this message by going to Community
[
https://community.jboss.org/message/752814#752814]
Start a new discussion in jBPM at Community
[
https://community.jboss.org/choose-container!input.jspa?contentType=1&...]