Package org.mule.module.client

Examples of org.mule.module.client.MuleClient


    }

    public void testSoapRequest() throws Exception
    {

        MuleClient client = new MuleClient(muleContext);
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("http.method", "POST");

        DefaultMuleMessage soapRequest = null;
        soapRequest = new DefaultMuleMessage(
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
            + "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:mule=\"http://www.muleumo.org/providers/soap/1.0\">"
            + "<soapenv:Header>"
            + "<Action>storeModuleInformation</Action>"
            + // this should be ignored
              "<mule:header>"
            + "<mule:MULE_REPLYTO>http://localhost:62182/reply</mule:MULE_REPLYTO>"
            + "</mule:header>"
            + "</soapenv:Header>"
            + "<soapenv:Body><echo soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><value0 xsi:type=\"soapenc:string\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">Test Message</value0></echo></soapenv:Body>"
            + "</soapenv:Envelope>", muleContext);

        MuleMessage reply = client.send("http://localhost:" + getPorts().get(0) + "/services/component", soapRequest, properties);

        // Put this in so that no spurious exceptions are thrown
        // TODO research and see why sometimes we get 404 or Connection refused
        // errors without this line. Note that the test completes even when the
        // exceptions are thrown.
View Full Code Here


        MuleMessage result = null;
        String resultPayload = StringUtils.EMPTY;

        try
        {
            MuleClient client = new MuleClient(muleContext);
            result = client.send(url, input, properties);
            resultPayload = (result != null ? result.getPayloadAsString() : StringUtils.EMPTY);
        }
        catch (MuleException e)
        {
            fail(ExceptionUtils.getStackTrace(e));
View Full Code Here

    public void testWsdl1() throws Exception
    {
        Map props = new HashMap();
        props.put(HttpConnector.HTTP_METHOD_PROPERTY, "GET");
        MuleClient client = new MuleClient(muleContext);

        MuleMessage result = client.send("http://localhost:" + getPorts().get(0) + "/services/EchoService1?wsdl", null, props);
        assertNotNull(result);
        String wsdl = result.getPayloadAsString();
        Document doc = DocumentHelper.parseText(wsdl);
        assertEquals("http://foo", doc.valueOf("/wsdl:definitions/@targetNamespace"));
View Full Code Here

    public void testWsdl2() throws Exception
    {
        Map props = new HashMap();
        props.put(HttpConnector.HTTP_METHOD_PROPERTY, "GET");
        MuleClient client = new MuleClient(muleContext);

        MuleMessage result = client.send("http://localhost:" + getPorts().get(1) + "/services/EchoService2?wsdl", null, props);
        assertNotNull(result);
        String wsdl = result.getPayloadAsString();
        Document doc = DocumentHelper.parseText(wsdl);
        assertEquals("http://simple.component.api.mule.org", doc.valueOf("/wsdl:definitions/@targetNamespace"));
        assertEquals("mulePortType", doc.valueOf("/wsdl:definitions/wsdl:portType/@name"));
View Full Code Here

    public void testWsdl3() throws Exception
    {
        Map props = new HashMap();
        props.put(HttpConnector.HTTP_METHOD_PROPERTY, "GET");
        MuleClient client = new MuleClient(muleContext);

        MuleMessage result = client.send("http://localhost:" + getPorts().get(2) + "/services/EchoService3?wsdl", null, props);
        assertNotNull(result);
        String wsdl = result.getPayloadAsString();
        Document doc = DocumentHelper.parseText(wsdl);
        assertEquals("http://foo.com", doc.valueOf("/wsdl:definitions/@targetNamespace"));
        assertEquals("mulePortType1", doc.valueOf("/wsdl:definitions/wsdl:portType/@name"));
View Full Code Here

                eventCount.incrementAndGet();
            }
        };
        subscriptionBean.setEventCallback(callback);

        MuleClient client = new MuleClient(muleContext);
        Order order = new Order("Sausage and Mash");
        client.send("jms://orders.queue", order, null);
        Thread.sleep(1000);
        assertTrue(eventCount.get() == 1);

        MuleMessage result = client.request("jms://processed.queue", 10000);
        assertEquals(1, eventCount.intValue());
        assertNotNull(result);
        assertEquals("Order 'Sausage and Mash' Processed", result.getPayloadAsString());
    }
View Full Code Here

        return "org/mule/test/integration/client/test-client-jms-mule-config.xml";
    }
   
    public void testTransactionsWithSetRollbackOnly() throws Exception
    {
        final MuleClient client = new MuleClient(muleContext);
        final Map<String, Object> props = new HashMap<String, Object>();
        props.put("JMSReplyTo", "replyTo.queue");
        props.put(MuleProperties.MULE_REMOTE_SYNC_PROPERTY, "false");

        // Empty reply queue
        while (client.request("jms://replyTo.queue", 2000) != null)
        {
            // slurp
        }

        MuleTransactionConfig tc = new MuleTransactionConfig();
        tc.setFactory(new JmsTransactionFactory());
        tc.setAction(TransactionConfig.ACTION_ALWAYS_BEGIN);

        // This enpoint needs to be registered prior to use cause we need to set
        // the transaction config so that the endpoint will "know" it is transacted
        // and not close the session itself but leave it up to the transaction.
        EndpointBuilder endpointBuilder = new EndpointURIEndpointBuilder(
            new URIBuilder("jms://test.queue", muleContext));
        endpointBuilder.setTransactionConfig(tc);
        endpointBuilder.setName("TransactedTest.Queue");
        ImmutableEndpoint inboundEndpoint = muleContext.getRegistry()
                .lookupEndpointFactory()
                .getOutboundEndpoint(endpointBuilder);
        client.getMuleContext().getRegistry().registerEndpoint(inboundEndpoint);

        TransactionTemplate<Void> tt = new TransactionTemplate<Void>(tc, muleContext);
        tt.execute(new TransactionCallback<Void>()
        {
            public Void doInTransaction() throws Exception
            {
                for (int i = 0; i < 100; i++)
                {
                    client.send("jms://test.queue", "Test Client Dispatch message " + i, props);
                }
                Transaction tx = TransactionCoordination.getInstance().getTransaction();
                assertNotNull(tx);
                tx.setRollbackOnly();
                return null;
            }
        });

        MuleMessage result = client.request("jms://replyTo.queue", 2000);
        assertNull(result);
    }
View Full Code Here

        assertNull(result);
    }

    public void testTransactionsWithExceptionThrown() throws Exception
    {
        final MuleClient client = new MuleClient(muleContext);
        final Map<String, Object> props = new HashMap<String, Object>();
        props.put("JMSReplyTo", "replyTo.queue");
        props.put(MuleProperties.MULE_REMOTE_SYNC_PROPERTY, "false");

        // Empty reply queue
        while (client.request("jms://replyTo.queue", 2000) != null)
        {
            // hmm..mesages
        }

        MuleTransactionConfig tc = new MuleTransactionConfig();
        tc.setFactory(new JmsTransactionFactory());
        tc.setAction(TransactionConfig.ACTION_ALWAYS_BEGIN);

        // This enpoint needs to be registered prior to use cause we need to set
        // the transaction config so that the endpoint will "know" it is transacted
        // and not close the session itself but leave it up to the transaction.
        EndpointBuilder endpointBuilder = new EndpointURIEndpointBuilder(
            new URIBuilder("jms://test.queue", muleContext));
        endpointBuilder.setTransactionConfig(tc);
        endpointBuilder.setName("TransactedTest.Queue");
        ImmutableEndpoint inboundEndpoint = muleContext.getRegistry()
                .lookupEndpointFactory()
                .getOutboundEndpoint(endpointBuilder);
        client.getMuleContext().getRegistry().registerEndpoint(inboundEndpoint);

        TransactionTemplate<Void> tt = new TransactionTemplate<Void>(tc, muleContext);
        try
        {
            tt.execute(new TransactionCallback<Void>()
            {
                public Void doInTransaction() throws Exception
                {
                    for (int i = 0; i < 100; i++)
                    {
                        client.send("jms://test.queue", "Test Client Dispatch message " + i, props);
                    }
                    throw new Exception();
                }
            });
            fail();
        }
        catch (Exception e)
        {
            // this is ok
        }

        MuleMessage result = client.request("jms://replyTo.queue", 2000);
        assertNull(result);
    }
View Full Code Here

{
    private String testString = "test";

    public void testWsCall() throws Exception
    {
        MuleClient client = new MuleClient(muleContext);
        MuleMessage result = client.send("vm://testin", new DefaultMuleMessage(testString, muleContext));
        assertNotNull(result.getPayload());
        assertEquals("Payload", "Received: "+ testString, result.getPayloadAsString());
    }
View Full Code Here

        assertNull(result);
    }

    public void testTransactionsWithCommit() throws Exception
    {
        final MuleClient client = new MuleClient(muleContext);
        final Map<String, Object> props = new HashMap<String, Object>();
        props.put("JMSReplyTo", "replyTo.queue");
        props.put(MuleProperties.MULE_REMOTE_SYNC_PROPERTY, "false");
        props.put("transacted", "true");

        // Empty reply queue
        while (client.request("jms://replyTo.queue", 2000) != null)
        {
            // yum!
        }

        MuleTransactionConfig tc = new MuleTransactionConfig();
        tc.setFactory(new JmsTransactionFactory());
        tc.setAction(TransactionConfig.ACTION_ALWAYS_BEGIN);

        // This enpoint needs to be registered prior to use cause we need to set
        // the transaction config so that the endpoint will "know" it is transacted
        // and not close the session itself but leave it up to the transaction.
        EndpointBuilder endpointBuilder = new EndpointURIEndpointBuilder(
            new URIBuilder("jms://test.queue", muleContext));
        endpointBuilder.setTransactionConfig(tc);
        endpointBuilder.setName("TransactedTest.Queue");
        ImmutableEndpoint inboundEndpoint = muleContext.getRegistry()
                .lookupEndpointFactory()
                .getOutboundEndpoint(endpointBuilder);
        client.getMuleContext().getRegistry().registerEndpoint(inboundEndpoint);


        TransactionTemplate<Void> tt = new TransactionTemplate<Void>(tc, muleContext);
        tt.execute(new TransactionCallback<Void>()
        {
            public Void doInTransaction() throws Exception
            {
                for (int i = 0; i < 100; i++)
                {
                    client.send("jms://test.queue", "Test Client Dispatch message " + i, props);
                }
                return null;
            }
        });

        for (int i = 0; i < 100; i++)
        {
            MuleMessage result = client.request("jms://replyTo.queue", 2000);
            assertNotNull(result);
        }
        MuleMessage result = client.request("jms://replyTo.queue", 2000);
        assertNull(result);
    }
View Full Code Here

TOP

Related Classes of org.mule.module.client.MuleClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.