Author: cschneider
Date: Thu Mar 24 21:29:58 2011
New Revision: 1085152
URL: http://svn.apache.org/viewvc?rev=1085152&view=rev
Log:
CXF-3419 Removed most of the osgi transport code
Added:
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/BaseUrlHelper.java
cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/servicelist/
cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/servicelist/BaseUrlHelperTest.java
Removed:
cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiDestination.java
cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiServletController.java
cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiTransportFactory.java
cxf/trunk/rt/transports/http-osgi/src/test/java/org/apache/cxf/transport/http_osgi/OsgiDestinationTest.java
cxf/trunk/rt/transports/http-osgi/src/test/java/org/apache/cxf/transport/http_osgi/OsgiTransportFactoryTest.java
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractServletController.java
Modified:
cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiServlet.java
cxf/trunk/rt/transports/http-osgi/src/main/resources/META-INF/cxf/osgi/cxf-extension-osgi.xml
cxf/trunk/rt/transports/http-osgi/src/test/java/org/apache/cxf/transport/http_osgi/OsgiServletTest.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/ServletTransportFactory.java
cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java
Modified:
cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiServlet.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiServlet.java?rev=1085152&r1=1085151&r2=1085152&view=diff
==============================================================================
---
cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiServlet.java
(original)
+++
cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiServlet.java
Thu Mar 24 21:29:58 2011
@@ -26,12 +26,13 @@ import javax.servlet.http.HttpServletRes
import org.apache.cxf.transport.http.DestinationRegistry;
import org.apache.cxf.transport.servlet.AbstractHTTPServlet;
+import org.apache.cxf.transport.servlet.ServletController;
import
org.apache.cxf.transport.servlet.servicelist.ServiceListGeneratorServlet;
public class OsgiServlet extends AbstractHTTPServlet {
private DestinationRegistry destinationRegistry;
- private OsgiServletController controller;
+ private ServletController controller;
private HttpServlet serviceListGenerator;
public OsgiServlet(DestinationRegistry destinationRegistry) {
@@ -45,9 +46,9 @@ public class OsgiServlet extends Abstrac
public void init(ServletConfig servletConfig) throws ServletException {
super.init(servletConfig);
- controller = new OsgiServletController(servletConfig,
- this.destinationRegistry,
- serviceListGenerator);
+ controller = new ServletController(this.destinationRegistry,
+ servletConfig,
+ serviceListGenerator);
}
@Override
Modified:
cxf/trunk/rt/transports/http-osgi/src/main/resources/META-INF/cxf/osgi/cxf-extension-osgi.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-osgi/src/main/resources/META-INF/cxf/osgi/cxf-extension-osgi.xml?rev=1085152&r1=1085151&r2=1085152&view=diff
==============================================================================
---
cxf/trunk/rt/transports/http-osgi/src/main/resources/META-INF/cxf/osgi/cxf-extension-osgi.xml
(original)
+++
cxf/trunk/rt/transports/http-osgi/src/main/resources/META-INF/cxf/osgi/cxf-extension-osgi.xml
Thu Mar 24 21:29:58 2011
@@ -24,12 +24,10 @@
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd">
- <bean id="org.apache.cxf.transport.http_osgi.OsgiTransportFactory"
- class="org.apache.cxf.transport.http_osgi.OsgiTransportFactory"
+ <bean id="ServletTransportFactory"
+ class="org.apache.cxf.transport.servlet.ServletTransportFactory"
lazy-init="true">
-
<constructor-arg ref="osgiDestinationRegistry"/>
-
<property name="bus" ref="cxf"/>
</bean>
Modified:
cxf/trunk/rt/transports/http-osgi/src/test/java/org/apache/cxf/transport/http_osgi/OsgiServletTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-osgi/src/test/java/org/apache/cxf/transport/http_osgi/OsgiServletTest.java?rev=1085152&r1=1085151&r2=1085152&view=diff
==============================================================================
---
cxf/trunk/rt/transports/http-osgi/src/test/java/org/apache/cxf/transport/http_osgi/OsgiServletTest.java
(original)
+++
cxf/trunk/rt/transports/http-osgi/src/test/java/org/apache/cxf/transport/http_osgi/OsgiServletTest.java
Thu Mar 24 21:29:58 2011
@@ -43,6 +43,7 @@ import org.apache.cxf.transport.Abstract
import org.apache.cxf.transport.MessageObserver;
import org.apache.cxf.transport.http.AbstractHTTPDestination;
import org.apache.cxf.transport.http.DestinationRegistry;
+import org.apache.cxf.transport.servlet.ServletController;
import org.apache.cxf.transports.http.QueryHandler;
import org.apache.cxf.transports.http.QueryHandlerRegistry;
import org.apache.cxf.wsdl.http.AddressType;
@@ -57,14 +58,14 @@ import org.junit.Test;
public class OsgiServletTest extends Assert {
- private final class TestOsgiServletController extends
OsgiServletController {
+ private final class TestOsgiServletController extends ServletController {
private boolean invokeDestinationCalled;
private TestOsgiServletController(ServletConfig config,
DestinationRegistry
destinationRegistry,
HttpServlet serviceListGenerator) {
- super(config, destinationRegistry, serviceListGenerator);
+ super(destinationRegistry, config, serviceListGenerator);
}
@Override
@@ -200,15 +201,15 @@ public class OsgiServletTest extends Ass
@Test
public void testInvokeRestful() throws Exception {
setUpRequest(URI, null, -1);
- EasyMock.expect(request.getContextPath()).andReturn("");
- EasyMock.expect(request.getServletPath()).andReturn("/cxf");
+ //EasyMock.expect(request.getContextPath()).andReturn("");
+ //EasyMock.expect(request.getServletPath()).andReturn("/cxf");
paths.add(PATH);
EasyMock.expect(registry.getDestinationForPath(PATH)).andReturn(destination).anyTimes();
EasyMock.expect(registry.checkRestfulRequest(EasyMock.isA(String.class))).andReturn(destination);
EasyMock.expect(destination.getMessageObserver()).andReturn(observer);
endpoint.addExtensor(extensor);
- extensor.setLocation(EasyMock.eq(ROOT + URI));
- EasyMock.expectLastCall();
+ //extensor.setLocation(EasyMock.eq(ROOT + URI));
+ //EasyMock.expectLastCall();
control.replay();
OsgiServlet servlet = new OsgiServlet(registry);
@@ -234,10 +235,8 @@ public class OsgiServletTest extends Ass
EasyMock.expect(registry.getDestinationForPath(path,
true)).andReturn(destination);
}
- if (destinationCount == -1) {
-
EasyMock.expect(registry.getDestinationsPaths()).andReturn(paths).anyTimes();
- } else if (destinationCount >= 0) {
- EasyMock.expect(registry.getDestinationsPaths()).andReturn(paths);
+
EasyMock.expect(registry.getDestinationsPaths()).andReturn(paths).anyTimes();
+ if (destinationCount >= 0) {
List<AbstractHTTPDestination> destinations =
new ArrayList<AbstractHTTPDestination>();
for (int i = 0; i < destinationCount; i++) {
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=1085152&r1=1085151&r2=1085152&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
Thu Mar 24 21:29:58 2011
@@ -35,6 +35,7 @@ import org.apache.cxf.BusFactory;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.transport.DestinationFactory;
import org.apache.cxf.transport.DestinationFactoryManager;
+import org.apache.cxf.transport.http.DestinationRegistryImpl;
import
org.apache.cxf.transport.servlet.servicelist.ServiceListGeneratorServlet;
@@ -47,9 +48,7 @@ public abstract class AbstractCXFServlet
protected Bus bus;
protected ServletTransportFactory servletTransportFactory;
protected ServletController controller;
-
- private boolean disableAddressUpdates;
-
+
public static Logger getLogger() {
return LogUtils.getL7dLogger(AbstractCXFServlet.class);
}
@@ -61,9 +60,6 @@ public abstract class AbstractCXFServlet
new ServletController(servletTransportFactory.getRegistry(),
servletConfig,
serviceListGeneratorServlet);
- if (servletConfig.getInitParameter("disable-address-updates") == null)
{
- newController.setDisableAddressUpdates(disableAddressUpdates);
- }
return newController;
}
@@ -97,7 +93,9 @@ public abstract class AbstractCXFServlet
protected DestinationFactory createServletTransportFactory() {
if (servletTransportFactory == null) {
- servletTransportFactory = new ServletTransportFactory(bus);
+ DestinationRegistryImpl registry = new DestinationRegistryImpl();
+ servletTransportFactory = new ServletTransportFactory(registry);
+ servletTransportFactory.setBus(bus);
}
return servletTransportFactory;
}
@@ -153,10 +151,4 @@ public abstract class AbstractCXFServlet
}
}
- // this makes it a bit easier to disable the address
- // updates when creating servlets programmatically
- public void setDisableAddressUpdates(boolean disableAddressUpdates) {
- this.disableAddressUpdates = disableAddressUpdates;
- }
-
}
Added:
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/BaseUrlHelper.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/BaseUrlHelper.java?rev=1085152&view=auto
==============================================================================
---
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/BaseUrlHelper.java
(added)
+++
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/BaseUrlHelper.java
Thu Mar 24 21:29:58 2011
@@ -0,0 +1,71 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.transport.servlet;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.cxf.transport.AbstractDestination;
+import org.apache.cxf.wsdl.WSDLLibrary;
+import org.apache.cxf.wsdl.http.AddressType;
+
+public final class BaseUrlHelper {
+ private BaseUrlHelper() {
+ }
+
+ public static String getBaseURL(HttpServletRequest request) {
+ String reqPrefix = request.getRequestURL().toString();
+ String pathInfo = request.getPathInfo() == null ? "" :
request.getPathInfo();
+ //fix for CXF-898
+ if (!"/".equals(pathInfo) || reqPrefix.endsWith("/")) {
+ String basePath = request.getContextPath() +
request.getServletPath();
+ int index;
+ if (basePath.length() == 0) {
+ index = reqPrefix.indexOf(request.getRequestURI());
+ } else {
+ index = reqPrefix.indexOf(basePath);
+ }
+ reqPrefix = reqPrefix.substring(0, index + basePath.length());
+ }
+ return reqPrefix;
+ }
+
+ public static void makeAddressesAbsolute(HttpServletRequest request,
String baseAddress,
+ AbstractDestination[]
destinations) {
+ for (AbstractDestination dest : destinations) {
+ String addr = dest.getEndpointInfo().getAddress();
+ if (addr == null || addr.length() == 0) {
+ addr = "/";
+ }
+ if (addr != null && !addr.startsWith("http")) {
+ String base = baseAddress == null ?
BaseUrlHelper.getBaseURL(request) : baseAddress;
+ setAddress(dest, base + addr);
+ }
+ }
+ }
+
+ public static void setAddress(AbstractDestination dest, String absAddress)
{
+ synchronized (dest) {
+ dest.getEndpointInfo().setAddress(absAddress);
+ if (WSDLLibrary.isAvailable()
+ && dest.getEndpointInfo().getExtensor(AddressType.class) !=
null) {
+
dest.getEndpointInfo().getExtensor(AddressType.class).setLocation(absAddress);
+ }
+ }
+ }
+}
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=1085152&r1=1085151&r2=1085152&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
Thu Mar 24 21:29:58 2011
@@ -16,9 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.cxf.transport.servlet;
import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Set;
+import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletConfig;
@@ -37,15 +41,107 @@ import org.apache.cxf.transport.http.Des
import org.apache.cxf.transports.http.QueryHandler;
import org.apache.cxf.transports.http.QueryHandlerRegistry;
-public class ServletController extends AbstractServletController {
+public class ServletController {
+ protected static final String DEFAULT_LISTINGS_CLASSIFIER = "/services";
private static final Logger LOG =
LogUtils.getL7dLogger(ServletController.class);
+
+ protected boolean isHideServiceList;
+ protected boolean disableAddressUpdates;
+ protected String forcedBaseAddress;
+ protected String serviceListStyleSheet;
+ protected String title;
+ protected String serviceListRelativePath = DEFAULT_LISTINGS_CLASSIFIER;
+ protected ServletConfig servletConfig;
+ protected DestinationRegistry destinationRegistry;
+ protected HttpServlet serviceListGenerator;
+
+ public ServletController(DestinationRegistry destinationRegistry,
+ ServletConfig config,
+ HttpServlet serviceListGenerator) {
+ this.servletConfig = config;
+ this.destinationRegistry = destinationRegistry;
+ this.serviceListGenerator = serviceListGenerator;
+ init();
+ }
- public ServletController(DestinationRegistry destinationRegistry,
- ServletConfig config,
- HttpServlet serviceListGenerator) {
- super(config, destinationRegistry, serviceListGenerator);
+ public void setServiceListRelativePath(String relativePath) {
+ serviceListRelativePath = relativePath;
}
+ public void setServiceListStyleSheet(String serviceListStyleSheet) {
+ this.serviceListStyleSheet = serviceListStyleSheet;
+ }
+ public void setTitle(String t) {
+ title = t;
+ }
+
+ protected synchronized void updateDests(HttpServletRequest request) {
+ updateDests(request, false);
+ }
+
+ protected void updateDests(HttpServletRequest request, boolean force) {
+
+ String base = forcedBaseAddress == null ?
BaseUrlHelper.getBaseURL(request) : forcedBaseAddress;
+
+ String pathInfo = request.getPathInfo();
+ if (pathInfo == null) {
+ pathInfo = "/";
+ }
+
+ Set<String> paths = destinationRegistry.getDestinationsPaths();
+ for (String path : paths) {
+ if (!force && pathInfo != null && !pathInfo.startsWith(path)) {
+ continue;
+ }
+ AbstractHTTPDestination d2 =
destinationRegistry.getDestinationForPath(path);
+ String ad = d2.getEndpointInfo().getAddress();
+ if (ad == null
+ && d2.getAddress() != null
+ && d2.getAddress().getAddress() != null) {
+ ad = d2.getAddress().getAddress().getValue();
+ if (ad == null) {
+ ad = "/";
+ }
+ }
+ if (ad != null
+ && (ad.equals(path))) {
+ if (disableAddressUpdates) {
+
request.setAttribute("org.apache.cxf.transport.endpoint.address",
+ base + path);
+ } else {
+ BaseUrlHelper.setAddress(d2, base + path);
+ }
+ }
+ }
+ }
+
+ private void init() {
+ if (servletConfig == null) {
+ return;
+ }
+
+ String hideServiceList =
servletConfig.getInitParameter("hide-service-list-page");
+ if (!StringUtils.isEmpty(hideServiceList)) {
+ this.isHideServiceList = Boolean.valueOf(hideServiceList);
+ }
+ String isDisableAddressUpdates =
servletConfig.getInitParameter("disable-address-updates");
+ if (!StringUtils.isEmpty(isDisableAddressUpdates)) {
+ this.disableAddressUpdates =
Boolean.valueOf(isDisableAddressUpdates);
+ }
+ String isForcedBaseAddress =
servletConfig.getInitParameter("base-address");
+ if (!StringUtils.isEmpty(isForcedBaseAddress)) {
+ this.forcedBaseAddress = isForcedBaseAddress;
+ }
+ try {
+ serviceListGenerator.init(servletConfig);
+ } catch (ServletException e) {
+ throw new RuntimeException(e.getMessage(), e);
+ }
+ String serviceListPath =
servletConfig.getInitParameter("service-list-path");
+ if (!StringUtils.isEmpty(serviceListPath)) {
+ this.serviceListRelativePath = serviceListPath;
+ }
+ }
public void invoke(HttpServletRequest request, HttpServletResponse res)
throws ServletException {
try {
@@ -117,5 +213,59 @@ public class ServletController extends A
}
}
+ public void invokeDestination(final HttpServletRequest request,
HttpServletResponse response,
+ AbstractHTTPDestination d) throws
ServletException {
+ if (LOG.isLoggable(Level.FINE)) {
+ LOG.fine("Service http request on thread: " +
Thread.currentThread());
+ }
+ try {
+ d.invoke(servletConfig, servletConfig.getServletContext(),
request, response);
+ } catch (IOException e) {
+ throw new ServletException(e);
+ } finally {
+ if (LOG.isLoggable(Level.FINE)) {
+ LOG.fine("Finished servicing http request on thread: " +
Thread.currentThread());
+ }
+ }
+ }
+
+ protected QueryHandler findQueryHandler(QueryHandlerRegistry
queryHandlerRegistry,
+ EndpointInfo ei,
+ String ctxUri,
+ String baseUri) {
+ if (queryHandlerRegistry == null) {
+ return null;
+ }
+ Iterable<QueryHandler> handlers = queryHandlerRegistry.getHandlers();
+ for (QueryHandler qh : handlers) {
+ if (qh.isRecognizedQuery(baseUri, ctxUri, ei)) {
+ return qh;
+ }
+ }
+ return null;
+ }
+
+ protected void respondUsingQueryHandler(QueryHandler selectedHandler,
HttpServletResponse res,
+ EndpointInfo ei, String ctxUri,
String baseUri) throws IOException,
+ ServletException {
+ res.setContentType(selectedHandler.getResponseContentType(baseUri,
ctxUri));
+ OutputStream out = res.getOutputStream();
+ try {
+ selectedHandler.writeResponse(baseUri, ctxUri, ei, out);
+ out.flush();
+ } catch (Exception e) {
+ LOG.warning(selectedHandler.getClass().getName()
+ + " Exception caught writing response: "
+ + e.getMessage());
+ throw new ServletException(e);
+ }
+ }
+
+ protected void generateNotFound(HttpServletRequest request,
HttpServletResponse res) throws IOException {
+ res.setStatus(404);
+ res.setContentType("text/html");
+ res.getWriter().write("<html><body>No service was
found.</body></html>");
+ }
+
}
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=1085152&r1=1085151&r2=1085152&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
Thu Mar 24 21:29:58 2011
@@ -21,8 +21,6 @@
package org.apache.cxf.transport.servlet;
import java.io.IOException;
-import java.util.Arrays;
-import java.util.List;
import javax.annotation.Resource;
@@ -32,19 +30,13 @@ import org.apache.cxf.transport.Destinat
import org.apache.cxf.transport.DestinationFactory;
import org.apache.cxf.transport.http.AbstractHTTPDestination;
import org.apache.cxf.transport.http.AbstractHTTPTransportFactory;
+import org.apache.cxf.transport.http.DestinationRegistry;
public class ServletTransportFactory extends AbstractHTTPTransportFactory
implements DestinationFactory {
- public ServletTransportFactory(Bus b) {
- super.setBus(b);
- List<String> ids = Arrays.asList(new String[] {
- "http://cxf.apache.org/transports/http",
- "http://cxf.apache.org/transports/http/configuration",
- "http://schemas.xmlsoap.org/wsdl/http",
- "http://schemas.xmlsoap.org/wsdl/http/",
- });
- this.setTransportIds(ids);
+ public ServletTransportFactory(DestinationRegistry registry) {
+ super(registry);
}
public ServletTransportFactory() {
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=1085152&r1=1085151&r2=1085152&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
Thu Mar 24 21:29:58 2011
@@ -57,7 +57,8 @@ public class ServletControllerTest exten
EasyMock.expectLastCall().andReturn("");
req.getServletPath();
EasyMock.expectLastCall().andReturn("");
-
+ req.setAttribute("org.apache.cxf.transport.endpoint.address",
"http://localhost:8080");
+ EasyMock.expectLastCall().anyTimes();
req.getRequestURI();
EasyMock.expectLastCall().andReturn(requestUri).times(2);
req.getParameter("stylesheet");
@@ -108,6 +109,8 @@ public class ServletControllerTest exten
EasyMock.expectLastCall().andReturn("false");
req.getRequestURL();
EasyMock.expectLastCall().andReturn(new
StringBuffer("http://localhost:8080/services"));
+ req.setAttribute("org.apache.cxf.transport.endpoint.address",
"http://localhost:8080");
+ EasyMock.expectLastCall().anyTimes();
registry.getDestinationsPaths();
EasyMock.expectLastCall().andReturn(Collections.emptySet()).atLeastOnce();
registry.getDestinationForPath("", true);
@@ -153,90 +156,7 @@ public class ServletControllerTest exten
sc.invoke(req, res);
assertFalse(sc.invokeDestinationCalled());
}
-
- private String testGetBaseURL(String requestUrl, String contextPath,
- String servletPath, String pathInfo) {
- req.getRequestURL();
- EasyMock.expectLastCall().andReturn(new StringBuffer(requestUrl));
-
- req.getContextPath();
- EasyMock.expectLastCall().andReturn(contextPath);
- req.getServletPath();
- EasyMock.expectLastCall().andReturn(servletPath);
-
- req.getPathInfo();
- EasyMock.expectLastCall().andReturn(pathInfo).times(2);
-
- String basePath = contextPath + servletPath;
- if (basePath.length() == 0) {
- req.getRequestURI();
- EasyMock.expectLastCall().andReturn(pathInfo);
- }
-
- EasyMock.replay(req);
- return new ServletController(null, null, null).getBaseURL(req);
- }
-
- @Test
- public void testGetRequestURL() throws Exception {
- String url = testGetBaseURL("http://localhost:8080/services/bar",
- "", "/services", "/bar");
- assertEquals("http://localhost:8080/services", url);
- }
-
- @Test
- public void testGetRequestURL2() throws Exception {
- String url = testGetBaseURL("http://localhost:8080/services/bar",
- "/services", "", "/bar");
- assertEquals("http://localhost:8080/services", url);
- }
-
- @Test
- public void testGetRequestURL3() throws Exception {
- String url = testGetBaseURL("http://localhost:8080/services/bar",
- "", "", "/services/bar");
- assertEquals("http://localhost:8080", url);
- }
-
- @Test
- public void testGetRequestURLSingleMatrixParam() throws Exception {
- String url = testGetBaseURL("http://localhost:8080/services/bar;a=b",
- "", "/services", "/bar");
- assertEquals("http://localhost:8080/services", url);
- }
-
- @Test
- public void testGetRequestURLMultipleMatrixParam() throws Exception {
- String url =
testGetBaseURL("http://localhost:8080/services/bar;a=b;c=d;e=f",
- "", "/services", "/bar");
- assertEquals("http://localhost:8080/services", url);
-
- }
-
- @Test
- public void testGetRequestURLMultipleMatrixParam2() throws Exception {
- String url =
testGetBaseURL("http://localhost:8080/services/bar;a=b;c=d;e=f",
- "", "/services", "/bar;a=b;c=d");
- assertEquals("http://localhost:8080/services", url);
-
- }
-
- @Test
- public void testGetRequestURLMultipleMatrixParam3() throws Exception {
- String url =
testGetBaseURL("http://localhost:8080/services/bar;a=b;c=d;e=f",
- "", "/services", "/bar;a=b");
- assertEquals("http://localhost:8080/services", url);
-
- }
-
- @Test
- public void testGetRequestURLMultipleMatrixParam4() throws Exception {
- String url =
testGetBaseURL("http://localhost:8080/services/bar;a=b;c=d;e=f;",
- "", "/services", "/bar;a=b");
- assertEquals("http://localhost:8080/services", url);
-
- }
-
+
public static class TestServletController extends ServletController {
private boolean invokeDestinationCalled;
@@ -245,6 +165,10 @@ public class ServletControllerTest exten
super(destinationRegistry, null, serviceListGenerator);
}
+ public void setHideServiceList(boolean b) {
+ this.isHideServiceList = b;
+ }
+
@Override
protected void updateDests(HttpServletRequest request) {
}
Added:
cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/servicelist/BaseUrlHelperTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/servicelist/BaseUrlHelperTest.java?rev=1085152&view=auto
==============================================================================
---
cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/servicelist/BaseUrlHelperTest.java
(added)
+++
cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/servicelist/BaseUrlHelperTest.java
Thu Mar 24 21:29:58 2011
@@ -0,0 +1,109 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.transport.servlet.servicelist;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.cxf.transport.servlet.BaseUrlHelper;
+import org.easymock.classextension.EasyMock;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class BaseUrlHelperTest {
+ private String testGetBaseURL(String requestUrl, String contextPath,
+ String servletPath, String pathInfo) {
+ HttpServletRequest req = EasyMock.createMock(HttpServletRequest.class);
+ req.getRequestURL();
+ EasyMock.expectLastCall().andReturn(new StringBuffer(requestUrl));
+
+ req.getContextPath();
+ EasyMock.expectLastCall().andReturn(contextPath);
+ req.getServletPath();
+ EasyMock.expectLastCall().andReturn(servletPath);
+
+ req.getPathInfo();
+ EasyMock.expectLastCall().andReturn(pathInfo).times(2);
+
+ String basePath = contextPath + servletPath;
+ if (basePath.length() == 0) {
+ req.getRequestURI();
+ EasyMock.expectLastCall().andReturn(pathInfo);
+ }
+
+ EasyMock.replay(req);
+ return BaseUrlHelper.getBaseURL(req);
+ }
+
+ @Test
+ public void testGetRequestURL() throws Exception {
+ String url = testGetBaseURL("http://localhost:8080/services/bar", "",
"/services", "/bar");
+ Assert.assertEquals("http://localhost:8080/services", url);
+ }
+
+ @Test
+ public void testGetRequestURL2() throws Exception {
+ String url = testGetBaseURL("http://localhost:8080/services/bar",
"/services", "", "/bar");
+ Assert.assertEquals("http://localhost:8080/services", url);
+ }
+
+ @Test
+ public void testGetRequestURL3() throws Exception {
+ String url = testGetBaseURL("http://localhost:8080/services/bar", "",
"", "/services/bar");
+ Assert.assertEquals("http://localhost:8080", url);
+ }
+
+ @Test
+ public void testGetRequestURLSingleMatrixParam() throws Exception {
+ String url = testGetBaseURL("http://localhost:8080/services/bar;a=b",
"", "/services", "/bar");
+ Assert.assertEquals("http://localhost:8080/services", url);
+ }
+
+ @Test
+ public void testGetRequestURLMultipleMatrixParam() throws Exception {
+ String url =
testGetBaseURL("http://localhost:8080/services/bar;a=b;c=d;e=f",
+ "", "/services", "/bar");
+ Assert.assertEquals("http://localhost:8080/services", url);
+
+ }
+
+ @Test
+ public void testGetRequestURLMultipleMatrixParam2() throws Exception {
+ String url =
testGetBaseURL("http://localhost:8080/services/bar;a=b;c=d;e=f", "",
"/services",
+ "/bar;a=b;c=d");
+ Assert.assertEquals("http://localhost:8080/services", url);
+
+ }
+
+ @Test
+ public void testGetRequestURLMultipleMatrixParam3() throws Exception {
+ String url =
testGetBaseURL("http://localhost:8080/services/bar;a=b;c=d;e=f", "",
"/services",
+ "/bar;a=b");
+ Assert.assertEquals("http://localhost:8080/services", url);
+
+ }
+
+ @Test
+ public void testGetRequestURLMultipleMatrixParam4() throws Exception {
+ String url =
testGetBaseURL("http://localhost:8080/services/bar;a=b;c=d;e=f;", "",
"/services",
+ "/bar;a=b");
+ Assert.assertEquals("http://localhost:8080/services", url);
+
+ }
+}