001 /** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 package org.apache.camel.component.cxf; 019 020 import org.apache.camel.CamelContext; 021 import org.apache.camel.Endpoint; 022 import org.apache.camel.impl.DefaultComponent; 023 import org.apache.cxf.Bus; 024 import org.apache.cxf.bus.CXFBusFactory; 025 026 import java.net.URI; 027 import java.util.Map; 028 import java.util.Properties; 029 030 /** 031 * @version $Revision: 525898 $ 032 */ 033 public class CxfInvokeComponent extends DefaultComponent<CxfExchange> { 034 private Bus bus; 035 036 public CxfInvokeComponent() { 037 bus = CXFBusFactory.getDefaultBus(); 038 } 039 040 public CxfInvokeComponent(CamelContext context) { 041 super(context); 042 bus = CXFBusFactory.getDefaultBus(); 043 } 044 045 @Override 046 protected Endpoint<CxfExchange> createEndpoint(String uri, String remaining, Map parameters) throws Exception { 047 return new CxfInvokeEndpoint(getAddress(remaining), this, getQueryAsProperties(new URI(remaining))); 048 } 049 050 /** 051 * Read query parameters from uri 052 * 053 * @param u 054 * @return parameter value pairs as properties 055 */ 056 protected Properties getQueryAsProperties(URI u) { 057 Properties retval = new Properties(); 058 if (u.getQuery() != null) { 059 String[] parameters = u.getQuery().split("&"); 060 for (int i = 0; i < parameters.length; i++) { 061 String[] s = parameters[i].split("="); 062 retval.put(s[0], s[1]); 063 } 064 } 065 return retval; 066 } 067 068 /** 069 * Remove query from uri 070 * 071 * @param uri 072 * @return substring before the "?" character 073 */ 074 protected String getAddress(String uri) { 075 int index = uri.indexOf("?"); 076 if (-1 != index) { 077 return uri.substring(0, index); 078 } 079 return uri; 080 } 081 082 public Bus getBus() { 083 return bus; 084 } 085 }