[rules-users] how to invoke rest service on drools server with serialized objects

lhorton LHorton at ABCLegal.com
Fri Jul 22 17:40:03 EDT 2011


finally realized the answer to my question is "you can't."  In case there are
other newbies to Camel and Rest out there, I was able to run against
drools-server using xstream with the following code:

import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.params.HttpClientParams;
import org.drools.command.BatchExecutionCommand;
import org.drools.command.Command;
import org.drools.command.CommandFactory;
import org.drools.runtime.help.impl.BatchExecutionHelperProviderImpl;
import org.drools.runtime.impl.ExecutionResultImpl;

		List commands = new ArrayList<Command>();
		commands.add(CommandFactory.newSetGlobal("logger", logger));
		commands.add(CommandFactory.newInsert(fact));  // fact == my domain object
		commands.add(CommandFactory.newFireAllRules());
		BatchExecutionCommand batchCommand =
CommandFactory.newBatchExecution(commands, "workflowKnowledgeSession");
		BatchExecutionHelperProviderImpl helper = new
BatchExecutionHelperProviderImpl();
		String xml = helper.newXStreamMarshaller().toXML(batchCommand);
		// create http client to perform the post
		HttpClient httpClient = new HttpClient();
		httpClient.getHostConfiguration().setHost("172.17.4.178", 8280);
		PostMethod postMethod = new
PostMethod("/drools-server/kservice/rest/execute");
		StringRequestEntity requestEntity = new StringRequestEntity(xml,
"text/plain", "utf-8");
		postMethod.setRequestEntity(requestEntity);
		httpClient.executeMethod(postMethod);
		assertEquals(200, postMethod.getStatusCode());
		Object result =
helper.newXStreamMarshaller().fromXML(postMethod.getResponseBodyAsString());

I can see in the drools-server log that my knowledge session is being given
the message, and my rule is firing (it writes to the server log).  However,
I am not getting anything in the response body.  I will post that as a
separate question.

--
View this message in context: http://drools.46999.n3.nabble.com/rules-users-how-to-invoke-rest-service-on-drools-server-with-serialized-objects-tp3179834p3192453.html
Sent from the Drools: User forum mailing list archive at Nabble.com.



More information about the rules-users mailing list