Coverage Report - org.apache.camel.component.cxf.CxfInvokeProducer
 
Classes in this File Line Coverage Branch Coverage Complexity
CxfInvokeProducer
77% 
50% 
0
 
 1  
 /**
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.camel.component.cxf;
 18  
 
 19  
 import java.util.List;
 20  
 
 21  
 import org.apache.camel.Exchange;
 22  
 import org.apache.camel.RuntimeCamelException;
 23  
 import org.apache.camel.impl.DefaultProducer;
 24  
 import org.apache.camel.util.ObjectHelper;
 25  
 import org.apache.cxf.endpoint.Client;
 26  
 import org.apache.cxf.frontend.ClientFactoryBean;
 27  
 
 28  
 /**
 29  
  * Sends messages from Camel into the CXF endpoint
 30  
  * 
 31  
  * @version $Revision: 563665 $
 32  
  */
 33  
 public class CxfInvokeProducer extends DefaultProducer {
 34  
     private CxfInvokeEndpoint endpoint;
 35  
     private Client client;
 36  
 
 37  
     public CxfInvokeProducer(CxfInvokeEndpoint endpoint) {
 38  1
         super(endpoint);
 39  1
         this.endpoint = endpoint;
 40  1
     }
 41  
 
 42  
     public void process(Exchange exchange) {
 43  1
         CxfExchange cxfExchange = endpoint.toExchangeType(exchange);
 44  1
         process(cxfExchange);
 45  1
         exchange.copyFrom(cxfExchange);
 46  1
     }
 47  
 
 48  
     public void process(CxfExchange exchange) {
 49  1
         List params = exchange.getIn().getBody(List.class);
 50  1
         Object[] response = null;
 51  
         try {
 52  1
             response = client.invoke(endpoint.getProperty(CxfConstants.METHOD), params.toArray());
 53  0
         } catch (Exception e) {
 54  0
             throw new RuntimeCamelException(e);
 55  1
         }
 56  
 
 57  1
         CxfBinding binding = endpoint.getBinding();
 58  1
         binding.storeCxfResponse(exchange, response);
 59  1
     }
 60  
 
 61  
     @Override
 62  
     protected void doStart() throws Exception {
 63  
         // TODO Add support for sending message inputstream. Currently, we only
 64  
         // handle
 65  
         // method invocation with pojo.
 66  
 
 67  
         // TODO Add support for endpoints associated with a WSDL
 68  1
         if (client == null) {
 69  1
             ClientFactoryBean cfBean = new ClientFactoryBean();
 70  1
             cfBean.setAddress(getEndpoint().getEndpointUri());
 71  1
             cfBean.setBus(endpoint.getBus());
 72  1
             String className = endpoint.getProperty(CxfConstants.SEI);
 73  1
             Class type = ObjectHelper.loadClass(className);
 74  1
             cfBean.setServiceClass(type);
 75  1
             client = cfBean.create();
 76  
         }
 77  1
     }
 78  
 
 79  
     @Override
 80  
     protected void doStop() throws Exception {
 81  0
         if (client != null) {
 82  0
             client.getConduit().close();
 83  0
             client = null;
 84  
         }
 85  
 
 86  0
         super.doStop();
 87  0
     }
 88  
 }