Search in sources :

Example 1 with ServiceClient

use of org.apache.axis2.client.ServiceClient in project tdi-studio-se by Talend.

the class MSCRMClient method setServiceClientOptions.

private static void setServiceClientOptions(ServiceClient sc, SecurityData securityData) throws AxisFault, XMLStreamException {
    Options options = sc.getOptions();
    options.setMessageId("urn:uuid:" + UUID.randomUUID().toString());
    EndpointReference endPoint = new EndpointReference("http://www.w3.org/2005/08/addressing/anonymous");
    options.setReplyTo(endPoint);
    sc.setOptions(options);
    sc.addHeader(createCRMSecurityHeaderBlock(securityData));
    HttpTransportProperties.ProxyProperties proxyProps = getProxyProperties();
    if (proxyProps != null) {
        sc.getOptions().setProperty(HTTPConstants.PROXY, proxyProps);
    }
    try {
        sc.engageModule("addressing");
    } catch (AxisFault e) {
        logger.error(e.getMessage());
        throw e;
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) Options(org.apache.axis2.client.Options) HttpTransportProperties(org.apache.axis2.transport.http.HttpTransportProperties) ProxyProperties(org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 2 with ServiceClient

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

Example 3 with ServiceClient

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

the class TCPEchoRawXMLTest method testEchoXMLSyncMC.

public void testEchoXMLSyncMC() throws Exception {
    AxisOperation opdesc = new OutInAxisOperation(new QName("echoOMElement"));
    Options options = new Options();
    options.setTo(targetEPR);
    options.setAction(operationName.getLocalPart());
    options.setTransportInProtocol(Constants.TRANSPORT_TCP);
    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);
    SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
    SOAPEnvelope envelope = factory.getDefaultEnvelope();
    envelope.getBody().addChild(method);
    MessageContext requestContext = new MessageContext();
    requestContext.setConfigurationContext(configContext);
    requestContext.setAxisService(clientService);
    requestContext.setAxisOperation(opdesc);
    requestContext.setEnvelope(envelope);
    ServiceClient sender = new ServiceClient(configContext, clientService);
    sender.setOptions(options);
    OperationClient opClient = sender.createClient(new QName("echoOMElement"));
    opClient.addMessageContext(requestContext);
    opClient.setOptions(options);
    opClient.execute(true);
    MessageContext response = opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
    SOAPEnvelope env = response.getEnvelope();
    assertNotNull(env);
    env.getBody().serialize(StAXUtils.createXMLStreamWriter(System.out));
    sender.cleanup();
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) Options(org.apache.axis2.client.Options) OperationClient(org.apache.axis2.client.OperationClient) OMNamespace(org.apache.axiom.om.OMNamespace) OutInAxisOperation(org.apache.axis2.description.OutInAxisOperation) AxisOperation(org.apache.axis2.description.AxisOperation) QName(javax.xml.namespace.QName) ServiceClient(org.apache.axis2.client.ServiceClient) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) MessageContext(org.apache.axis2.context.MessageContext) OutInAxisOperation(org.apache.axis2.description.OutInAxisOperation) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 4 with ServiceClient

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

the class AxisTestClient method setUp.

@Setup
@SuppressWarnings("unused")
private void setUp(AxisTestClientContext context, Channel channel, AxisTestClientConfigurator[] configurators) throws Exception {
    this.configurators = configurators;
    sender = context.getSender();
    serviceClient = new ServiceClient(context.getConfigurationContext(), null);
    axisOptions = new Options();
    axisOptions.setTo(channel.getEndpointReference());
    serviceClient.setOptions(axisOptions);
}
Also used : Options(org.apache.axis2.client.Options) ClientOptions(org.apache.axis2.transport.testkit.client.ClientOptions) ServiceClient(org.apache.axis2.client.ServiceClient) Setup(org.apache.axis2.transport.testkit.tests.Setup)

Example 5 with ServiceClient

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

the class UDPTest method testSoapOverUdpWithEchoService.

public void testSoapOverUdpWithEchoService() throws Exception {
    Options options = new Options();
    options.setTo(new EndpointReference("udp://127.0.0.1:3333?contentType=text/xml+soap"));
    options.setAction(Constants.AXIS2_NAMESPACE_URI + "/echoOMElement");
    options.setUseSeparateListener(true);
    options.setTimeOutInMilliSeconds(Long.MAX_VALUE);
    ServiceClient serviceClient = new ServiceClient(getClientCfgCtx(), null);
    serviceClient.setOptions(options);
    // We need to set up the anonymous service Axis uses to get the response
    AxisService clientService = serviceClient.getServiceContext().getAxisService();
    clientService.addParameter(UDPConstants.PORT_KEY, 4444);
    clientService.addParameter(UDPConstants.CONTENT_TYPE_KEY, "text/xml+soap");
    OMElement response = serviceClient.sendReceive(createPayload());
    assertEchoResponse(response);
}
Also used : Options(org.apache.axis2.client.Options) ServiceClient(org.apache.axis2.client.ServiceClient) AxisService(org.apache.axis2.description.AxisService) OMElement(org.apache.axiom.om.OMElement) EndpointReference(org.apache.axis2.addressing.EndpointReference)

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