Coverage Report - org.mule.module.cxf.support.StaxFeature
 
Classes in this File Line Coverage Branch Coverage Complexity
StaxFeature
0%
0/25
0%
0/4
0
StaxFeature$1
0%
0/4
0%
0/2
0
StaxFeature$2
0%
0/4
0%
0/2
0
 
 1  
 /*
 2  
  * $Id$
 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 javax.xml.stream.XMLInputFactory;
 14  
 import javax.xml.stream.XMLOutputFactory;
 15  
 
 16  
 import org.apache.cxf.Bus;
 17  
 import org.apache.cxf.endpoint.Client;
 18  
 import org.apache.cxf.endpoint.Server;
 19  
 import org.apache.cxf.feature.AbstractFeature;
 20  
 import org.apache.cxf.interceptor.Fault;
 21  
 import org.apache.cxf.message.Message;
 22  
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 23  
 import org.apache.cxf.phase.Phase;
 24  
 import org.apache.cxf.service.Service;
 25  
 
 26  
 /**
 27  
  * Configures the StAX XMLInputFactory and XMLOutputFactory which CXF uses.
 28  
  * 
 29  
  */
 30  0
 public class StaxFeature extends AbstractFeature {
 31  
     private String xmlInputFactory;
 32  
     private String xmlOutputFactory;
 33  
     
 34  
     @Override
 35  
     public void initialize(Client client, Bus bus) {
 36  0
         Service service = client.getEndpoint().getService();
 37  
         
 38  0
         setProperties(service);
 39  0
     }
 40  
 
 41  
     private void setProperties(Service service) {
 42  0
         if (xmlInputFactory != null) {
 43  0
             service.put(XMLInputFactory.class.getName(), xmlInputFactory);
 44  
         }
 45  
         
 46  0
         if (xmlOutputFactory != null) {
 47  0
             service.put(XMLOutputFactory.class.getName(), xmlOutputFactory);
 48  
         }
 49  0
     }
 50  
 
 51  
     @Override
 52  
     public void initialize(Server server, Bus bus) {
 53  0
         Service service = server.getEndpoint().getService();
 54  
         
 55  0
         setProperties(service);
 56  0
     }
 57  
 
 58  
     @Override
 59  
     public void initialize(Bus bus) {
 60  0
         AbstractPhaseInterceptor<Message> in = new AbstractPhaseInterceptor<Message>(Phase.RECEIVE) {
 61  
             public void handleMessage(Message message) throws Fault {
 62  0
                 if (xmlInputFactory != null) {
 63  0
                     message.put(XMLInputFactory.class.getName(), xmlInputFactory);
 64  
                 }
 65  0
             }
 66  
         };
 67  
         
 68  0
         bus.getInInterceptors().add(in);
 69  0
         bus.getInFaultInterceptors().add(in);
 70  
         
 71  0
         AbstractPhaseInterceptor<Message> out = new AbstractPhaseInterceptor<Message>(Phase.SETUP) {
 72  
             public void handleMessage(Message message) throws Fault {
 73  0
                 if (xmlOutputFactory != null) {
 74  0
                     message.put(XMLOutputFactory.class.getName(), xmlOutputFactory);
 75  
                 }
 76  0
             }
 77  
         };
 78  
         
 79  0
         bus.getOutInterceptors().add(out);
 80  0
         bus.getOutFaultInterceptors().add(out);
 81  0
     }
 82  
 
 83  
     public String getXmlInputFactory() {
 84  0
         return xmlInputFactory;
 85  
     }
 86  
 
 87  
     public void setXmlInputFactory(String xmlInputFactory) {
 88  0
         this.xmlInputFactory = xmlInputFactory;
 89  0
     }
 90  
 
 91  
     public String getXmlOutputFactory() {
 92  0
         return xmlOutputFactory;
 93  
     }
 94  
 
 95  
     public void setXmlOutputFactory(String xmlOutputFactory) {
 96  0
         this.xmlOutputFactory = xmlOutputFactory;
 97  0
     }
 98  
 
 99  
 }