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.transport.http_jetty;
019:
020: import java.io.IOException;
021: import java.security.GeneralSecurityException;
022: import java.util.HashMap;
023: import java.util.Map;
024:
025: import javax.annotation.PostConstruct;
026: import javax.annotation.Resource;
027: import javax.imageio.IIOException;
028:
029: import org.apache.cxf.Bus;
030: import org.apache.cxf.service.model.EndpointInfo;
031: import org.apache.cxf.transport.Destination;
032: import org.apache.cxf.transport.http.AbstractHTTPTransportFactory;
033:
034: public class JettyHTTPTransportFactory extends
035: AbstractHTTPTransportFactory {
036:
037: private Map<String, JettyHTTPDestination> destinations = new HashMap<String, JettyHTTPDestination>();
038:
039: public JettyHTTPTransportFactory() {
040: super ();
041: }
042:
043: @Resource(name="bus")
044: public void setBus(Bus b) {
045: super .setBus(b);
046: }
047:
048: @PostConstruct
049: public void finalizeConfig() {
050: // This call will register the server engine factory
051: // with the Bus.
052: getJettyHTTPServerEngineFactory();
053: }
054:
055: /**
056: * This method returns the Jetty HTTP Server Engine Factory.
057: */
058: protected JettyHTTPServerEngineFactory getJettyHTTPServerEngineFactory() {
059: // We have got to *always* get this off the bus, because it may have
060: // been overridden by Spring Configuration initially.
061: // Spring Configuration puts it on the correct bus.
062: JettyHTTPServerEngineFactory serverEngineFactory = getBus()
063: .getExtension(JettyHTTPServerEngineFactory.class);
064: // If it's not there, then create it and register it.
065: // Spring may override it later, but we need it here for default
066: // with no spring configuration.
067: if (serverEngineFactory == null) {
068: serverEngineFactory = new JettyHTTPServerEngineFactory();
069: serverEngineFactory.setBus(getBus());
070: serverEngineFactory.finalizeConfig();
071: }
072: return serverEngineFactory;
073: }
074:
075: @Override
076: public Destination getDestination(EndpointInfo endpointInfo)
077: throws IOException {
078:
079: String addr = endpointInfo.getAddress();
080: JettyHTTPDestination destination = destinations.get(addr);
081: if (destination == null) {
082: destination = createDestination(endpointInfo);
083: }
084:
085: return destination;
086: }
087:
088: private synchronized JettyHTTPDestination createDestination(
089: EndpointInfo endpointInfo) throws IOException {
090:
091: JettyHTTPDestination destination = destinations
092: .get(endpointInfo.getAddress());
093: if (destination == null) {
094: destination = new JettyHTTPDestination(getBus(), this ,
095: endpointInfo);
096:
097: destinations.put(endpointInfo.getAddress(), destination);
098:
099: configure(destination);
100: try {
101: destination.finalizeConfig();
102: } catch (GeneralSecurityException ex) {
103: throw new IIOException("JSSE Security Exception ", ex);
104: }
105: }
106: return destination;
107: }
108:
109: /**
110: * This function removes the destination for a particular endpoint.
111: */
112: void removeDestination(EndpointInfo ei) {
113: destinations.remove(ei.getAddress());
114: }
115: }
|