I'm trying to send a byte array with the Jade ACL message. Basically I want to do what this guy does: Decryption Error bad padding But I don't want to convert the cipher into a string but send the bytes directly. There's a function named setByteSequence which I could/should use but when I run my code, it throws an error saying that base64 is not supported and refers to the documentation which doesn't say anything about how to use it. Just that it's supported. I'm using the jade.jar from the Jade Website.
Sender:
public class Alice extends Agent {
private static final long serialVersionUID = 725326296709140752L;
protected void setup() {
ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
AID recipient1 = new AID();
recipient1.setName(String.format("Bob@%s:1099/JADE", Main.IPBob));
recipient1.addAddresses(String.format("http://%s:7778/acc", Main.IPBob));
msg.addReceiver(recipient1);
// byte[] mBytes = "bla".getBytes(); // this doesn't work
byte[] mBytes = Base64.getEncoder().encode("bla".getBytes()); // neither does this
msg.setByteSequenceContent(mBytes);
send(msg);
}
}
Receiver:
public class Bob extends Agent {
private static final long serialVersionUID = 2028682217881039710L;
protected void setup() {
addBehaviour(new CyclicBehaviour(this) {
private static final long serialVersionUID = 1L;
public void action() {
ACLMessage msg = myAgent.receive();
if (msg != null) {
System.out.println(String.format("Got Message %s", DatatypeConverter.printBase64Binary(msg.getByteSequenceContent())));
} else {
block();
}
}
});
}
}
Main:
public class Main {
public static final String IPAlice = "...";
public static final String IPBob = "...";
public static void main(String[] args) {
int port = 1099;
int mtpPort = 7778;
String hostIP = "...";
Profile profile = new ProfileImpl(hostIP, port, null, true);
profile.setParameter(Profile.MTPS, "jade.mtp.http.MessageTransportProtocol(http://"+hostIP+":"+mtpPort+"/acc)");
Runtime runtime = Runtime.instance();
AgentContainer container = runtime.createMainContainer(profile);
try {
// AgentController bob = container.createNewAgent("Bob", agent.Bob.class.getName(), null);
// bob.start();
AgentController alice = container.createNewAgent("Alice", agent.Alice.class.getName(), null);
alice.start();
} catch (StaleProxyException e) {
e.printStackTrace();
}
}
}
}
The base64 example doesn't show anything either. It just sets an object as the message's content and says that it will be base64-encoded...Might be that I'm missing the obvious but I can't see it. I'm grateful for help.
Tried it with the soures instead of the jar and found that org.apache.commons.codec.binary.Base64
could not be resolved which means that I have to add Apache Commons Codec to my project.