Coverage Report - org.mule.transport.soap.axis.AxisMessageRequester
 
Classes in this File Line Coverage Branch Coverage Complexity
AxisMessageRequester
0%
0/51
0%
0/12
1.667
 
 1  
 /*
 2  
  * $Id: AxisMessageRequester.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.transport.soap.axis;
 12  
 
 13  
 import org.mule.api.MuleMessage;
 14  
 import org.mule.api.config.MuleProperties;
 15  
 import org.mule.api.endpoint.EndpointURI;
 16  
 import org.mule.api.endpoint.ImmutableEndpoint;
 17  
 import org.mule.api.endpoint.InboundEndpoint;
 18  
 import org.mule.endpoint.MuleEndpointURI;
 19  
 import org.mule.transport.AbstractMessageRequester;
 20  
 
 21  
 import java.util.Iterator;
 22  
 import java.util.Properties;
 23  
 
 24  
 import javax.xml.soap.SOAPEnvelope;
 25  
 
 26  
 import org.apache.axis.AxisProperties;
 27  
 import org.apache.axis.EngineConfiguration;
 28  
 import org.apache.axis.Message;
 29  
 import org.apache.axis.client.Call;
 30  
 import org.apache.axis.client.Service;
 31  
 import org.apache.axis.configuration.FileProvider;
 32  
 
 33  
 /**
 34  
  * <code>AxisMessageDispatcher</code> is used to make soap requests via the Axis
 35  
  * soap client.
 36  
  */
 37  
 public class AxisMessageRequester extends AbstractMessageRequester
 38  
 {
 39  
 
 40  
     protected EngineConfiguration clientConfig;
 41  
     protected AxisConnector connector;
 42  
     protected Service service;
 43  
 
 44  
     public AxisMessageRequester(InboundEndpoint endpoint)
 45  
     {
 46  0
         super(endpoint);
 47  0
         this.connector = (AxisConnector)endpoint.getConnector();
 48  0
         AxisProperties.setProperty("axis.doAutoTypes", Boolean.toString(connector.isDoAutoTypes()));
 49  0
     }
 50  
 
 51  
     protected void doConnect() throws Exception
 52  
     {
 53  0
         if (service == null)
 54  
         {
 55  0
             service = createService(endpoint);
 56  
         }
 57  0
     }
 58  
 
 59  
     protected void doDisconnect() throws Exception
 60  
     {
 61  0
         if (service != null)
 62  
         {
 63  0
             service = null;
 64  
         }
 65  0
     }
 66  
 
 67  
     protected void doDispose()
 68  
     {
 69  
         // template method
 70  0
     }
 71  
 
 72  
     protected synchronized EngineConfiguration getClientConfig(ImmutableEndpoint endpoint)
 73  
     {
 74  0
         if (clientConfig == null)
 75  
         {
 76  
             // Allow the client config to be set on the endpoint
 77  
             String config;
 78  0
             config = (String)endpoint.getProperty(AxisConnector.AXIS_CLIENT_CONFIG_PROPERTY);
 79  
 
 80  0
             if (config != null)
 81  
             {
 82  0
                 clientConfig = new FileProvider(config);
 83  
             }
 84  
             else
 85  
             {
 86  0
                 clientConfig = connector.getClientProvider();
 87  
             }
 88  
         }
 89  0
         return clientConfig;
 90  
     }
 91  
 
 92  
     protected Service createService(ImmutableEndpoint endpoint) throws Exception
 93  
     {
 94  
         // Create a simple axis service without wsdl
 95  0
         EngineConfiguration config = getClientConfig(endpoint);
 96  0
         return new Service(config);
 97  
     }
 98  
 
 99  
     /**
 100  
      * Make a specific request to the underlying transport
 101  
      *
 102  
      * @param timeout the maximum time the operation should block before returning.
 103  
      *            The call should return immediately if there is data available. If
 104  
      *            no data becomes available before the timeout elapses, null will be
 105  
      *            returned
 106  
      * @return the result of the request wrapped in a MuleMessage object. Null will be
 107  
      *         returned if no data was avaialable
 108  
      * @throws Exception if the call to the underlying protocal cuases an exception
 109  
      */
 110  
     protected MuleMessage doRequest(long timeout) throws Exception
 111  
     {
 112  0
         Call call = new Call(service);
 113  0
         String uri = endpoint.getEndpointURI().toString();
 114  0
         call.setSOAPActionURI(uri);
 115  0
         call.setTargetEndpointAddress(uri);
 116  
 
 117  0
         Properties params = endpoint.getEndpointURI().getUserParams();
 118  0
         String method = (String)params.remove(MuleProperties.MULE_METHOD_PROPERTY);
 119  0
         call.setOperationName(method);
 120  
 
 121  0
         String args[] = new String[params.size()];
 122  0
         int i = 0;
 123  0
         for (Iterator iterator = params.values().iterator(); iterator.hasNext(); i++)
 124  
         {
 125  0
             args[i] = iterator.next().toString();
 126  
         }
 127  
 
 128  0
         call.setOperationName(method);
 129  0
         call.setProperty(MuleProperties.MULE_ENDPOINT_PROPERTY, endpoint);
 130  0
         call.setProperty(MuleProperties.MULE_CONTEXT_PROPERTY, connector.getMuleContext());
 131  
 
 132  0
         Object result = call.invoke(method, args);
 133  0
         return AxisMessageDispatcher.createMessage(result, call, connector.getMuleContext());
 134  
     }
 135  
 
 136  
     public MuleMessage request(String endpoint, Object[] args) throws Exception
 137  
     {
 138  0
         Call call = new Call(service);
 139  
 
 140  0
         call.setSOAPActionURI(endpoint);
 141  0
         call.setTargetEndpointAddress(endpoint);
 142  
 
 143  0
         if (!endpoint.startsWith("axis:"))
 144  
         {
 145  0
             endpoint = "axis:" + endpoint;
 146  
         }
 147  0
         EndpointURI ep = new MuleEndpointURI(endpoint, connector.getMuleContext());
 148  0
         String method = (String)ep.getParams().remove(MuleProperties.MULE_METHOD_PROPERTY);
 149  0
         call.setOperationName(method);
 150  
 
 151  0
         call.setOperationName(method);
 152  0
         Object result = call.invoke(method, args);
 153  0
         return AxisMessageDispatcher.createMessage(result, call, connector.getMuleContext());
 154  
     }
 155  
 
 156  
     public MuleMessage request(String endpoint, SOAPEnvelope envelope) throws Exception
 157  
     {
 158  0
         Call call = new Call(service);
 159  
 
 160  0
         call.setSOAPActionURI(endpoint);
 161  0
         call.setTargetEndpointAddress(endpoint);
 162  0
         Object result = call.invoke(new Message(envelope));
 163  0
         return AxisMessageDispatcher.createMessage(result, call, connector.getMuleContext());
 164  
     }
 165  
 
 166  
 }