View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.test.usecases.axis.clientbridge;
8   
9   import org.mule.api.MuleException;
10  import org.mule.api.MuleContext;
11  import org.mule.api.MuleMessage;
12  import org.mule.api.context.MuleContextFactory;
13  import org.mule.config.spring.SpringXmlConfigurationBuilder;
14  import org.mule.context.DefaultMuleContextFactory;
15  import org.mule.module.client.MuleClient;
16  
17  public class Client
18  {
19      private static final String LOCAL_ENDPOINT = "vm://complexRequest";
20      private static final String AXIS_ENDPOINT = "axis:http://localhost:8002/axisService/doSomeWork";
21      protected static MuleContext muleContext;
22  
23      public static void main(String[] args) throws Exception
24      {
25          muleContext = null;
26  
27          try
28          {
29              SpringXmlConfigurationBuilder builder = new SpringXmlConfigurationBuilder("clientbridge/conf/client-mule-config.xml");
30              MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
31              muleContext = muleContextFactory.createMuleContext(builder);
32  
33              Client c = new Client();
34              c.execute();
35          }
36          finally
37          {
38              if (muleContext != null)
39              {
40                 muleContext.dispose();
41              }
42          }
43      }
44  
45      private MuleClient client;
46  
47      private void execute() throws MuleException
48      {
49          client = new MuleClient(muleContext);
50  
51          try
52          {
53              executeComplexity();
54              complexRequest();
55          }
56          finally
57          {
58              if (client != null)
59              {
60                  client.dispose();
61              }
62          }
63      }
64  
65      private void executeComplexity() throws MuleException
66      {
67          System.err.println("\nexecuteComplexity");
68          Object result = client.send(AXIS_ENDPOINT + "?method=executeComplexity", new ComplexData("Foo",
69              new Integer(42)), null);
70          System.err.println(result);
71          MuleMessage message = (MuleMessage)result;
72          ComplexData data = (ComplexData)message.getPayload();
73          System.err.println(data);
74      }
75  
76      private void complexRequest() throws MuleException
77      {
78          System.err.println("\ncomplexRequest");
79          Object result = client.send(LOCAL_ENDPOINT, new ComplexData("Foo", new Integer(84)), null);
80          System.err.println(result);
81          MuleMessage message = (MuleMessage)result;
82          ComplexData data = (ComplexData)message.getPayload();
83          System.err.println(data);
84      }
85  }