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.servicemix.cxfbc;
018
019 import java.util.List;
020
021 import org.apache.cxf.Bus;
022 import org.apache.cxf.BusFactory;
023 import org.apache.cxf.bus.spring.SpringBusFactory;
024 import org.apache.servicemix.common.DefaultComponent;
025 import org.apache.servicemix.jbi.security.auth.AuthenticationService;
026 import org.apache.servicemix.jbi.security.auth.impl.JAASAuthenticationService;
027
028 /**
029 *
030 * @author gnodet
031 * @org.apache.xbean.XBean element="component" description="a JBI component for hosting endpoints that can use
032 * either SOAP/HTTP or SOAP/JMS."
033 */
034 public class CxfBcComponent extends DefaultComponent {
035
036 private CxfBcEndpointType[] endpoints;
037
038 private Bus bus;
039
040 private String busCfg;
041
042 private CxfBcConfiguration configuration = new CxfBcConfiguration();
043
044 /**
045 * @return the endpoints
046 */
047 public CxfBcEndpointType[] getEndpoints() {
048 return endpoints;
049 }
050
051 /**
052 * Specifies the list of endpoints hosted by the component.
053 * @param endpoints
054 * the endpoints to set
055 * @org.apache.xbean.Property description="the list of endpoints hosted by the component"
056 */
057 public void setEndpoints(CxfBcEndpointType[] endpoints) {
058 this.endpoints = endpoints;
059 }
060
061 @Override
062 protected List getConfiguredEndpoints() {
063 return asList(endpoints);
064 }
065
066 @Override
067 protected Class[] getEndpointClasses() {
068 return new Class[] {CxfBcProvider.class, CxfBcConsumer.class};
069 }
070
071 @Override
072 protected void doInit() throws Exception {
073 //Load configuration
074 configuration.setRootDir(context.getWorkspaceRoot());
075 configuration.setComponentName(context.getComponentName());
076 configuration.load();
077 if (configuration.getBusCfg() != null && configuration.getBusCfg().length() > 0) {
078 SpringBusFactory bf = new SpringBusFactory();
079 bus = bf.createBus(configuration.getBusCfg());
080 } else {
081 bus = BusFactory.getDefaultBus();
082 }
083 if (getConfiguration().getAuthenticationService() == null) {
084 try {
085 String name = getConfiguration().getAuthenticationServiceName();
086 Object as = context.getNamingContext().lookup(name);
087 getConfiguration().setAuthenticationService((AuthenticationService) as);
088 } catch (Throwable e) {
089 getConfiguration().setAuthenticationService(new JAASAuthenticationService());
090 }
091 }
092 super.doInit();
093 }
094
095 @Override
096 protected void doShutDown() throws Exception {
097 // Bus should no longer be the thread default since the component's threads will end now
098 if (bus != null) {
099 BusFactory.setThreadDefaultBus(null);
100 }
101 super.doShutDown();
102 }
103
104 public Bus getBus() {
105 return bus;
106 }
107
108 /**
109 * Specifies the location of the CXF configuraiton file used to configure
110 * the CXF bus. This allows you to access features like JMS runtime
111 * behavior and WS-RM. The configuration set at the component level is
112 * superceeded by any configuration specified by an endpoint.
113 *
114 * @param busCfg a string containing the relative path to the configuration file
115 * @org.apache.xbean.Property description="the location of the CXF configuration file used to configure the CXF
116 * bus for all endpoints in the container. Endpoint-specific configuration overrides these settings. This allows
117 * you to configure features like WS-RM and JMS runtime behavior."
118 **/
119 public void setBusConfig(String busConfig) {
120 this.busCfg = busConfig;
121 }
122
123 public String getBusConfig() {
124 return busCfg;
125 }
126
127 public void setConfiguration(CxfBcConfiguration configuration) {
128 this.configuration = configuration;
129 }
130
131 public CxfBcConfiguration getConfiguration() {
132 return configuration;
133 }
134 }