001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.camel.component.cxf.jaxrs;
019
020 import java.util.HashMap;
021 import java.util.Map;
022
023 import org.apache.camel.CamelContext;
024 import org.apache.camel.Endpoint;
025 import org.apache.camel.component.cxf.CxfConstants;
026 import org.apache.camel.impl.HeaderFilterStrategyComponent;
027 import org.apache.camel.util.CamelContextHelper;
028 import org.apache.camel.util.CastUtils;
029 import org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean;
030
031 /**
032 * Defines the <a href="http://camel.apache.org/cxfrs.html">CXF RS Component</a>
033 */
034 public class CxfRsComponent extends HeaderFilterStrategyComponent {
035 public CxfRsComponent() {
036 super();
037 }
038
039 public CxfRsComponent(CamelContext context) {
040 super(context);
041 }
042
043 @Override
044 protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
045 CxfRsEndpoint answer = null;
046 if (remaining.startsWith(CxfConstants.SPRING_CONTEXT_ENDPOINT)) {
047 // Get the bean from the Spring context
048 String beanId = remaining.substring(CxfConstants.SPRING_CONTEXT_ENDPOINT.length());
049 if (beanId.startsWith("//")) {
050 beanId = beanId.substring(2);
051 }
052
053 AbstractJAXRSFactoryBean bean = CamelContextHelper.mandatoryLookup(getCamelContext(), beanId,
054 AbstractJAXRSFactoryBean.class);
055
056 answer = new CxfRsSpringEndpoint(this.getCamelContext(), bean);
057
058 // Apply Spring bean properties (including # notation referenced bean). Note that the
059 // Spring bean properties values can be overridden by property defined in URI query.
060 // The super class (DefaultComponent) will invoke "setProperties" after this method
061 // with to apply properties defined by URI query.
062 if (bean.getProperties() != null) {
063 Map<String, Object> copy = new HashMap<String, Object>();
064 copy.putAll(bean.getProperties());
065 setProperties(answer, copy);
066 }
067
068 } else {
069 // endpoint URI does not specify a bean
070 answer = new CxfRsEndpoint(remaining, this);
071 }
072 Map<String, String> params = CastUtils.cast(parameters);
073 answer.setParameters(params);
074 setEndpointHeaderFilterStrategy(answer);
075 return answer;
076 }
077 }