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