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