View Javadoc

1   /*
2    * $Id: Client.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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      protected static MuleContext muleContext;
26  
27      public static void main(String[] args) throws Exception
28      {
29          muleContext = null;
30  
31          try
32          {
33              SpringXmlConfigurationBuilder builder = new SpringXmlConfigurationBuilder("clientbridge/conf/client-mule-config.xml");
34              MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
35              muleContext = muleContextFactory.createMuleContext(builder);
36  
37              Client c = new Client();
38              c.execute();
39          }
40          finally
41          {
42              if (muleContext != null)
43              {
44                 muleContext.dispose();
45              }
46          }
47      }
48  
49      private MuleClient client;
50  
51      private void execute() throws MuleException
52      {
53          client = new MuleClient(muleContext);
54  
55          try
56          {
57              executeComplexity();
58              complexRequest();
59          }
60          finally
61          {
62              if (client != null)
63              {
64                  client.dispose();
65              }
66          }
67      }
68  
69      private void executeComplexity() throws MuleException
70      {
71          System.err.println("\nexecuteComplexity");
72          Object result = client.send(AXIS_ENDPOINT + "?method=executeComplexity", new ComplexData("Foo",
73              new Integer(42)), null);
74          System.err.println(result);
75          MuleMessage message = (MuleMessage)result;
76          ComplexData data = (ComplexData)message.getPayload();
77          System.err.println(data);
78      }
79  
80      private void complexRequest() throws MuleException
81      {
82          System.err.println("\ncomplexRequest");
83          Object result = client.send(LOCAL_ENDPOINT, new ComplexData("Foo", new Integer(84)), null);
84          System.err.println(result);
85          MuleMessage message = (MuleMessage)result;
86          ComplexData data = (ComplexData)message.getPayload();
87          System.err.println(data);
88      }
89  }