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 package org.apache.camel.component.cxf.transport;
018
019 import java.io.IOException;
020 import java.util.Arrays;
021 import java.util.HashSet;
022 import java.util.List;
023 import java.util.Set;
024
025 import javax.annotation.Resource;
026
027 import org.apache.camel.CamelContext;
028 import org.apache.camel.CamelContextAware;
029 import org.apache.camel.component.cxf.common.header.CxfHeaderFilterStrategy;
030 import org.apache.camel.spi.HeaderFilterStrategy;
031 import org.apache.cxf.Bus;
032 import org.apache.cxf.common.injection.NoJSR250Annotations;
033 import org.apache.cxf.service.model.EndpointInfo;
034 import org.apache.cxf.transport.AbstractTransportFactory;
035 import org.apache.cxf.transport.Conduit;
036 import org.apache.cxf.transport.ConduitInitiator;
037 import org.apache.cxf.transport.Destination;
038 import org.apache.cxf.transport.DestinationFactory;
039 import org.apache.cxf.ws.addressing.EndpointReferenceType;
040
041 /**
042 * @version
043 */
044 @NoJSR250Annotations(unlessNull = "bus")
045 public class CamelTransportFactory extends AbstractTransportFactory implements ConduitInitiator, DestinationFactory, CamelContextAware {
046
047 public static final String TRANSPORT_ID = "http://cxf.apache.org/transports/camel";
048 public static final List<String> DEFAULT_NAMESPACES = Arrays.asList(TRANSPORT_ID);
049 private static final Set<String> URI_PREFIXES = new HashSet<String>();
050
051 private HeaderFilterStrategy headerFilterStrategy;
052 private boolean checkException;
053
054 static {
055 URI_PREFIXES.add("camel://");
056 }
057
058 private CamelContext camelContext;
059
060 public CamelTransportFactory() {
061 CxfHeaderFilterStrategy defaultHeaderFilterStrategy = new CxfHeaderFilterStrategy();
062 // Doesn't filter the camel relates headers by default
063 defaultHeaderFilterStrategy.setOutFilterPattern(null);
064 headerFilterStrategy = defaultHeaderFilterStrategy;
065 }
066 public CamelTransportFactory(Bus b) {
067 super(DEFAULT_NAMESPACES, b);
068 CxfHeaderFilterStrategy defaultHeaderFilterStrategy = new CxfHeaderFilterStrategy();
069 // Doesn't filter the camel relates headers by default
070 defaultHeaderFilterStrategy.setOutFilterPattern(null);
071 headerFilterStrategy = defaultHeaderFilterStrategy;
072 }
073
074 @Resource(name = "cxf")
075 public void setBus(Bus b) {
076 super.setBus(b);
077 }
078
079 public void setCheckException(boolean check) {
080 checkException = check;
081 }
082
083 public boolean isCheckException() {
084 return checkException;
085 }
086
087 public Conduit getConduit(EndpointInfo targetInfo) throws IOException {
088 return getConduit(targetInfo, null);
089 }
090
091 public Conduit getConduit(EndpointInfo endpointInfo, EndpointReferenceType target) throws IOException {
092 return new CamelConduit(camelContext, bus, endpointInfo, target, headerFilterStrategy);
093 }
094
095 public Destination getDestination(EndpointInfo endpointInfo) throws IOException {
096 return new CamelDestination(camelContext, bus, this, endpointInfo, headerFilterStrategy, checkException);
097 }
098
099 public Set<String> getUriPrefixes() {
100 return URI_PREFIXES;
101 }
102
103 public HeaderFilterStrategy getHeaderFilterStrategy() {
104 return headerFilterStrategy;
105 }
106
107 public void setHeaderFilterStrategy(HeaderFilterStrategy headerFilterStrategy) {
108 this.headerFilterStrategy = headerFilterStrategy;
109 }
110
111 public CamelContext getCamelContext() {
112 return camelContext;
113 }
114 public void setCamelContext(CamelContext c) {
115 camelContext = c;
116 }
117
118 }
119
120