Search in sources :

Example 31 with SampleClientResult

use of org.apache.synapse.samples.framework.SampleClientResult in project wso2-synapse by wso2.

the class Sample9 method testDynamicSequences.

public void testDynamicSequences() {
    String addUrl = "http://localhost:9000/services/SimpleStockQuoteService";
    String trpUrl = "http://localhost:8280/";
    StockQuoteSampleClient client = getStockQuoteClient();
    log.info("Running test: Dynamic Sequences with Registry");
    SampleClientResult result = client.requestStandardQuote(addUrl, trpUrl, null, "IBM", null);
    assertResponseReceived(result);
}
Also used : SampleClientResult(org.apache.synapse.samples.framework.SampleClientResult) StockQuoteSampleClient(org.apache.synapse.samples.framework.clients.StockQuoteSampleClient)

Example 32 with SampleClientResult

use of org.apache.synapse.samples.framework.SampleClientResult in project wso2-synapse by wso2.

the class Sample657 method testDistributedTransaction.

public void testDistributedTransaction() {
    if (System.getProperty("java.naming.factory.initial") == null) {
        System.setProperty("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
    }
    String addUrl = "http://localhost:9000/services/SimpleStockQuoteService";
    String trpUrl = "http://localhost:8280/";
    StockQuoteSampleClient client = getStockQuoteClient();
    log.info("Running test: Distributed Transaction Management");
    SampleClientResult result = client.requestStandardQuote(addUrl, trpUrl, null, "IBM", null);
    assertTrue("Client did not get run successfully ", result.responseReceived());
}
Also used : SampleClientResult(org.apache.synapse.samples.framework.SampleClientResult) StockQuoteSampleClient(org.apache.synapse.samples.framework.clients.StockQuoteSampleClient)

Example 33 with SampleClientResult

use of org.apache.synapse.samples.framework.SampleClientResult in project wso2-synapse by wso2.

the class IterateSOAPActionTestCase method testSOAPAction.

public void testSOAPAction() throws Exception {
    String addUrl = "http://localhost:8280/services/iterateWithSOAPActionTestProxy";
    StockQuoteSampleClient client = getStockQuoteClient();
    SampleClientResult result = client.requestStandardQuote(addUrl, null, null, "WSO2", null);
    assertTrue("Client didn't get response", result.responseReceived());
}
Also used : SampleClientResult(org.apache.synapse.samples.framework.SampleClientResult) StockQuoteSampleClient(org.apache.synapse.samples.framework.clients.StockQuoteSampleClient)

Example 34 with SampleClientResult

use of org.apache.synapse.samples.framework.SampleClientResult in project wso2-synapse by wso2.

the class LogMediatorAfterSendMediatorTestCase method testLogMediatorAfterSendMediator.

public void testLogMediatorAfterSendMediator() {
    StockQuoteSampleClient client = getStockQuoteClient();
    SampleClientResult result = client.requestStandardQuote("http://localhost:8280/services/sendMediatorWithLogAfterwardsTestProxy", null, null, "WSO2", null);
    assertTrue("Response not received", result.responseReceived());
}
Also used : SampleClientResult(org.apache.synapse.samples.framework.SampleClientResult) StockQuoteSampleClient(org.apache.synapse.samples.framework.clients.StockQuoteSampleClient)

Example 35 with SampleClientResult

use of org.apache.synapse.samples.framework.SampleClientResult in project wso2-synapse by wso2.

the class MTOMSwASampleClient method sendUsingMTOM.

public SampleClientResult sendUsingMTOM(String fileName, String targetEPR) {
    clientResult = new SampleClientResult();
    try {
        OMFactory factory = OMAbstractFactory.getOMFactory();
        OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
        payload = factory.createOMElement("uploadFileUsingMTOM", ns);
        OMElement request = factory.createOMElement("request", ns);
        OMElement image = factory.createOMElement("image", ns);
        log.info("Sending file : " + fileName + " as MTOM");
        FileDataSource fileDataSource = new FileDataSource(new File(fileName));
        DataHandler dataHandler = new DataHandler(fileDataSource);
        OMText textData = factory.createOMText(dataHandler, true);
        image.addChild(textData);
        request.addChild(image);
        payload.addChild(request);
        ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(configuration.getClientRepo(), configuration.getAxis2Xml());
        serviceClient = new ServiceClient(configContext, null);
        Options options = new Options();
        options.setTo(new EndpointReference(targetEPR));
        options.setAction("urn:uploadFileUsingMTOM");
        options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
        serviceClient.setOptions(options);
        OMElement response = serviceClient.sendReceive(payload);
        OMText binaryNode = (OMText) response.getFirstChildWithName(new QName("http://services.samples", "response")).getFirstChildWithName(new QName("http://services.samples", "image")).getFirstOMChild();
        dataHandler = (DataHandler) binaryNode.getDataHandler();
        InputStream is = dataHandler.getInputStream();
        log.info("temp.dir: " + System.getProperty("java.io.tmpdir"));
        File tempFile = File.createTempFile("mtom-", ".gif");
        FileOutputStream fos = new FileOutputStream(tempFile);
        BufferedOutputStream dest = new BufferedOutputStream(fos, 2048);
        byte[] data = new byte[2048];
        int count;
        while ((count = is.read(data, 0, 2048)) != -1) {
            dest.write(data, 0, count);
        }
        dest.flush();
        dest.close();
        log.info("Saved response to file : " + tempFile.getAbsolutePath());
        clientResult.incrementResponseCount();
    } catch (Exception e) {
        log.error("Error invoking service", e);
        clientResult.setException(e);
    }
    return clientResult;
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Options(org.apache.axis2.client.Options) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) DataHandler(javax.activation.DataHandler) EndpointReference(org.apache.axis2.addressing.EndpointReference) ServiceClient(org.apache.axis2.client.ServiceClient) SampleClientResult(org.apache.synapse.samples.framework.SampleClientResult) FileOutputStream(java.io.FileOutputStream) FileDataSource(javax.activation.FileDataSource) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

SampleClientResult (org.apache.synapse.samples.framework.SampleClientResult)64 StockQuoteSampleClient (org.apache.synapse.samples.framework.clients.StockQuoteSampleClient)45 OMElement (org.apache.axiom.om.OMElement)5 AxisFault (org.apache.axis2.AxisFault)5 QName (javax.xml.namespace.QName)4 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 DataHandler (javax.activation.DataHandler)2 FileDataSource (javax.activation.FileDataSource)2 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)2 EndpointReference (org.apache.axis2.addressing.EndpointReference)2 OperationClient (org.apache.axis2.client.OperationClient)2 Options (org.apache.axis2.client.Options)2 ServiceClient (org.apache.axis2.client.ServiceClient)2 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)2 MessageContext (org.apache.axis2.context.MessageContext)2 MTOMSwASampleClient (org.apache.synapse.samples.framework.clients.MTOMSwASampleClient)2 BufferedOutputStream (java.io.BufferedOutputStream)1 InputStream (java.io.InputStream)1 Attachments (org.apache.axiom.attachments.Attachments)1