I posted that before I was done... oops... here is the class I have to call
the drools server...
private static void sendMessage() throws ClassNotFoundException,
JAXBException, PropertyException, IOException,
ClientProtocolException {
List<String> myDomainClasses = new ArrayList<String>();
myDomainClasses.add("com.koder.example.facts.Message");
// I need to create a JAXB context including my domain classes
// to be able to create a JAXB representation to send to the server
jaxbContext =
DroolsJaxbContextHelper.createDroolsJaxbContext(myDomainClasses, null);
Message test = new Message();
test.setMsg("blah");
// Once I get my object I need to create
// some commands to execute on the server
// Here I include a reference to the session that
// I define in my Knowledge Context Profile
List<Command> listOCommand = new ArrayList<Command>();
Command insertObjectCommand = CommandFactory.newInsert(test, "testFact",
true, null);
Command fireRules = new FireAllRulesCommand();
listOCommand.add(insertObjectCommand);
listOCommand.add(fireRules);
BatchExecutionCommand cmd =
CommandFactory.newBatchExecution(listOCommand, "ksession1");
// Once I get all I need to send to the server,
// I need to use the JAXB context
// to obtain the JAXB representation.
StringWriter xmlReq = new StringWriter();
javax.xml.bind.Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty("jaxb.formatted.output", true);
marshaller.marshal(cmd, xmlReq);
// I create a HTTPClient to interact with the
// server via REST (HTTP POST)
DefaultHttpClient httpClient = new DefaultHttpClient();
//Print the JAXB xml that we will send to the server
System.out.println("XML:\n" + xmlReq.toString() );
HttpPost postMethod = new
HttpPost("http://localhost:8080/drools-server/kservice/rest");
// HttpParams p = new BasicHttpParams();
// p.setParameter("execute", xmlReq.toString());
// postMethod.setParams(p);
//
StringEntity entity = new StringEntity(xmlReq.toString());
entity.setContentType("text/plain"); //"application/xml"
postMethod.setEntity(entity);
// HttpClientParams.setRedirecting(postMethod.getParams(), false);
HttpResponse response = httpClient.execute(postMethod);
System.out.println(response);
}
the comments are left in from the original code from salaboy's post...
the message that I get back is:
HTTP/1.1 404 Not Found [Server: Apache-Coyote/1.1, Allow: POST,OPTIONS,
Date: Tue, 09 Aug 2011 22:35:36 GMT, Content-Type: text/xml, Content-Length:
0]
trying to figure out what went wrong...
--
View this message in context:
http://drools.46999.n3.nabble.com/Insert-a-fact-into-drools-server-from-a...
Sent from the Drools: User forum mailing list archive at
Nabble.com.