Coverage Report - org.mule.module.cxf.builder.ProxyServiceMessageProcessorBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
ProxyServiceMessageProcessorBuilder
0%
0/31
0%
0/10
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.module.cxf.CxfConstants;
 10  
 import org.mule.module.cxf.support.CopyAttachmentInInterceptor;
 11  
 import org.mule.module.cxf.support.CopyAttachmentOutInterceptor;
 12  
 import org.mule.module.cxf.support.CxfUtils;
 13  
 import org.mule.module.cxf.support.OutputPayloadInterceptor;
 14  
 import org.mule.module.cxf.support.ProxySchemaValidationInInterceptor;
 15  
 import org.mule.module.cxf.support.ProxyService;
 16  
 import org.mule.module.cxf.support.ProxyServiceFactoryBean;
 17  
 import org.mule.module.cxf.support.ResetStaxInterceptor;
 18  
 import org.mule.module.cxf.support.ReversibleStaxInInterceptor;
 19  
 import org.mule.module.cxf.support.ReversibleValidatingInterceptor;
 20  
 
 21  
 import org.apache.cxf.binding.soap.interceptor.RPCOutInterceptor;
 22  
 import org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor;
 23  
 import org.apache.cxf.databinding.stax.StaxDataBinding;
 24  
 import org.apache.cxf.databinding.stax.StaxDataBindingFeature;
 25  
 import org.apache.cxf.endpoint.Server;
 26  
 import org.apache.cxf.frontend.ServerFactoryBean;
 27  
 import org.apache.cxf.interceptor.BareOutInterceptor;
 28  
 
 29  
 /**
 30  
  * Creates an inbound proxy based on a specially configure CXF Server.
 31  
  * This allows you to send raw XML to your MessageProcessor and have it sent
 32  
  * through CXF for SOAP processing, WS-Security, etc.
 33  
  * <p>
 34  
  * The input to the resulting MessageProcessor can be either a SOAP Body
 35  
  * or a SOAP Envelope depending on how the payload attribute is configured.
 36  
  * Valid values are "body" or "envelope". 
 37  
  */
 38  0
 public class ProxyServiceMessageProcessorBuilder extends AbstractInboundMessageProcessorBuilder
 39  
 {
 40  
     private String payload;
 41  
     
 42  
     @Override
 43  
     protected ServerFactoryBean createServerFactory() throws Exception
 44  
     {
 45  0
         ServerFactoryBean sfb = new ServerFactoryBean();
 46  0
         sfb.setDataBinding(new StaxDataBinding());
 47  0
         sfb.getFeatures().add(new StaxDataBindingFeature());
 48  0
         sfb.setServiceFactory(new ProxyServiceFactoryBean());
 49  0
         sfb.setServiceClass(ProxyService.class);
 50  
         
 51  0
         addProxyInterceptors(sfb);
 52  
         
 53  0
         return sfb;
 54  
     }
 55  
 
 56  
     @Override
 57  
     protected Class<?> getServiceClass()
 58  
     {
 59  0
         return ProxyService.class;
 60  
     }
 61  
 
 62  
     @Override
 63  
     protected void configureServer(Server server)
 64  
     {
 65  0
         if (isProxyEnvelope()) 
 66  
         {
 67  0
             CxfUtils.removeInterceptor(server.getEndpoint().getBinding().getOutInterceptors(), SoapOutInterceptor.class.getName());
 68  
         }
 69  
 
 70  
         // RPCOutInterceptor adds an operation node to the response, so if it's present replace if by a BareOutInterceptor
 71  0
         if(CxfUtils.removeInterceptor(server.getEndpoint().getBinding().getOutInterceptors(), RPCOutInterceptor.class.getName()))
 72  
         {
 73  0
             server.getEndpoint().getBinding().getOutInterceptors().add(new BareOutInterceptor());
 74  
         }
 75  
 
 76  0
         if (isValidationEnabled())
 77  
         {
 78  0
             server.getEndpoint().getInInterceptors().add(new ProxySchemaValidationInInterceptor(getConfiguration().getCxfBus(), 
 79  
                server.getEndpoint().getService().getServiceInfos().get(0)));
 80  
         }
 81  0
     }
 82  
 
 83  
     @Override
 84  
     public boolean isProxy()
 85  
     {
 86  0
         return true;
 87  
     }
 88  
 
 89  
     protected void addProxyInterceptors(ServerFactoryBean sfb)
 90  
     {
 91  0
         sfb.getOutInterceptors().add(new OutputPayloadInterceptor());
 92  0
         sfb.getInInterceptors().add(new CopyAttachmentInInterceptor());
 93  0
         sfb.getOutInterceptors().add(new CopyAttachmentOutInterceptor());
 94  
         
 95  0
         if (isProxyEnvelope()) 
 96  
         {
 97  0
             sfb.getInInterceptors().add(new ReversibleStaxInInterceptor());
 98  0
             sfb.getInInterceptors().add(new ResetStaxInterceptor());
 99  
         }
 100  
         /* Even if the payload is body, if validation is enabled, then we need to use a ReversibleXMLStreamReader to
 101  
          * avoid the message from being consumed during schema validation.
 102  
          */
 103  0
         else if(isValidationEnabled())
 104  
         {
 105  0
             sfb.getInInterceptors().add(new ReversibleValidatingInterceptor());
 106  0
             sfb.getInInterceptors().add(new ResetStaxInterceptor());
 107  
         }
 108  0
     }
 109  
 
 110  
     public boolean isProxyEnvelope()
 111  
     {
 112  0
         return CxfConstants.PAYLOAD_ENVELOPE.equals(payload);
 113  
     }
 114  
 
 115  
     public String getPayload()
 116  
     {
 117  0
         return payload;
 118  
     }
 119  
 
 120  
     public void setPayload(String payload)
 121  
     {
 122  0
         this.payload = payload;
 123  0
     }
 124  
     
 125  
 }