001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with 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,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.endpoint;
019:
020: import java.util.List;
021: import java.util.Map;
022: import java.util.ResourceBundle;
023: import java.util.concurrent.Executor;
024: import java.util.logging.Logger;
025:
026: import javax.xml.namespace.QName;
027:
028: import org.apache.cxf.Bus;
029: import org.apache.cxf.BusException;
030: import org.apache.cxf.BusFactory;
031: import org.apache.cxf.binding.Binding;
032: import org.apache.cxf.binding.BindingFactory;
033: import org.apache.cxf.binding.BindingFactoryManager;
034: import org.apache.cxf.common.i18n.Message;
035: import org.apache.cxf.common.logging.LogUtils;
036: import org.apache.cxf.configuration.Configurable;
037: import org.apache.cxf.feature.AbstractFeature;
038: import org.apache.cxf.interceptor.AbstractAttributedInterceptorProvider;
039: import org.apache.cxf.interceptor.ClientFaultConverter;
040: import org.apache.cxf.interceptor.InFaultChainInitiatorObserver;
041: import org.apache.cxf.interceptor.MessageSenderInterceptor;
042: import org.apache.cxf.interceptor.OutFaultChainInitiatorObserver;
043: import org.apache.cxf.service.Service;
044: import org.apache.cxf.service.model.BindingInfo;
045: import org.apache.cxf.service.model.EndpointInfo;
046: import org.apache.cxf.transport.MessageObserver;
047:
048: public class EndpointImpl extends AbstractAttributedInterceptorProvider
049: implements Endpoint, Configurable {
050:
051: private static final Logger LOG = LogUtils
052: .getL7dLogger(EndpointImpl.class);
053: private static final ResourceBundle BUNDLE = LOG
054: .getResourceBundle();
055:
056: private Service service;
057: private Binding binding;
058: private EndpointInfo endpointInfo;
059: private Executor executor;
060: private Bus bus;
061: private MessageObserver inFaultObserver;
062: private MessageObserver outFaultObserver;
063: private List<AbstractFeature> activeFeatures;
064:
065: public EndpointImpl(Bus bus, Service s, QName endpointName)
066: throws EndpointException {
067: this (bus, s, s.getEndpointInfo(endpointName));
068: }
069:
070: public EndpointImpl(Bus bus, Service s, EndpointInfo ei)
071: throws EndpointException {
072: if (ei == null) {
073: throw new NullPointerException(
074: "EndpointInfo can not be null!");
075: }
076:
077: if (bus == null) {
078: this .bus = BusFactory.getThreadDefaultBus();
079: } else {
080: this .bus = bus;
081: }
082: service = s;
083: endpointInfo = ei;
084:
085: createBinding(endpointInfo.getBinding());
086:
087: inFaultObserver = new InFaultChainInitiatorObserver(bus);
088: outFaultObserver = new OutFaultChainInitiatorObserver(bus);
089:
090: getInFaultInterceptors().add(new ClientFaultConverter());
091: getOutInterceptors().add(new MessageSenderInterceptor());
092: getOutFaultInterceptors().add(new MessageSenderInterceptor());
093: }
094:
095: public String getBeanName() {
096: return endpointInfo.getName().toString() + ".endpoint";
097: }
098:
099: public EndpointInfo getEndpointInfo() {
100: return endpointInfo;
101: }
102:
103: public Service getService() {
104: return service;
105: }
106:
107: public Binding getBinding() {
108: return binding;
109: }
110:
111: public Executor getExecutor() {
112: return executor == null ? service.getExecutor() : executor;
113: }
114:
115: public void setExecutor(Executor e) {
116: executor = e;
117: }
118:
119: public Bus getBus() {
120: return bus;
121: }
122:
123: public void setBus(Bus bus) {
124: this .bus = bus;
125: }
126:
127: final void createBinding(BindingInfo bi) throws EndpointException {
128: if (null != bi) {
129: String namespace = bi.getBindingId();
130: BindingFactory bf = null;
131: try {
132: bf = bus.getExtension(BindingFactoryManager.class)
133: .getBindingFactory(namespace);
134: binding = bf.createBinding(bi);
135: } catch (BusException ex) {
136: throw new EndpointException(ex);
137: }
138: if (null == bf) {
139: Message msg = new Message("NO_BINDING_FACTORY", BUNDLE,
140: namespace);
141: throw new EndpointException(msg);
142: }
143: }
144: }
145:
146: public MessageObserver getInFaultObserver() {
147: return inFaultObserver;
148: }
149:
150: public MessageObserver getOutFaultObserver() {
151: return outFaultObserver;
152: }
153:
154: public void setInFaultObserver(MessageObserver observer) {
155: inFaultObserver = observer;
156: }
157:
158: public void setOutFaultObserver(MessageObserver observer) {
159: outFaultObserver = observer;
160:
161: }
162:
163: /**
164: * Utility method to make it easy to set properties from Spring.
165: *
166: * @param properties
167: */
168: public void setProperties(Map<String, Object> properties) {
169: this .putAll(properties);
170: }
171:
172: /**
173: * @return the list of fearures <b>already</b> activated for this endpoint.
174: */
175: public List<AbstractFeature> getActiveFeatures() {
176: return activeFeatures;
177: }
178:
179: /**
180: * @param the list of fearures <b>already</b> activated for this endpoint.
181: */
182: public void initializeActiveFeatures(List<AbstractFeature> features) {
183: activeFeatures = features;
184: }
185: }
|