Author: cschneider
Date: Wed Dec 8 07:52:24 2010
New Revision: 1043328
URL: http://svn.apache.org/viewvc?rev=1043328&view=rev
Log:
CXF-3160 Patch 3: Reduce Code duplication between http transport variants -
using DestinationRegistry for all http transport variants
Added:
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/DestinationRegistry.java
- copied, changed from r1042434,
cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiDestinationRegistryIntf.java
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/DestinationRegistryImpl.java
- copied, changed from r1042434,
cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiDestinationRegistry.java
Modified:
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPTransportFactory.java
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletTransportFactory.java
cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java
Modified:
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java?rev=1043328&r1=1043327&r2=1043328&view=diff
==============================================================================
---
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
(original)
+++
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
Wed Dec 8 07:52:24 2010
@@ -95,6 +95,8 @@ public abstract class AbstractHTTPDestin
private static final long serialVersionUID = 1L;
protected final Bus bus;
+ protected final DestinationRegistry registry;
+ protected final String path;
// Configuration values
protected HTTPServerPolicy server;
@@ -114,12 +116,15 @@ public abstract class AbstractHTTPDestin
* @throws IOException
*/
public AbstractHTTPDestination(Bus b,
+ DestinationRegistry registry,
EndpointInfo ei,
+ String path,
boolean dp)
throws IOException {
super(b, getTargetReference(getAddressValue(ei, dp), b), ei);
- bus = b;
-
+ this.bus = b;
+ this.registry = registry;
+ this.path = path;
try {
ServletRequest.class.getMethod("isAsyncSupported");
isServlet3 = true;
@@ -691,4 +696,9 @@ public abstract class AbstractHTTPDestin
return PolicyUtils.HTTPSERVERPOLICY_ASSERTION_QNAME.equals(type);
}
+ @Override
+ public void shutdown() {
+ registry.removeDestination(path);
+ super.shutdown();
+ }
}
Modified:
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPTransportFactory.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPTransportFactory.java?rev=1043328&r1=1043327&r2=1043328&view=diff
==============================================================================
---
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPTransportFactory.java
(original)
+++
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPTransportFactory.java
Wed Dec 8 07:52:24 2010
@@ -56,11 +56,24 @@ public abstract class AbstractHTTPTransp
URI_PREFIXES.add("https://");
}
+ protected final DestinationRegistry registry;
+
+ public AbstractHTTPTransportFactory() {
+ this(new DestinationRegistryImpl());
+ }
+
+ public AbstractHTTPTransportFactory(DestinationRegistry registry) {
+ this.registry = registry;
+ }
+
+ public DestinationRegistry getRegistry() {
+ return registry;
+ }
+
/**
* This call is used by CXF ExtensionManager to inject the
activationNamespaces
* @param ans The transport ids.
*/
-
public void setActivationNamespaces(Collection<String> ans) {
setTransportIds(new ArrayList<String>(ans));
}
Copied:
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/DestinationRegistry.java
(from r1042434,
cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiDestinationRegistryIntf.java)
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/DestinationRegistry.java?p2=cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/DestinationRegistry.java&p1=cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiDestinationRegistryIntf.java&r1=1042434&r2=1043328&rev=1043328&view=diff
==============================================================================
---
cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiDestinationRegistryIntf.java
(original)
+++
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/DestinationRegistry.java
Wed Dec 8 07:52:24 2010
@@ -16,23 +16,29 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.cxf.transport.http_osgi;
+package org.apache.cxf.transport.http;
import java.util.Collection;
+import java.util.List;
import java.util.Set;
-import org.apache.cxf.transport.http.AbstractHTTPDestination;
-public interface OsgiDestinationRegistryIntf {
+public interface DestinationRegistry {
void addDestination(String path, AbstractHTTPDestination destination);
void removeDestination(String path);
AbstractHTTPDestination getDestinationForPath(String path);
+ AbstractHTTPDestination getDestinationForPath(String path, boolean
tryDecoding);
+
AbstractHTTPDestination checkRestfulRequest(String address);
Collection<AbstractHTTPDestination> getDestinations();
+
+ List<AbstractHTTPDestination> getSortedDestinations();
Set<String> getDestinationsPaths();
+
+ String getTrimmedPath(String path);
}
Copied:
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/DestinationRegistryImpl.java
(from r1042434,
cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiDestinationRegistry.java)
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/DestinationRegistryImpl.java?p2=cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/DestinationRegistryImpl.java&p1=cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiDestinationRegistry.java&r1=1042434&r2=1043328&rev=1043328&view=diff
==============================================================================
---
cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiDestinationRegistry.java
(original)
+++
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/DestinationRegistryImpl.java
Wed Dec 8 07:52:24 2010
@@ -16,50 +16,104 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.cxf.transport.http_osgi;
+package org.apache.cxf.transport.http;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
import java.util.Collection;
import java.util.Collections;
+import java.util.Comparator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import org.apache.cxf.transport.http.AbstractHTTPDestination;
-
-public class OsgiDestinationRegistry implements OsgiDestinationRegistryIntf {
+public class DestinationRegistryImpl implements DestinationRegistry {
private ConcurrentMap<String, AbstractHTTPDestination> destinations
= new ConcurrentHashMap<String, AbstractHTTPDestination>();
+ private Map<String, AbstractHTTPDestination> decodedDestinations =
+ new ConcurrentHashMap<String, AbstractHTTPDestination>();
- public OsgiDestinationRegistry() {
+ public DestinationRegistryImpl() {
}
public void addDestination(String path, AbstractHTTPDestination
destination) {
String p = getTrimmedPath(path);
destinations.putIfAbsent(p, destination);
+ try {
+ decodedDestinations.put(URLDecoder.decode(p, "ISO-8859-1"),
destination);
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException("Unsupported Encoding", e);
+ }
}
public void removeDestination(String path) {
destinations.remove(path);
+ try {
+ decodedDestinations.remove(URLDecoder.decode(path, "ISO-8859-1"));
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException("Unsupported Encoding", e);
+ }
}
public AbstractHTTPDestination getDestinationForPath(String path) {
- // to use the url context match
- return destinations.get(getTrimmedPath(path));
+ return getDestinationForPath(path, false);
+ }
+
+ public AbstractHTTPDestination getDestinationForPath(String path, boolean
tryDecoding) {
+ // to use the url context match
+ String m = getTrimmedPath(path);
+ AbstractHTTPDestination s = destinations.get(m);
+ if (s == null) {
+ s = decodedDestinations.get(m);
+ }
+ return s;
}
public AbstractHTTPDestination checkRestfulRequest(String address) {
- for (String path : getDestinationsPaths()) {
- if (address.startsWith(path)) {
- return getDestinationForPath(path);
+ int len = -1;
+ AbstractHTTPDestination ret = null;
+ for (String path : getDestinationsPaths()) {
+ if (address.startsWith(path)
+ && path.length() > len) {
+ ret = getDestinationForPath(path);
+ len = path.length();
}
}
- return null;
+ if (ret != null && ret.getMessageObserver() == null) {
+ return null;
+ }
+ return ret;
}
public Collection<AbstractHTTPDestination> getDestinations() {
return Collections.unmodifiableCollection(destinations.values());
}
+
+
+ public List<AbstractHTTPDestination> getSortedDestinations() {
+ List<AbstractHTTPDestination> dest2 = new
LinkedList<AbstractHTTPDestination>(
+ getDestinations());
+ Collections.sort(dest2, new Comparator<AbstractHTTPDestination>() {
+ public int compare(AbstractHTTPDestination o1,
AbstractHTTPDestination o2) {
+ if (o1.getEndpointInfo().getInterface() == null) {
+ return -1;
+ }
+ if (o2.getEndpointInfo().getInterface() == null) {
+ return 1;
+ }
+ return o1.getEndpointInfo().getInterface().getName()
+ .getLocalPart().compareTo(
+ o2.getEndpointInfo().getInterface().getName()
+ .getLocalPart());
+ }
+ });
+
+ return dest2;
+ }
public Set<String> getDestinationsPaths() {
return Collections.unmodifiableSet(destinations.keySet());
@@ -71,7 +125,7 @@ public class OsgiDestinationRegistry imp
* @param path
* @return trimmed path
*/
- static String getTrimmedPath(String path) {
+ public String getTrimmedPath(String path) {
if (path == null) {
return "/";
}
@@ -83,7 +137,7 @@ public class OsgiDestinationRegistry imp
} else if (path.startsWith(lhs)) {
path = path.substring(lhs.length());
}
- if (!path.startsWith("/")) {
+ if (!path.contains("://") && !path.startsWith("/")) {
path = "/" + path;
}
Modified:
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java?rev=1043328&r1=1043327&r2=1043328&view=diff
==============================================================================
---
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
(original)
+++
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
Wed Dec 8 07:52:24 2010
@@ -54,11 +54,10 @@ public abstract class AbstractCXFServlet
public ServletController createServletController(ServletConfig
servletConfig) {
ServletController newController =
- new ServletController(servletTransportFactory,
+ new ServletController(servletTransportFactory.getRegistry(),
servletConfig,
- this.getServletContext(),
bus);
-
+ servletTransportFactory.setServletController(newController);
if (servletConfig.getInitParameter("disable-address-updates") == null)
{
newController.setDisableAddressUpdates(disableAddressUpdates);
}
Modified:
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java?rev=1043328&r1=1043327&r2=1043328&view=diff
==============================================================================
---
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
(original)
+++
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
Wed Dec 8 07:52:24 2010
@@ -23,9 +23,6 @@ import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.URL;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -33,7 +30,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -45,6 +41,8 @@ import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.service.model.EndpointInfo;
import org.apache.cxf.service.model.OperationInfo;
+import org.apache.cxf.transport.http.AbstractHTTPDestination;
+import org.apache.cxf.transport.http.DestinationRegistry;
import org.apache.cxf.transports.http.QueryHandler;
import org.apache.cxf.transports.http.QueryHandlerRegistry;
import org.apache.cxf.wsdl.http.AddressType;
@@ -53,21 +51,17 @@ public class ServletController extends A
private static final Logger LOG =
LogUtils.getL7dLogger(ServletController.class);
- private ServletTransportFactory transport;
private Bus bus;
private volatile String lastBase = "";
+
+ private final DestinationRegistry destinationRegistry;
- public ServletController(ServletTransportFactory df,
+ public ServletController(DestinationRegistry destinationRegistry,
ServletConfig config,
- ServletContext context,
Bus b) {
super(config);
- this.transport = df;
+ this.destinationRegistry = destinationRegistry;
this.bus = b;
- this.transport.setServletController(this);
- }
-
- ServletController() {
}
String getLastBaseURL() {
@@ -81,9 +75,9 @@ public class ServletController extends A
if (base.equals(lastBase)) {
return;
}
- Set<String> paths = transport.getDestinationsPaths();
+ Set<String> paths = destinationRegistry.getDestinationsPaths();
for (String path : paths) {
- ServletDestination d2 = transport.getDestinationForPath(path);
+ AbstractHTTPDestination d2 =
destinationRegistry.getDestinationForPath(path);
String ad = d2.getEndpointInfo().getAddress();
if (ad == null
&& d2.getAddress() != null
@@ -112,14 +106,15 @@ public class ServletController extends A
lastBase = base;
}
- public void invoke(HttpServletRequest request, HttpServletResponse res)
throws ServletException {
+ public void invoke(HttpServletRequest request, HttpServletResponse res)
+ throws ServletException {
try {
EndpointInfo ei = new EndpointInfo();
String address = request.getPathInfo() == null ? "" :
request.getPathInfo();
ei.setAddress(address);
- ServletDestination d = getDestination(ei.getAddress());
+ AbstractHTTPDestination d =
destinationRegistry.getDestinationForPath(ei.getAddress(), true);
if (d == null) {
if (!isHideServiceList &&
(request.getRequestURI().endsWith(serviceListRelativePath)
||
request.getRequestURI().endsWith(serviceListRelativePath + "/")
@@ -135,8 +130,8 @@ public class ServletController extends A
generateServiceList(request, res);
}
} else {
- d = checkRestfulRequest(request);
- if (d == null || d.getMessageObserver() == null) {
+ d = destinationRegistry.checkRestfulRequest(address);
+ if (d == null) {
LOG.warning("Can't find the request for "
+ request.getRequestURL() + "'s Observer
");
generateNotFound(request, res);
@@ -193,26 +188,8 @@ public class ServletController extends A
throw new ServletException(e);
}
}
-
- protected ServletDestination getDestination(String address) {
- return (ServletDestination)transport.getDestinationForPath(address,
true);
- }
-
- protected ServletDestination checkRestfulRequest(HttpServletRequest
request) throws IOException {
-
- String address = request.getPathInfo() == null ? "" :
request.getPathInfo();
-
- int len = -1;
- ServletDestination ret = null;
- for (String path : transport.getDestinationsPaths()) {
- if (address.startsWith(path)
- && path.length() > len) {
- ret = transport.getDestinationForPath(path);
- len = path.length();
- }
- }
- return ret;
- }
+
+
@SuppressWarnings("unchecked")
protected void generateServiceList(HttpServletRequest request,
HttpServletResponse response)
@@ -239,7 +216,7 @@ public class ServletController extends A
}
response.getWriter().write("</head><body>");
- List<ServletDestination> destinations = getServletDestinations();
+ List<AbstractHTTPDestination> destinations =
destinationRegistry.getSortedDestinations();
if (destinations.size() > 0) {
List<String> privateEndpoints =
@@ -256,13 +233,13 @@ public class ServletController extends A
response.getWriter().write("</body></html>");
}
- private void writeSOAPEndpoints(HttpServletResponse response,
List<ServletDestination> destinations,
+ private void writeSOAPEndpoints(HttpServletResponse response,
List<AbstractHTTPDestination> destinations,
List<String> privateEndpoints, Map<String,
String> atomMap)
throws IOException {
response.getWriter().write("<span class=\"heading\">Available SOAP
services:</span><br/>");
response.getWriter().write("<table " + (serviceListStyleSheet == null
? "cellpadding=\"1\" cellspacing=\"1\" border=\"1\"
width=\"100%\"" : "") + ">");
- for (ServletDestination sd : destinations) {
+ for (AbstractHTTPDestination sd : destinations) {
if (null != sd.getEndpointInfo().getName()
&& null != sd.getEndpointInfo().getInterface()
@@ -296,12 +273,14 @@ public class ServletController extends A
}
- private void writeRESTfulEndpoints(HttpServletResponse response,
List<ServletDestination> destinations,
- List<String> privateEndpoints,
Map<String, String> atomMap)
+ private void writeRESTfulEndpoints(HttpServletResponse response,
+ List<AbstractHTTPDestination>
destinations,
+ List<String> privateEndpoints,
+ Map<String, String> atomMap)
throws IOException {
- List<ServletDestination> restfulDests = new
ArrayList<ServletDestination>();
- for (ServletDestination sd : destinations) {
+ List<AbstractHTTPDestination> restfulDests = new
ArrayList<AbstractHTTPDestination>();
+ for (AbstractHTTPDestination sd : destinations) {
// use some more reasonable check - though this one seems to be
the only option at the moment
if (null == sd.getEndpointInfo().getInterface()
&& !isPrivate(sd.getEndpointInfo(), privateEndpoints)) {
@@ -315,7 +294,7 @@ public class ServletController extends A
response.getWriter().write("<span class=\"heading\">Available RESTful
services:</span><br/>");
response.getWriter().write("<table " + (serviceListStyleSheet == null
? "cellpadding=\"1\" cellspacing=\"1\" border=\"1\"
width=\"100%\"" : "") + ">");
- for (ServletDestination sd : restfulDests) {
+ for (AbstractHTTPDestination sd : restfulDests) {
response.getWriter().write("<tr><td>");
String address = sd.getEndpointInfo().getAddress();
response.getWriter().write("<span class=\"field\">Endpoint
address:</span> "
@@ -373,32 +352,12 @@ public class ServletController extends A
}
}
- private List<ServletDestination> getServletDestinations() {
- List<ServletDestination> destinations = new
LinkedList<ServletDestination>(
- transport.getDestinations());
- Collections.sort(destinations, new Comparator<ServletDestination>() {
- public int compare(ServletDestination o1, ServletDestination o2) {
- if (o1.getEndpointInfo().getInterface() == null) {
- return -1;
- }
- if (o2.getEndpointInfo().getInterface() == null) {
- return 1;
- }
- return o1.getEndpointInfo().getInterface().getName()
- .getLocalPart().compareTo(
- o2.getEndpointInfo().getInterface().getName()
- .getLocalPart());
- }
- });
-
- return destinations;
- }
protected void generateUnformattedServiceList(HttpServletRequest request,
HttpServletResponse response) throws IOException {
response.setContentType("text/plain; charset=UTF-8");
- List<ServletDestination> destinations = getServletDestinations();
+ List<AbstractHTTPDestination> destinations =
destinationRegistry.getSortedDestinations();
if (destinations.size() > 0) {
writeUnformattedSOAPEndpoints(response, destinations,
request.getParameter("wsdlList"));
writeUnformattedRESTfulEndpoints(response, destinations);
@@ -408,12 +367,12 @@ public class ServletController extends A
}
private void writeUnformattedSOAPEndpoints(HttpServletResponse response,
- List<ServletDestination>
destinations,
+ List<AbstractHTTPDestination>
destinations,
Object renderParam)
throws IOException {
boolean renderWsdlList = "true".equals(renderParam);
- for (ServletDestination sd : destinations) {
+ for (AbstractHTTPDestination sd : destinations) {
if (null != sd.getEndpointInfo().getInterface()) {
@@ -430,9 +389,9 @@ public class ServletController extends A
}
private void writeUnformattedRESTfulEndpoints(HttpServletResponse response,
- List<ServletDestination>
destinations)
+
List<AbstractHTTPDestination> destinations)
throws IOException {
- for (ServletDestination sd : destinations) {
+ for (AbstractHTTPDestination sd : destinations) {
if (null == sd.getEndpointInfo().getInterface()) {
String address = sd.getEndpointInfo().getAddress();
response.getWriter().write(address + "?_wadl&_type=xml");
Modified:
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java?rev=1043328&r1=1043327&r2=1043328&view=diff
==============================================================================
---
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java
(original)
+++
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java
Wed Dec 8 07:52:24 2010
@@ -27,16 +27,14 @@ import org.apache.cxf.Bus;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.service.model.EndpointInfo;
import org.apache.cxf.transport.http.AbstractHTTPDestination;
+import org.apache.cxf.transport.http.DestinationRegistry;
public class ServletDestination extends AbstractHTTPDestination {
static final Logger LOG = LogUtils.getL7dLogger(ServletDestination.class);
- private static final long serialVersionUID = 1L;
-
- final ServletTransportFactory factory;
- final String path;
+ private static final long serialVersionUID = 1L;
/**
* Constructor, allowing subsititution of configuration.
@@ -48,14 +46,12 @@ public class ServletDestination extends
* @throws IOException
*/
public ServletDestination(Bus b,
+ DestinationRegistry registry,
EndpointInfo ei,
- ServletTransportFactory fact,
- String p)
+ String path)
throws IOException {
// would add the default port to the address
- super(b, ei, false);
- factory = fact;
- path = p;
+ super(b, registry, ei, path, false);
}
@@ -75,16 +71,5 @@ public class ServletDestination extends
return contextPath + address;
}
-
- @Override
- public void shutdown() {
- try {
- factory.removeDestination(path);
- } catch (IOException ex) {
- //ignore
- }
-
- super.shutdown();
- }
-
+
}
Modified:
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletTransportFactory.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletTransportFactory.java?rev=1043328&r1=1043327&r2=1043328&view=diff
==============================================================================
---
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletTransportFactory.java
(original)
+++
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletTransportFactory.java
Wed Dec 8 07:52:24 2010
@@ -21,14 +21,8 @@
package org.apache.cxf.transport.servlet;
import java.io.IOException;
-import java.net.URLDecoder;
import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Resource;
@@ -37,17 +31,13 @@ import org.apache.cxf.common.util.String
import org.apache.cxf.service.model.EndpointInfo;
import org.apache.cxf.transport.Destination;
import org.apache.cxf.transport.DestinationFactory;
+import org.apache.cxf.transport.http.AbstractHTTPDestination;
import org.apache.cxf.transport.http.AbstractHTTPTransportFactory;
import org.apache.cxf.wsdl.http.AddressType;
public class ServletTransportFactory extends AbstractHTTPTransportFactory
implements DestinationFactory {
-
- private Map<String, ServletDestination> destinations =
- new ConcurrentHashMap<String, ServletDestination>();
- private Map<String, ServletDestination> decodedDestinations =
- new ConcurrentHashMap<String, ServletDestination>();
-
+
private ServletController controller;
public ServletTransportFactory(Bus b) {
@@ -72,21 +62,15 @@ public class ServletTransportFactory ext
public void setBus(Bus b) {
super.setBus(b);
}
-
- public void removeDestination(String path) throws IOException {
- destinations.remove(path);
- decodedDestinations.remove(URLDecoder.decode(path, "ISO-8859-1"));
- }
-
+
public Destination getDestination(EndpointInfo endpointInfo)
throws IOException {
- ServletDestination d =
getDestinationForPath(endpointInfo.getAddress());
+ AbstractHTTPDestination d =
registry.getDestinationForPath(endpointInfo.getAddress());
if (d == null) {
- String path = getTrimmedPath(endpointInfo.getAddress());
- d = new ServletDestination(getBus(), endpointInfo, this, path);
- destinations.put(path, d);
- decodedDestinations.put(URLDecoder.decode(path, "ISO-8859-1"), d);
-
+ String path = registry.getTrimmedPath(endpointInfo.getAddress());
+ d = new ServletDestination(getBus(), registry, endpointInfo, path);
+ registry.addDestination(path, d);
+
if (controller != null
&& !StringUtils.isEmpty(controller.getLastBaseURL())) {
String ad = d.getEndpointInfo().getAddress();
@@ -103,45 +87,5 @@ public class ServletTransportFactory ext
}
return d;
}
-
- public ServletDestination getDestinationForPath(String path) {
- return getDestinationForPath(path, false);
- }
- public ServletDestination getDestinationForPath(String path, boolean
tryDecoding) {
- // to use the url context match
- String m = getTrimmedPath(path);
- ServletDestination s = destinations.get(m);
- if (s == null) {
- s = decodedDestinations.get(m);
- }
- return s;
- }
-
- static String getTrimmedPath(String path) {
- if (path == null) {
- return "/";
- }
- final String lh = "http://localhost/";
- final String lhs = "https://localhost/";
-
- if (path.startsWith(lh)) {
- path = path.substring(lh.length());
- } else if (path.startsWith(lhs)) {
- path = path.substring(lhs.length());
- }
- if (!path.startsWith("/")) {
- path = "/" + path;
-
- }
- return path;
- }
-
- public Collection<ServletDestination> getDestinations() {
- return Collections.unmodifiableCollection(destinations.values());
- }
- public Set<String> getDestinationsPaths() {
- return Collections.unmodifiableSet(destinations.keySet());
- }
-
-
+
}
Modified:
cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java?rev=1043328&r1=1043327&r2=1043328&view=diff
==============================================================================
---
cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java
(original)
+++
cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java
Wed Dec 8 07:52:24 2010
@@ -24,8 +24,8 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.apache.cxf.transport.MessageObserver;
import org.apache.cxf.transport.http.AbstractHTTPDestination;
+import org.apache.cxf.transport.http.DestinationRegistry;
import org.easymock.classextension.EasyMock;
import org.junit.Assert;
@@ -36,11 +36,13 @@ public class ServletControllerTest exten
private HttpServletRequest req;
private HttpServletResponse res;
+ private DestinationRegistry registry;
@Before
public void setUp() {
req = EasyMock.createMock(HttpServletRequest.class);
res = EasyMock.createMock(HttpServletResponse.class);
+ registry = EasyMock.createMock(DestinationRegistry.class);
}
@Test
@@ -54,7 +56,7 @@ public class ServletControllerTest exten
req.getParameter("formatted");
EasyMock.expectLastCall().andReturn("true");
EasyMock.replay(req);
- TestServletController sc = new TestServletController();
+ TestServletController sc = new TestServletController(registry);
sc.invoke(req, res);
assertTrue(sc.generateListCalled());
assertFalse(sc.generateUnformattedCalled());
@@ -72,7 +74,7 @@ public class ServletControllerTest exten
req.getParameter("formatted");
EasyMock.expectLastCall().andReturn("false");
EasyMock.replay(req);
- TestServletController sc = new TestServletController();
+ TestServletController sc = new TestServletController(registry);
sc.invoke(req, res);
assertFalse(sc.generateListCalled());
assertTrue(sc.generateUnformattedCalled());
@@ -83,8 +85,14 @@ public class ServletControllerTest exten
public void testHideServiceListing() throws Exception {
req.getPathInfo();
EasyMock.expectLastCall().andReturn(null);
+ registry.getDestinationForPath("", true);
+ EasyMock.expectLastCall().andReturn(null).atLeastOnce();
+ AbstractHTTPDestination dest =
EasyMock.createMock(AbstractHTTPDestination.class);
+ registry.checkRestfulRequest("");
+ EasyMock.expectLastCall().andReturn(dest).atLeastOnce();
EasyMock.replay(req);
- TestServletController sc = new TestServletController();
+ EasyMock.replay(registry);
+ TestServletController sc = new TestServletController(registry);
sc.setHideServiceList(true);
sc.invoke(req, res);
assertFalse(sc.generateListCalled());
@@ -103,7 +111,7 @@ public class ServletControllerTest exten
req.getParameter("formatted");
EasyMock.expectLastCall().andReturn("true");
EasyMock.replay(req);
- TestServletController sc = new TestServletController();
+ TestServletController sc = new TestServletController(registry);
sc.setServiceListRelativePath("/listing");
sc.invoke(req, res);
assertTrue(sc.generateListCalled());
@@ -119,7 +127,7 @@ public class ServletControllerTest exten
req.getPathInfo();
EasyMock.expectLastCall().andReturn("/bar").anyTimes();
EasyMock.replay(req);
- String url = new ServletController().getBaseURL(req);
+ String url = new ServletController(null, null, null).getBaseURL(req);
assertEquals("http://localhost:8080/services", url);
}
@@ -132,7 +140,7 @@ public class ServletControllerTest exten
req.getPathInfo();
EasyMock.expectLastCall().andReturn("/bar").anyTimes();
EasyMock.replay(req);
- String url = new ServletController().getBaseURL(req);
+ String url = new ServletController(null, null, null).getBaseURL(req);
assertEquals("http://localhost:8080/services", url);
}
@@ -145,7 +153,7 @@ public class ServletControllerTest exten
req.getPathInfo();
EasyMock.expectLastCall().andReturn("/bar").anyTimes();
EasyMock.replay(req);
- String url = new ServletController().getBaseURL(req);
+ String url = new ServletController(null, null, null).getBaseURL(req);
assertEquals("http://localhost:8080/services", url);
}
@@ -158,7 +166,7 @@ public class ServletControllerTest exten
req.getPathInfo();
EasyMock.expectLastCall().andReturn("/bar;a=b;c=d").anyTimes();
EasyMock.replay(req);
- String url = new ServletController().getBaseURL(req);
+ String url = new ServletController(null, null, null).getBaseURL(req);
assertEquals("http://localhost:8080/services", url);
}
@@ -171,7 +179,7 @@ public class ServletControllerTest exten
req.getPathInfo();
EasyMock.expectLastCall().andReturn("/bar;a=b").anyTimes();
EasyMock.replay(req);
- String url = new ServletController().getBaseURL(req);
+ String url = new ServletController(null, null, null).getBaseURL(req);
assertEquals("http://localhost:8080/services", url);
}
@@ -184,35 +192,24 @@ public class ServletControllerTest exten
req.getPathInfo();
EasyMock.expectLastCall().andReturn("/bar;a=b").anyTimes();
EasyMock.replay(req);
- String url = new ServletController().getBaseURL(req);
+ String url = new ServletController(null, null, null).getBaseURL(req);
assertEquals("http://localhost:8080/services", url);
}
public static class TestServletController extends ServletController {
-
+
private boolean generateListCalled;
private boolean generateUnformattedCalled;
private boolean invokeDestinationCalled;
-
- @Override
- protected ServletDestination getDestination(String address) {
- return null;
+
+ public TestServletController(DestinationRegistry destinationRegistry) {
+ super(destinationRegistry, null, null);
}
@Override
protected void updateDests(HttpServletRequest request) {
}
-
- @Override
- protected ServletDestination checkRestfulRequest(HttpServletRequest
request)
- throws IOException {
- ServletDestination sd =
EasyMock.createMock(ServletDestination.class);
- sd.getMessageObserver();
-
EasyMock.expectLastCall().andReturn(EasyMock.createMock(MessageObserver.class));
- EasyMock.replay(sd);
- return sd;
- }
@Override
public void invokeDestination(final HttpServletRequest request,
HttpServletResponse response,