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 java.net.URI;
021    import java.util.Map;
022    
023    import org.apache.camel.CamelContext;
024    import org.apache.camel.Endpoint;
025    import org.apache.camel.impl.DefaultComponent;
026    import org.apache.cxf.Bus;
027    import org.apache.cxf.BusException;
028    import org.apache.cxf.bus.CXFBusFactory;
029    import org.apache.cxf.service.model.EndpointInfo;
030    import org.apache.cxf.transport.DestinationFactoryManager;
031    import org.apache.cxf.transport.local.LocalTransportFactory;
032    import org.xmlsoap.schemas.wsdl.http.AddressType;
033    
034    /**
035     * Defines the <a href="http://activemq.apache.org/camel/cxf.html">CXF Component</a>
036    
037     * @version $Revision: 550734 $
038     */
039    public class CxfComponent extends DefaultComponent<CxfExchange> {
040        private LocalTransportFactory localTransportFactory;
041    
042        public CxfComponent() {
043        }
044    
045        public CxfComponent(CamelContext context) {
046            super(context);
047        }
048    
049        @Override
050        protected Endpoint<CxfExchange> createEndpoint(String uri, String remaining, Map parameters) throws Exception {
051            URI u = new URI(remaining);
052    
053            // TODO this is a hack!!!
054            EndpointInfo endpointInfo = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
055            AddressType a = new AddressType();
056            a.setLocation(remaining);
057            endpointInfo.addExtensor(a);
058    
059            return new CxfEndpoint(uri, this, endpointInfo);
060        }
061    
062        public LocalTransportFactory getLocalTransportFactory() throws BusException {
063            if (localTransportFactory == null) {
064                localTransportFactory = findLocalTransportFactory();
065                if (localTransportFactory == null) {
066                    localTransportFactory = new LocalTransportFactory();
067                }
068            }
069            return localTransportFactory;
070        }
071    
072        public void setLocalTransportFactory(LocalTransportFactory localTransportFactory) {
073            this.localTransportFactory = localTransportFactory;
074        }
075    
076        protected LocalTransportFactory findLocalTransportFactory() throws BusException {
077            Bus bus = CXFBusFactory.getDefaultBus();
078            DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
079            return (LocalTransportFactory) dfm.getDestinationFactory(LocalTransportFactory.TRANSPORT_ID);
080        }
081    }