Coverage Report - org.apache.camel.component.cxf.CxfInvokeComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
CxfInvokeComponent
79% 
100% 
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.CamelContext;
 21  
 import org.apache.camel.Endpoint;
 22  
 import org.apache.camel.impl.DefaultComponent;
 23  
 import org.apache.cxf.Bus;
 24  
 import org.apache.cxf.bus.CXFBusFactory;
 25  
 
 26  
 import java.net.URI;
 27  
 import java.util.Map;
 28  
 import java.util.Properties;
 29  
 
 30  
 /**
 31  
  * @version $Revision: 525898 $
 32  
  */
 33  
 public class CxfInvokeComponent extends DefaultComponent<CxfExchange> {
 34  
     private Bus bus;
 35  
 
 36  1
     public CxfInvokeComponent() {
 37  1
         bus = CXFBusFactory.getDefaultBus();
 38  1
     }
 39  
 
 40  
     public CxfInvokeComponent(CamelContext context) {
 41  0
         super(context);
 42  0
         bus = CXFBusFactory.getDefaultBus();
 43  0
     }
 44  
 
 45  
     @Override
 46  
     protected Endpoint<CxfExchange> createEndpoint(String uri, String remaining, Map parameters) throws Exception {
 47  1
         return new CxfInvokeEndpoint(getAddress(remaining), this, getQueryAsProperties(new URI(remaining)));
 48  
     }
 49  
 
 50  
     /**
 51  
      * Read query parameters from uri
 52  
      *
 53  
      * @param u
 54  
      * @return parameter value pairs as properties
 55  
      */
 56  
     protected Properties getQueryAsProperties(URI u) {
 57  1
         Properties retval = new Properties();
 58  1
         if (u.getQuery() != null) {
 59  1
             String[] parameters = u.getQuery().split("&");
 60  3
             for (int i = 0; i < parameters.length; i++) {
 61  2
                 String[] s = parameters[i].split("=");
 62  2
                 retval.put(s[0], s[1]);
 63  
             }
 64  
         }
 65  1
         return retval;
 66  
     }
 67  
 
 68  
     /**
 69  
      * Remove query from uri
 70  
      *
 71  
      * @param uri
 72  
      * @return substring before  the "?" character
 73  
      */
 74  
     protected String getAddress(String uri) {
 75  1
         int index = uri.indexOf("?");
 76  1
         if (-1 != index) {
 77  1
             return uri.substring(0, index);
 78  
         }
 79  0
         return uri;
 80  
     }
 81  
 
 82  
     public Bus getBus() {
 83  1
         return bus;
 84  
     }
 85  
 }