Coverage Report - org.apache.camel.component.cxf.CxfInvokeProducer
 
Classes in this File Line Coverage Branch Coverage Complexity
CxfInvokeProducer
75% 
50% 
0
 
 1  
 /**
 2  
  *
 3  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 4  
  * contributor license agreements.  See the NOTICE file distributed with
 5  
  * this work for additional information regarding copyright ownership.
 6  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 7  
  * (the "License"); you may not use this file except in compliance with
 8  
  * the License.  You may obtain a copy of the License at
 9  
  *
 10  
  * http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 package org.apache.camel.component.cxf;
 19  
 
 20  
 import org.apache.camel.RuntimeCamelException;
 21  
 import org.apache.camel.Exchange;
 22  
 import org.apache.camel.impl.DefaultProducer;
 23  
 import org.apache.cxf.endpoint.Client;
 24  
 import org.apache.cxf.frontend.ClientFactoryBean;
 25  
 
 26  
 import java.util.List;
 27  
 
 28  
 /**
 29  
  * Sends messages from Camel into the CXF endpoint
 30  
  *
 31  
  * @version $Revision: 534156 $
 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  
         }                                                           
 54  0
         catch (Exception e) {
 55  0
             throw new RuntimeCamelException(e);
 56  1
         }
 57  
 
 58  1
         CxfBinding binding = endpoint.getBinding();
 59  1
         binding.storeCxfResponse(exchange, response);
 60  1
     }
 61  
 
 62  
     @Override
 63  
     protected void doStart() throws Exception {
 64  
         // TODO Add support for sending message inputstream.  Currently, we only 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
             cfBean.setServiceClass(Class.forName(endpoint.getProperty(CxfConstants.SEI)));
 73  1
             client = cfBean.create();
 74  
         }
 75  1
     }
 76  
 
 77  
     @Override
 78  
     protected void doStop() throws Exception {
 79  0
         if (client != null) {
 80  0
             client.getConduit().close();
 81  0
             client = null;
 82  
         }
 83  
 
 84  0
         super.doStop();
 85  0
     }
 86  
 }
 87  
 
 88