use of org.apache.axis2.client.async.AxisCallback in project wso2-axis2-transports by wso2.
the class TCPEchoRawXMLTest method testEchoXMLASync.
public void testEchoXMLASync() throws Exception {
OMElement payload = createPayload();
Options options = new Options();
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_TCP);
options.setAction(Constants.AXIS2_NAMESPACE_URI + "/" + operationName.getLocalPart());
AxisCallback axisCallback = new AxisCallback() {
public void onMessage(MessageContext msgContext) {
try {
msgContext.getEnvelope().serialize(StAXUtils.createXMLStreamWriter(System.out));
finish = true;
} catch (XMLStreamException e) {
onError(e);
}
}
public void onFault(MessageContext msgContext) {
try {
msgContext.getEnvelope().serialize(StAXUtils.createXMLStreamWriter(System.out));
finish = true;
} catch (XMLStreamException e) {
onError(e);
}
}
public void onError(Exception e) {
log.info(e.getMessage());
finish = true;
}
public void onComplete() {
finish = true;
}
};
ServiceClient sender = new ServiceClient(configContext, clientService);
sender.setOptions(options);
sender.sendReceiveNonBlocking(operationName, payload, axisCallback);
int index = 0;
while (!finish) {
Thread.sleep(1000);
index++;
if (index > 10) {
throw new AxisFault("Server was shutdown as the async response take too long to complete");
}
}
sender.cleanup();
}
use of org.apache.axis2.client.async.AxisCallback in project wso2-axis2-transports by wso2.
the class TCPTwoChannelEchoRawXMLTest method testEchoXMLCompleteASync.
public void testEchoXMLCompleteASync() throws Exception {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
OMElement method = fac.createOMElement("echoOMElement", omNs);
OMElement value = fac.createOMElement("myValue", omNs);
value.setText("Isaac Asimov, The Foundation Trilogy");
method.addChild(value);
ServiceClient sender;
try {
Options options = new Options();
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_TCP);
options.setUseSeparateListener(true);
options.setAction(operationName.getLocalPart());
AxisCallback axisCallback = new AxisCallback() {
public void onMessage(MessageContext msgContext) {
try {
msgContext.getEnvelope().serialize(StAXUtils.createXMLStreamWriter(System.out));
finish = true;
} catch (XMLStreamException e) {
onError(e);
}
}
public void onFault(MessageContext msgContext) {
try {
msgContext.getEnvelope().serialize(StAXUtils.createXMLStreamWriter(System.out));
finish = true;
} catch (XMLStreamException e) {
onError(e);
}
}
public void onError(Exception e) {
log.info(e.getMessage());
finish = true;
}
public void onComplete() {
finish = true;
}
};
AxisService serviceClient = Utils.createSimpleServiceforClient(serviceName, Echo.class.getName(), operationName);
sender = new ServiceClient(configContext, serviceClient);
sender.setOptions(options);
sender.sendReceiveNonBlocking(operationName, method, axisCallback);
int index = 0;
while (!finish) {
Thread.sleep(1000);
index++;
if (index > 10) {
throw new AxisFault("Server was shutdown as the async response take too long to complete");
}
}
} finally {
if (finish) {
}
}
}
Aggregations