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