The reason I am starting this is, there is no clear documentation out there to explain this stuff. So, hopefully this will help someone to not go through the pain.
By the way, I just extended the bookTrading example in the jade distribution to get this to work.
1. Create JSP form
2. Create a simple bookTradingServlet which will send an ACLMessage to the agent. we will be using a simple OneShotBehaviour
- Create your servlet class
- Declare a private variable
private JadeGateway gateway = null;
- Initialize JADE gateway
public void init(ServletConfig config) throws ServletException
{
JadeGateway.init(null, null);
}
The first parameter should be null if you want to utilize the internal Agent class, which is supplied by default.
The second parameter is null unless you want to set some container parameters in the newly created container.
- in the doPost method, create ACLMessage, Behaviour and execute JADEGateway
protected void process(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
String title = "Sent Buyer Agent a Request :-)";
String bookTitle = req.getParameter("Title");
String cost = req.getParameter("Cost");
try
{
JadeGateway.execute(new OneShotBehaviour()
{
public void action()
{
final ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
AID buyer = new AID("Buyer@LA7750389:1099/JADE", false);
msg.addReceiver(buyer);
msg.setConversationId("book-trade-setup");
msg.setContent("TESTING Message via servlet");
myAgent.send(msg);
}
});
}
catch(Exception e)
{
e.printStackTrace();
System.out.println(e.getMessage());
}
out.println(ServletUtilities.headWithTitle(title) +
"\n" +
"
" + title + "
\n" +"
- \n" +
- param1: "
+ bookTitle + "\n" +
" - param2: "
+ cost + "\n" + "\n" +
"
"
"