Search in sources :

Example 6 with ServiceClient

use of org.apache.axis2.client.ServiceClient 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) {
        }
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) Options(org.apache.axis2.client.Options) OMNamespace(org.apache.axiom.om.OMNamespace) AxisCallback(org.apache.axis2.client.async.AxisCallback) AxisService(org.apache.axis2.description.AxisService) OMElement(org.apache.axiom.om.OMElement) XMLStreamException(javax.xml.stream.XMLStreamException) OMFactory(org.apache.axiom.om.OMFactory) XMLStreamException(javax.xml.stream.XMLStreamException) ServiceClient(org.apache.axis2.client.ServiceClient) MessageContext(org.apache.axis2.context.MessageContext)

Example 7 with ServiceClient

use of org.apache.axis2.client.ServiceClient in project wso2-axis2-transports by wso2.

the class TCPEchoRawXMLTest method testEchoXMLCompleteSync.

public void testEchoXMLCompleteSync() throws Exception {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
    OMElement payloadElement = fac.createOMElement("echoOMElement", omNs);
    OMElement value = fac.createOMElement("myValue", omNs);
    value.setText("Isaac Asimov, The Foundation Trilogy");
    payloadElement.addChild(value);
    Options options = new Options();
    options.setTo(targetEPR);
    options.setAction(Constants.AXIS2_NAMESPACE_URI + "/" + operationName.getLocalPart());
    options.setTransportInProtocol(Constants.TRANSPORT_TCP);
    options.setUseSeparateListener(true);
    ServiceClient sender = new ServiceClient(configContext, clientService);
    sender.setOptions(options);
    OMElement result = sender.sendReceive(operationName, payloadElement);
    result.serialize(StAXUtils.createXMLStreamWriter(System.out));
    sender.cleanup();
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) Options(org.apache.axis2.client.Options) OMNamespace(org.apache.axiom.om.OMNamespace) ServiceClient(org.apache.axis2.client.ServiceClient) OMElement(org.apache.axiom.om.OMElement)

Example 8 with ServiceClient

use of org.apache.axis2.client.ServiceClient in project wso2-axis2-transports by wso2.

the class TCPEchoRawXMLTest method testEchoXMLSync.

public void testEchoXMLSync() 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());
    ServiceClient sender = new ServiceClient(configContext, clientService);
    sender.setOptions(options);
    OMElement result = sender.sendReceive(operationName, payload);
    result.serialize(StAXUtils.createXMLStreamWriter(System.out));
    sender.cleanup();
}
Also used : Options(org.apache.axis2.client.Options) ServiceClient(org.apache.axis2.client.ServiceClient) OMElement(org.apache.axiom.om.OMElement)

Aggregations

Options (org.apache.axis2.client.Options)8 ServiceClient (org.apache.axis2.client.ServiceClient)7 OMElement (org.apache.axiom.om.OMElement)6 OMFactory (org.apache.axiom.om.OMFactory)3 OMNamespace (org.apache.axiom.om.OMNamespace)3 AxisFault (org.apache.axis2.AxisFault)3 MessageContext (org.apache.axis2.context.MessageContext)3 XMLStreamException (javax.xml.stream.XMLStreamException)2 EndpointReference (org.apache.axis2.addressing.EndpointReference)2 AxisCallback (org.apache.axis2.client.async.AxisCallback)2 AxisService (org.apache.axis2.description.AxisService)2 QName (javax.xml.namespace.QName)1 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)1 SOAPFactory (org.apache.axiom.soap.SOAPFactory)1 OperationClient (org.apache.axis2.client.OperationClient)1 AxisOperation (org.apache.axis2.description.AxisOperation)1 OutInAxisOperation (org.apache.axis2.description.OutInAxisOperation)1 HttpTransportProperties (org.apache.axis2.transport.http.HttpTransportProperties)1 ProxyProperties (org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties)1 ClientOptions (org.apache.axis2.transport.testkit.client.ClientOptions)1