Coverage Report - org.mule.module.cxf.builder.AbstractOutboundMessageProcessorBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractOutboundMessageProcessorBuilder
0%
0/92
0%
0/16
0
 
 1  
 /*
 2  
  * $Id: AbstractOutboundMessageProcessorBuilder.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.module.cxf.builder;
 12  
 
 13  
 import org.mule.api.DefaultMuleException;
 14  
 import org.mule.api.MuleContext;
 15  
 import org.mule.api.MuleException;
 16  
 import org.mule.api.context.MuleContextAware;
 17  
 import org.mule.api.lifecycle.CreateException;
 18  
 import org.mule.api.processor.MessageProcessorBuilder;
 19  
 import org.mule.module.cxf.CxfConfiguration;
 20  
 import org.mule.module.cxf.CxfOutboundMessageProcessor;
 21  
 import org.mule.module.cxf.CxfPayloadToArguments;
 22  
 import org.mule.module.cxf.support.MuleHeadersInInterceptor;
 23  
 import org.mule.module.cxf.support.MuleHeadersOutInterceptor;
 24  
 import org.mule.module.cxf.support.MuleProtocolHeadersOutInterceptor;
 25  
 
 26  
 import java.lang.reflect.Method;
 27  
 import java.util.List;
 28  
 import java.util.Map;
 29  
 
 30  
 import org.apache.cxf.Bus;
 31  
 import org.apache.cxf.databinding.DataBinding;
 32  
 import org.apache.cxf.endpoint.Client;
 33  
 import org.apache.cxf.feature.AbstractFeature;
 34  
 import org.apache.cxf.interceptor.Interceptor;
 35  
 import org.apache.cxf.message.Message;
 36  
 
 37  0
 public abstract class AbstractOutboundMessageProcessorBuilder 
 38  
     implements MessageProcessorBuilder, MuleContextAware
 39  
 {
 40  
     protected Client client;
 41  
     protected String defaultMethodName;
 42  
     protected Method defaultMethod;
 43  
 
 44  
     protected CxfConfiguration configuration;
 45  
     protected List<Interceptor> inInterceptors;
 46  
     protected List<Interceptor> inFaultInterceptors;
 47  
     protected List<Interceptor> outInterceptors;
 48  
     protected List<Interceptor> outFaultInterceptors;
 49  
     protected DataBinding databinding;
 50  
     protected List<AbstractFeature> features;
 51  
     protected String wsdlLocation;
 52  
     protected boolean mtomEnabled;
 53  0
     protected boolean enableMuleSoapHeaders = true;
 54  0
     protected CxfPayloadToArguments payloadToArguments = CxfPayloadToArguments.NULL_PAYLOAD_AS_PARAMETER;
 55  
     protected Map<String,Object> properties;
 56  
     protected MuleContext muleContext;
 57  
     protected String address;
 58  
     protected String operation;
 59  
     
 60  
     @SuppressWarnings("unchecked")
 61  
     public CxfOutboundMessageProcessor build() throws MuleException
 62  
     {
 63  0
         if (muleContext == null) 
 64  
         {
 65  0
             throw new IllegalStateException("MuleContext must be supplied.");
 66  
         }
 67  
         
 68  0
         if (configuration == null)
 69  
         {
 70  0
             configuration = CxfConfiguration.getConfiguration(muleContext);
 71  
         }
 72  
         
 73  
         try
 74  
         {
 75  0
             client = createClient();
 76  
         }
 77  0
         catch (Exception e)
 78  
         {
 79  0
             throw new DefaultMuleException(e);
 80  0
         }
 81  
         
 82  0
         addInterceptors(client.getInInterceptors(), inInterceptors);
 83  0
         addInterceptors(client.getInFaultInterceptors(), inFaultInterceptors);
 84  0
         addInterceptors(client.getOutInterceptors(), outInterceptors);
 85  0
         addInterceptors(client.getOutFaultInterceptors(), outFaultInterceptors);
 86  
 
 87  0
         client.setThreadLocalRequestContext(true);
 88  
         
 89  0
         configureClient(client);
 90  
         
 91  0
         if (features != null)
 92  
         {
 93  0
             for (AbstractFeature f : features)
 94  
             {
 95  0
                 f.initialize(client, getBus());
 96  
             }
 97  
         }
 98  
 
 99  0
         if (mtomEnabled)
 100  
         {
 101  0
             client.getEndpoint().put(Message.MTOM_ENABLED, mtomEnabled);
 102  
         }
 103  
         
 104  0
         addMuleInterceptors();
 105  
         
 106  0
         CxfOutboundMessageProcessor processor = createMessageProcessor();
 107  0
         processor.setOperation(operation);
 108  0
         configureMessageProcessor(processor);
 109  0
         processor.setPayloadToArguments(payloadToArguments);
 110  0
         return processor;
 111  
     }
 112  
 
 113  
     protected CxfOutboundMessageProcessor createMessageProcessor()
 114  
     {
 115  0
         CxfOutboundMessageProcessor processor = new CxfOutboundMessageProcessor(client);
 116  0
         return processor;
 117  
     }
 118  
 
 119  
     protected void configureMessageProcessor(CxfOutboundMessageProcessor processor)
 120  
     {
 121  0
     }
 122  
 
 123  
     protected void configureClient(Client client)
 124  
     {
 125  0
     }
 126  
 
 127  
     protected Bus getBus()
 128  
     {
 129  0
         return configuration.getCxfBus();
 130  
     }
 131  
 
 132  
     protected abstract Client createClient() throws CreateException, Exception;
 133  
 
 134  
     public Client getClient()
 135  
     {
 136  0
         return client;
 137  
     }
 138  
 
 139  
     @SuppressWarnings("unchecked")
 140  
     private void addInterceptors(List<Interceptor> col, List<Interceptor> supplied)
 141  
     {
 142  0
         if (supplied != null) 
 143  
         {
 144  0
             col.addAll(supplied);
 145  
         }
 146  0
     }
 147  
     
 148  
     
 149  
     protected String getAddress()
 150  
     {
 151  0
         if (address == null) 
 152  
         {
 153  
             // dummy URL for client builder
 154  0
             return "http://host";
 155  
         }
 156  0
         return address;
 157  
     }
 158  
 
 159  
     public void setAddress(String address)
 160  
     {
 161  0
         this.address = address;
 162  0
     }
 163  
 
 164  
     protected void createClientFromLocalServer() throws Exception
 165  
     {
 166  0
     }
 167  
 
 168  
     protected void addMuleInterceptors()
 169  
     {
 170  0
         if (enableMuleSoapHeaders)
 171  
         {
 172  0
             client.getInInterceptors().add(new MuleHeadersInInterceptor());
 173  0
             client.getInFaultInterceptors().add(new MuleHeadersInInterceptor());
 174  0
             client.getOutInterceptors().add(new MuleHeadersOutInterceptor());
 175  0
             client.getOutFaultInterceptors().add(new MuleHeadersOutInterceptor());
 176  
         }
 177  0
         client.getOutInterceptors().add(new MuleProtocolHeadersOutInterceptor());
 178  0
         client.getOutFaultInterceptors().add(new MuleProtocolHeadersOutInterceptor());
 179  0
     }
 180  
     
 181  
     public String getOperation()
 182  
     {
 183  0
         return operation;
 184  
     }
 185  
 
 186  
     public void setOperation(String operation)
 187  
     {
 188  0
         this.operation = operation;
 189  0
     }
 190  
 
 191  
     public DataBinding getDatabinding()
 192  
     {
 193  0
         return databinding;
 194  
     }
 195  
 
 196  
     public void setDatabinding(DataBinding databinding)
 197  
     {
 198  0
         this.databinding = databinding;
 199  0
     }
 200  
 
 201  
     public boolean isMtomEnabled()
 202  
     {
 203  0
         return mtomEnabled;
 204  
     }
 205  
 
 206  
     public void setMtomEnabled(boolean mtomEnabled)
 207  
     {
 208  0
         this.mtomEnabled = mtomEnabled;
 209  0
     }
 210  
     
 211  
     public List<Interceptor> getInInterceptors()
 212  
     {
 213  0
         return inInterceptors;
 214  
     }
 215  
 
 216  
     public void setInInterceptors(List<Interceptor> inInterceptors)
 217  
     {
 218  0
         this.inInterceptors = inInterceptors;
 219  0
     }
 220  
 
 221  
     public List<Interceptor> getInFaultInterceptors()
 222  
     {
 223  0
         return inFaultInterceptors;
 224  
     }
 225  
 
 226  
     public void setInFaultInterceptors(List<Interceptor> inFaultInterceptors)
 227  
     {
 228  0
         this.inFaultInterceptors = inFaultInterceptors;
 229  0
     }
 230  
 
 231  
     public List<Interceptor> getOutInterceptors()
 232  
     {
 233  0
         return outInterceptors;
 234  
     }
 235  
 
 236  
     public void setOutInterceptors(List<Interceptor> outInterceptors)
 237  
     {
 238  0
         this.outInterceptors = outInterceptors;
 239  0
     }
 240  
 
 241  
     public List<Interceptor> getOutFaultInterceptors()
 242  
     {
 243  0
         return outFaultInterceptors;
 244  
     }
 245  
 
 246  
     public void setOutFaultInterceptors(List<Interceptor> outFaultInterceptors)
 247  
     {
 248  0
         this.outFaultInterceptors = outFaultInterceptors;
 249  0
     }
 250  
 
 251  
     public List<AbstractFeature> getFeatures()
 252  
     {
 253  0
         return features;
 254  
     }
 255  
 
 256  
     public void setFeatures(List<AbstractFeature> features)
 257  
     {
 258  0
         this.features = features;
 259  0
     }
 260  
     
 261  
     public String getWsdlLocation()
 262  
     {
 263  0
         return wsdlLocation;
 264  
     }
 265  
 
 266  
     public void setWsdlLocation(String wsdlLocation)
 267  
     {
 268  0
         this.wsdlLocation = wsdlLocation;
 269  0
     }
 270  
     
 271  
     public CxfConfiguration getConfiguration()
 272  
     {
 273  0
         return configuration;
 274  
     }
 275  
 
 276  
     public void setConfiguration(CxfConfiguration configuration)
 277  
     {
 278  0
         this.configuration = configuration;
 279  0
     }
 280  
 
 281  
     public boolean isEnableMuleSoapHeaders()
 282  
     {
 283  0
         return enableMuleSoapHeaders;
 284  
     }
 285  
 
 286  
     public void setEnableMuleSoapHeaders(boolean enableMuleSoapHeaders)
 287  
     {
 288  0
         this.enableMuleSoapHeaders = enableMuleSoapHeaders;
 289  0
     }
 290  
 
 291  
     public CxfPayloadToArguments getPayloadToArguments()
 292  
     {
 293  0
         return payloadToArguments;
 294  
     }
 295  
 
 296  
     public void setPayloadToArguments(CxfPayloadToArguments payloadToArguments)
 297  
     {
 298  0
         this.payloadToArguments = payloadToArguments;
 299  0
     }
 300  
     
 301  
     public Map<String, Object> getProperties()
 302  
     {
 303  0
         return properties;
 304  
     }
 305  
 
 306  
     public void setProperties(Map<String, Object> properties)
 307  
     {
 308  0
         this.properties = properties;
 309  0
     }
 310  
 
 311  
     public void setMuleContext(MuleContext context)
 312  
     {
 313  0
         muleContext = context;
 314  0
     }
 315  
     
 316  
 }