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