}
@Test
public void testMessageBox() throws Exception {
MsgBoxClient user = new MsgBoxClient();
port = InMemoryMessageBoxServer.TESTING_PORT;
// test publish with Epr
EndpointReference msgBoxEpr = user.createMessageBox("http://localhost:" + port
+ "/axis2/services/MsgBoxService", timeout);
System.out.println(msgBoxEpr.toString());
user.storeMessage(msgBoxEpr, timeout,
MsgBoxUtils.reader2OMElement(new StringReader("<test>A simple test message</test>")));
Iterator<OMElement> iterator = user.takeMessagesFromMsgBox(msgBoxEpr, timeout);
int i = 0;
if (iterator != null)
while (iterator.hasNext()) {
i++;
System.out.println("Retrieved message :" + i);
System.out.println(iterator.next().toStringWithConsume());
}
// test invocations with id encoded in the Url
// port = InMemoryMessageBoxServer.getAvailablePort();
// user = new MsgBoxClient();
// msgBoxEpr = user.createMessageBox("http://localhost:" + port + "/axis2/services/MsgBoxService", timeout);
String msgBoxId = UUID.randomUUID().toString();
String address = msgBoxEpr.getAddress();
int biginIndex = address.indexOf("clientid");
if (biginIndex != -1) {
msgBoxId = address.substring(biginIndex + "clientid".length() + 1);
}
System.out.println("MSGBOX ID:" + msgBoxId);
String mesgboxUrl = "http://localhost:" + port + "/axis2/services/MsgBoxService/clientid/" + msgBoxId;
OMElement request = OMAbstractFactory.getOMFactory().createOMElement(new QName("foo"));
request.setText("bar");
ServiceClient client = null;
try {
client = new ServiceClient();
System.out.println(mesgboxUrl);
client.getOptions().setTo(new EndpointReference(mesgboxUrl));
OMElement response = client.sendReceive(request);
} finally {
client.cleanupTransport();
}
iterator = user.takeMessagesFromMsgBox(new EndpointReference(mesgboxUrl), timeout);
assertTrue(iterator.hasNext());
while (iterator.hasNext()) {
i++;
System.out.println("Retrieved message :" + i);
System.out.println(iterator.next().toStringWithConsume());
}
assertFalse(iterator.hasNext());
System.out.println("Delete message box response : " + user.deleteMsgBox(msgBoxEpr, timeout));
System.out.println("All tests Done");
}