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