I just started to use Jade and I would like to know if it is possible to send a message from an agent to a servlet using JadeGateway, I have already managed to send a message from a servlet to an agent, but I want that agent to send back a reply and nothing seems to work for me.
Here is the doPost method of my servlet:
String champ = request.getParameter("action");
try {
JadeGateway.execute(new OneShotBehaviour() {
@Override
public void action() {
out.println("action");
final ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);
AID theAgent = new AID("Agent47", false);
msg.addReceiver(theAgent);
msg.setConversationId("Agent servlet communication");
msg.setContent(champ);
myAgent.send(msg);
ACLMessage res = myAgent.receive();
if (res != null) {
System.out.println(res.getContent());
}
}
});
The servlet sends the data entered by the user in a jsp page to the agent.
Here is the code of the agent:
//The cyclic behaviour i added to the agent
public class ProcessExternalRequests extends CyclicBehaviour {
private MessageTemplate mt;
@Override
public void action() {
mt = MessageTemplate.MatchConversationId("Agent servlet communication");
ACLMessage msg = myAgent.receive(mt);
if(msg!=null){
if(msg.getPerformative()==ACLMessage.REQUEST){
String content = msg.getContent();
System.out.println("Agent " + myAgent.getAID().getLocalName() + " Content = " + content);
//Response
ACLMessage res = new ACLMessage(ACLMessage.CONFIRM);
res.addReceiver(msg.getSender());
res.setContent("Bien reçu!");
myAgent.send(res);
}
}else{
block();
}
My problem is that the agent won't send a message back to the servlet. What should I do?