Coverage Report - org.mule.module.cxf.builder.ProxyClientMessageProcessorBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
ProxyClientMessageProcessorBuilder
0%
0/36
0%
0/6
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.module.cxf.builder;
 8  
 
 9  
 import org.mule.api.lifecycle.CreateException;
 10  
 import org.mule.module.cxf.CxfConstants;
 11  
 import org.mule.module.cxf.CxfOutboundMessageProcessor;
 12  
 import org.mule.module.cxf.support.CopyAttachmentInInterceptor;
 13  
 import org.mule.module.cxf.support.CopyAttachmentOutInterceptor;
 14  
 import org.mule.module.cxf.support.CxfUtils;
 15  
 import org.mule.module.cxf.support.OutputPayloadInterceptor;
 16  
 import org.mule.module.cxf.support.ProxyService;
 17  
 import org.mule.module.cxf.support.ResetStaxInterceptor;
 18  
 import org.mule.module.cxf.support.ReversibleStaxInInterceptor;
 19  
 import org.mule.module.cxf.support.StreamClosingInterceptor;
 20  
 import org.mule.module.cxf.transport.MuleUniversalConduit;
 21  
 
 22  
 import org.apache.cxf.binding.Binding;
 23  
 import org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor;
 24  
 import org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor;
 25  
 import org.apache.cxf.binding.soap.interceptor.Soap12FaultInInterceptor;
 26  
 import org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor;
 27  
 import org.apache.cxf.databinding.stax.StaxDataBinding;
 28  
 import org.apache.cxf.databinding.stax.StaxDataBindingFeature;
 29  
 import org.apache.cxf.endpoint.Client;
 30  
 import org.apache.cxf.frontend.ClientProxy;
 31  
 import org.apache.cxf.frontend.ClientProxyFactoryBean;
 32  
 import org.apache.cxf.interceptor.WrappedOutInterceptor;
 33  
 
 34  
 /**
 35  
  * Creates an outbound proxy based on a specially configure CXF Client.
 36  
  * This allows you to send raw XML to your MessageProcessor and have it sent
 37  
  * through CXF for SOAP processing, WS-Security, etc.
 38  
  * <p>
 39  
  * The input to the resulting MessageProcessor can be either a SOAP Body
 40  
  * or a SOAP Envelope depending on how the payload attribute is configured.
 41  
  * Valid values are "body" or "envelope". 
 42  
  */
 43  0
 public class ProxyClientMessageProcessorBuilder extends AbstractOutboundMessageProcessorBuilder
 44  
 {
 45  
     private String payload;
 46  
     
 47  
     @Override
 48  
     protected void configureClient(Client client)
 49  
     {
 50  0
         MuleUniversalConduit conduit = (MuleUniversalConduit)client.getConduit();
 51  
 
 52  
         // add interceptors to handle Mule proxy specific stuff
 53  0
         client.getInInterceptors().add(new CopyAttachmentInInterceptor());
 54  0
         client.getInInterceptors().add(new StreamClosingInterceptor());
 55  0
         client.getOutInterceptors().add(new OutputPayloadInterceptor());
 56  0
         client.getOutInterceptors().add(new CopyAttachmentOutInterceptor());
 57  
         
 58  
         // Don't close the input because people need to be able to work with the live stream
 59  0
         conduit.setCloseInput(false);
 60  0
     }
 61  
 
 62  
     public boolean isProxyEnvelope()
 63  
     {
 64  0
         return CxfConstants.PAYLOAD_ENVELOPE.equals(payload);
 65  
     }
 66  
     
 67  
     @Override
 68  
     protected void configureMessageProcessor(CxfOutboundMessageProcessor processor)
 69  
     {
 70  0
         processor.setProxy(true);
 71  0
     }
 72  
 
 73  
     @Override
 74  
     protected Client createClient() throws CreateException, Exception
 75  
     {
 76  0
         ClientProxyFactoryBean cpf = new ClientProxyFactoryBean();
 77  0
         cpf.setServiceClass(ProxyService.class);
 78  0
         cpf.setDataBinding(new StaxDataBinding());
 79  0
         cpf.getFeatures().add(new StaxDataBindingFeature());
 80  0
         cpf.setAddress(getAddress());
 81  0
         cpf.setBus(getBus());
 82  0
         cpf.setProperties(properties);
 83  
 
 84  
         // If there's a soapVersion defined then the corresponding bindingId will be set
 85  0
         if(soapVersion != null)
 86  
         {
 87  0
             cpf.setBindingId(CxfUtils.getBindingIdForSoapVersion(soapVersion));
 88  
         }
 89  
         
 90  0
         if (wsdlLocation != null) 
 91  
         {
 92  0
             cpf.setWsdlLocation(wsdlLocation);
 93  
         }
 94  
         
 95  0
         Client client = ClientProxy.getClient(cpf.create());
 96  
 
 97  0
         Binding binding = client.getEndpoint().getBinding();
 98  0
         CxfUtils.removeInterceptor(binding.getOutInterceptors(), WrappedOutInterceptor.class.getName());
 99  0
         CxfUtils.removeInterceptor(binding.getInInterceptors(), Soap11FaultInInterceptor.class.getName());
 100  0
         CxfUtils.removeInterceptor(binding.getInInterceptors(), Soap12FaultInInterceptor.class.getName());
 101  0
         CxfUtils.removeInterceptor(binding.getInInterceptors(), CheckFaultInterceptor.class.getName());
 102  
 
 103  0
         if (isProxyEnvelope()) 
 104  
         {
 105  0
             CxfUtils.removeInterceptor(binding.getOutInterceptors(), SoapOutInterceptor.class.getName());
 106  0
             client.getInInterceptors().add(new ReversibleStaxInInterceptor());
 107  0
             client.getInInterceptors().add(new ResetStaxInterceptor());
 108  
         }
 109  
         
 110  0
         return client;
 111  
     }
 112  
 
 113  
     public String getPayload()
 114  
     {
 115  0
         return payload;
 116  
     }
 117  
 
 118  
     public void setPayload(String payload)
 119  
     {
 120  0
         this.payload = payload;
 121  0
     }
 122  
     
 123  
 }