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.servlet;
019:
020: import java.io.IOException;
021: import java.util.Arrays;
022: import java.util.Collection;
023: import java.util.Collections;
024: import java.util.List;
025: import java.util.Map;
026: import java.util.Set;
027: import java.util.concurrent.ConcurrentHashMap;
028:
029: import javax.annotation.Resource;
030:
031: import org.apache.cxf.Bus;
032: import org.apache.cxf.service.model.EndpointInfo;
033: import org.apache.cxf.transport.Destination;
034: import org.apache.cxf.transport.DestinationFactory;
035: import org.apache.cxf.transport.http.AbstractHTTPTransportFactory;
036:
037: public class ServletTransportFactory extends
038: AbstractHTTPTransportFactory implements DestinationFactory {
039:
040: private Map<String, ServletDestination> destinations = new ConcurrentHashMap<String, ServletDestination>();
041:
042: public ServletTransportFactory(Bus b) {
043: super .setBus(b);
044: List<String> ids = Arrays.asList(new String[] {
045: "http://schemas.xmlsoap.org/wsdl/soap/http",
046: "http://schemas.xmlsoap.org/soap/http",
047: "http://www.w3.org/2003/05/soap/bindings/HTTP/",
048: "http://schemas.xmlsoap.org/wsdl/http/",
049: "http://cxf.apache.org/transports/http/configuration",
050: "http://cxf.apache.org/bindings/xformat", });
051: this .setTransportIds(ids);
052: }
053:
054: public ServletTransportFactory() {
055: }
056:
057: @Resource(name="bus")
058: public void setBus(Bus b) {
059: super .setBus(b);
060: }
061:
062: public void removeDestination(String path) {
063: destinations.remove(path);
064: }
065:
066: public Destination getDestination(EndpointInfo endpointInfo)
067: throws IOException {
068: ServletDestination d = getDestinationForPath(endpointInfo
069: .getAddress());
070: if (d == null) {
071: String path = getTrimmedPath(endpointInfo.getAddress());
072: d = new ServletDestination(getBus(), null, endpointInfo,
073: this , path);
074: destinations.put(path, d);
075: }
076: return d;
077: }
078:
079: public ServletDestination getDestinationForPath(String path) {
080: // to use the url context match
081: return destinations.get(getTrimmedPath(path));
082: }
083:
084: static String getTrimmedPath(String path) {
085: if (path == null) {
086: return "/";
087: }
088: final String lh = "http://localhost/";
089: final String lhs = "https://localhost/";
090:
091: if (path.startsWith(lh)) {
092: path = path.substring(lh.length());
093: } else if (path.startsWith(lhs)) {
094: path = path.substring(lhs.length());
095: }
096: if (!path.startsWith("/")) {
097: path = "/" + path;
098:
099: }
100: return path;
101: }
102:
103: public Collection<ServletDestination> getDestinations() {
104: return Collections
105: .unmodifiableCollection(destinations.values());
106: }
107:
108: public Set<String> getDestinationsPaths() {
109: return Collections.unmodifiableSet(destinations.keySet());
110: }
111:
112: }
|