Coverage Report - org.mule.module.cxf.support.ProxySchemaValidationInInterceptor
 
Classes in this File Line Coverage Branch Coverage Complexity
ProxySchemaValidationInInterceptor
0%
0/21
0%
0/8
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.support;
 8  
 
 9  
 import org.mule.module.xml.stax.ReversibleXMLStreamReader;
 10  
 
 11  
 import java.util.logging.Logger;
 12  
 
 13  
 import javax.xml.stream.XMLStreamException;
 14  
 import javax.xml.stream.XMLStreamReader;
 15  
 
 16  
 import org.apache.cxf.Bus;
 17  
 import org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor;
 18  
 import org.apache.cxf.binding.soap.interceptor.StartBodyInterceptor;
 19  
 import org.apache.cxf.common.logging.LogUtils;
 20  
 import org.apache.cxf.interceptor.Fault;
 21  
 import org.apache.cxf.io.StaxValidationManager;
 22  
 import org.apache.cxf.message.Message;
 23  
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 24  
 import org.apache.cxf.phase.Phase;
 25  
 import org.apache.cxf.service.model.ServiceInfo;
 26  
 
 27  
 public class ProxySchemaValidationInInterceptor extends AbstractPhaseInterceptor<Message> {
 28  0
     private static final Logger LOG = LogUtils.getL7dLogger(ProxySchemaValidationInInterceptor.class);
 29  
     
 30  
     private ServiceInfo service;
 31  
     private Bus bus;
 32  
     
 33  
     public ProxySchemaValidationInInterceptor(Bus bus, ServiceInfo service) {
 34  0
         super(Phase.READ);
 35  0
         this.bus = bus;
 36  0
         this.service = service;
 37  0
         addBefore(StartBodyInterceptor.class.getName());
 38  0
         addAfter(ReadHeadersInterceptor.class.getName());
 39  0
     }
 40  
 
 41  
 
 42  
     public void handleMessage(Message message) throws Fault {
 43  0
         XMLStreamReader xmlReader = message.getContent(XMLStreamReader.class);
 44  
         
 45  
         // if we're in proxy envelope mode, find the underlying stream reader before performing validation
 46  0
         if (xmlReader instanceof ReversibleXMLStreamReader) {
 47  0
             xmlReader = ((ReversibleXMLStreamReader) xmlReader).getDelegateReader();
 48  
         }
 49  
         
 50  
         try {
 51  0
             setSchemaInMessage(message, xmlReader);
 52  0
         } catch (XMLStreamException e) {
 53  0
             throw new Fault(new org.apache.cxf.common.i18n.Message("SCHEMA_ERROR", LOG), 
 54  
                             e);
 55  0
         }
 56  0
     }
 57  
     
 58  
     private void setSchemaInMessage(Message message, XMLStreamReader reader) throws XMLStreamException  {
 59  0
         Object en = message.getContextualProperty(org.apache.cxf.message.Message.SCHEMA_VALIDATION_ENABLED);
 60  0
         if (Boolean.TRUE.equals(en) || "true".equals(en)) {
 61  0
             StaxValidationManager mgr = bus.getExtension(StaxValidationManager.class);
 62  0
             if (mgr != null) {
 63  0
                 mgr.setupValidation(reader, service);
 64  
             }
 65  
         }
 66  0
     }
 67  
 }