You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2011/06/10 13:39:36 UTC
svn commit: r1134283 - in /cxf/branches/2.4.x-fixes: ./
rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/
rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/
rt/transports/http/src/test/java/org/apache/cxf/tr...
Author: sergeyb
Date: Fri Jun 10 11:39:36 2011
New Revision: 1134283
URL: http://svn.apache.org/viewvc?rev=1134283&view=rev
Log:
Merged revisions 1134281 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1134281 | sergeyb | 2011-06-10 12:34:14 +0100 (Fri, 10 Jun 2011) | 1 line
[CXF-3583] Saving the calculated base address as HTTP request attribute and using for building services pages
........
Modified:
cxf/branches/2.4.x-fixes/ (props changed)
cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java
cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListGeneratorServlet.java
cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListWriter.java
cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/UnformattedServiceListWriter.java
cxf/branches/2.4.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java
Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jun 10 11:39:36 2011
@@ -1 +1 @@
-/cxf/trunk:1134248
+/cxf/trunk:1134248,1134281
Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Jun 10 11:39:36 2011
@@ -1 +1 @@
-/cxf/trunk:1-1134023,1134142,1134248
+/cxf/trunk:1-1134023,1134142,1134248,1134281
Modified: cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java?rev=1134283&r1=1134282&r2=1134283&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java (original)
+++ cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java Fri Jun 10 11:39:36 2011
@@ -21,7 +21,6 @@ package org.apache.cxf.transport.servlet
import java.io.IOException;
import java.io.OutputStream;
-import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -34,6 +33,7 @@ import javax.servlet.http.HttpServletRes
import org.apache.cxf.Bus;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.message.Message;
import org.apache.cxf.resource.ResourceManager;
import org.apache.cxf.service.model.EndpointInfo;
import org.apache.cxf.transport.http.AbstractHTTPDestination;
@@ -76,23 +76,17 @@ public class ServletController {
title = t;
}
- protected void updateDests(HttpServletRequest request, AbstractHTTPDestination d) {
-
- String base = forcedBaseAddress == null ? BaseUrlHelper.getBaseURL(request) : forcedBaseAddress;
-
- if (d == null) {
- Collection<AbstractHTTPDestination> dests = destinationRegistry.getDestinations();
- for (AbstractHTTPDestination dest : dests) {
- updateDestination(dest, request, base);
- }
- } else {
- updateDestination(d, request, base);
- }
+ protected String getBaseURL(HttpServletRequest request) {
+ return forcedBaseAddress == null ? BaseUrlHelper.getBaseURL(request) : forcedBaseAddress;
+ }
+
+ protected void setBaseURLAttribute(HttpServletRequest request) {
+ request.setAttribute(Message.BASE_PATH, getBaseURL(request));
}
- protected void updateDestination(AbstractHTTPDestination d,
- HttpServletRequest request,
- String base) {
+ protected void updateDestination(HttpServletRequest request,
+ AbstractHTTPDestination d) {
+ String base = getBaseURL(request);
synchronized (d) {
String ad = d.getEndpointInfo().getAddress();
if (ad == null
@@ -154,7 +148,7 @@ public class ServletController {
|| request.getRequestURI().endsWith(serviceListRelativePath + "/")
|| StringUtils.isEmpty(pathInfo)
|| "/".equals(pathInfo))) {
- updateDests(request, null);
+ setBaseURLAttribute(request);
serviceListGenerator.service(request, res);
} else {
d = destinationRegistry.checkRestfulRequest(pathInfo);
@@ -163,7 +157,7 @@ public class ServletController {
+ request.getRequestURL() + "'s Observer ");
generateNotFound(request, res);
} else { // the request should be a restful service request
- updateDests(request, d);
+ updateDestination(request, d);
invokeDestination(request, res, d);
}
}
@@ -186,7 +180,7 @@ public class ServletController {
// update the EndPoint Address with request url
if ("GET".equals(request.getMethod())) {
- updateDests(request, d);
+ updateDestination(request, d);
}
String ctxUri = request.getPathInfo();
@@ -201,7 +195,7 @@ public class ServletController {
return;
}
} else {
- updateDests(request, d);
+ updateDestination(request, d);
}
invokeDestination(request, res, d);
} finally {
Modified: cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java?rev=1134283&r1=1134282&r2=1134283&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java (original)
+++ cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/FormattedServiceListWriter.java Fri Jun 10 11:39:36 2011
@@ -43,6 +43,7 @@ public class FormattedServiceListWriter
}
public void writeServiceList(PrintWriter writer,
+ String basePath,
AbstractDestination[] soapDestinations,
AbstractDestination[] restDestinations) throws IOException {
writer.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" "
@@ -58,8 +59,8 @@ public class FormattedServiceListWriter
writer.write("</head><body>");
if (soapDestinations.length > 0 || restDestinations.length > 0) {
- writeSOAPEndpoints(writer, soapDestinations);
- writeRESTfulEndpoints(writer, restDestinations);
+ writeSOAPEndpoints(writer, basePath, soapDestinations);
+ writeRESTfulEndpoints(writer, basePath, restDestinations);
} else {
writer.write("<span class=\"heading\">No services have been found.</span>");
}
@@ -67,19 +68,22 @@ public class FormattedServiceListWriter
writer.write("</body></html>");
}
- private void writeSOAPEndpoints(PrintWriter writer,
+ private void writeSOAPEndpoints(PrintWriter writer,
+ String basePath,
AbstractDestination[] destinations)
throws IOException {
writer.write("<span class=\"heading\">Available SOAP services:</span><br/>");
writer.write("<table " + (styleSheetPath.endsWith("stylesheet=1")
? "cellpadding=\"1\" cellspacing=\"1\" border=\"1\" width=\"100%\"" : "") + ">");
for (AbstractDestination sd : destinations) {
- writerSoapEndpoint(writer, sd);
+ writerSoapEndpoint(writer, basePath, sd);
}
writer.write("</table><br/><br/>");
}
- private void writerSoapEndpoint(PrintWriter writer, AbstractDestination sd) {
+ private void writerSoapEndpoint(PrintWriter writer,
+ String basePath,
+ AbstractDestination sd) {
writer.write("<tr><td>");
writer.write("<span class=\"porttypename\">"
+ sd.getEndpointInfo().getInterface().getName().getLocalPart() + "</span>");
@@ -91,37 +95,52 @@ public class FormattedServiceListWriter
}
writer.write("</ul>");
writer.write("</td><td>");
- String address = sd.getEndpointInfo().getAddress();
+
+ String absoluteURL = getAbsoluteAddress(basePath, sd);
writer.write("<span class=\"field\">Endpoint address:</span> " + "<span class=\"value\">"
- + address + "</span>");
- writer.write("<br/><span class=\"field\">WSDL :</span> " + "<a href=\"" + address
+ + absoluteURL + "</span>");
+ writer.write("<br/><span class=\"field\">WSDL :</span> " + "<a href=\"" + absoluteURL
+ "?wsdl\">" + sd.getEndpointInfo().getService().getName() + "</a>");
writer.write("<br/><span class=\"field\">Target namespace:</span> "
+ "<span class=\"value\">"
+ sd.getEndpointInfo().getService().getTargetNamespace() + "</span>");
- addAtomLinkIfNeeded(address, atomMap, writer);
+ addAtomLinkIfNeeded(absoluteURL, atomMap, writer);
writer.write("</td></tr>");
}
- private void writeRESTfulEndpoints(PrintWriter writer, AbstractDestination[] restfulDests)
+ private String getAbsoluteAddress(String basePath, AbstractDestination d) {
+ String endpointAddress = d.getEndpointInfo().getAddress();
+ if (basePath == null || endpointAddress.startsWith(basePath)) {
+ return endpointAddress;
+ } else {
+ return basePath + endpointAddress;
+ }
+ }
+
+ private void writeRESTfulEndpoints(PrintWriter writer,
+ String basePath,
+ AbstractDestination[] restfulDests)
throws IOException {
writer.write("<span class=\"heading\">Available RESTful services:</span><br/>");
writer.write("<table " + (styleSheetPath.endsWith("stylesheet=1")
? "cellpadding=\"1\" cellspacing=\"1\" border=\"1\" width=\"100%\"" : "") + ">");
for (AbstractDestination sd : restfulDests) {
- writeRESTfulEndpoint(writer, sd);
+ writeRESTfulEndpoint(writer, basePath, sd);
}
writer.write("</table>");
}
- private void writeRESTfulEndpoint(PrintWriter writer, AbstractDestination sd) {
+ private void writeRESTfulEndpoint(PrintWriter writer,
+ String basePath,
+ AbstractDestination sd) {
+ String absoluteURL = getAbsoluteAddress(basePath, sd);
+
writer.write("<tr><td>");
- String address = sd.getEndpointInfo().getAddress();
writer.write("<span class=\"field\">Endpoint address:</span> " + "<span class=\"value\">"
- + address + "</span>");
- writer.write("<br/><span class=\"field\">WADL :</span> " + "<a href=\"" + address
- + "?_wadl&_type=xml\">" + address + "?_wadl&type=xml" + "</a>");
- addAtomLinkIfNeeded(address, atomMap, writer);
+ + absoluteURL + "</span>");
+ writer.write("<br/><span class=\"field\">WADL :</span> " + "<a href=\"" + absoluteURL
+ + "?_wadl&_type=xml\">" + absoluteURL + "?_wadl&type=xml" + "</a>");
+ addAtomLinkIfNeeded(absoluteURL, atomMap, writer);
writer.write("</td></tr>");
}
Modified: cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListGeneratorServlet.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListGeneratorServlet.java?rev=1134283&r1=1134282&r2=1134283&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListGeneratorServlet.java (original)
+++ cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListGeneratorServlet.java Fri Jun 10 11:39:36 2011
@@ -34,6 +34,7 @@ import javax.servlet.http.HttpServletRes
import org.apache.cxf.Bus;
import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.message.Message;
import org.apache.cxf.service.model.EndpointInfo;
import org.apache.cxf.transport.AbstractDestination;
import org.apache.cxf.transport.http.DestinationRegistry;
@@ -101,7 +102,10 @@ public class ServiceListGeneratorServlet
}
response.setContentType(serviceListWriter.getContentType());
- serviceListWriter.writeServiceList(writer, soapEndpoints, restEndpoints);
+ Object basePath = request.getAttribute(Message.BASE_PATH);
+ serviceListWriter.writeServiceList(writer,
+ basePath == null ? null : basePath.toString(),
+ soapEndpoints, restEndpoints);
}
Modified: cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListWriter.java?rev=1134283&r1=1134282&r2=1134283&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListWriter.java (original)
+++ cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListWriter.java Fri Jun 10 11:39:36 2011
@@ -25,7 +25,8 @@ import org.apache.cxf.transport.Abstract
public interface ServiceListWriter {
String getContentType();
- void writeServiceList(PrintWriter writer,
+ void writeServiceList(PrintWriter writer,
+ String baseAddress,
AbstractDestination[] soapDestinations,
AbstractDestination[] restDestinations) throws IOException;
Modified: cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/UnformattedServiceListWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/UnformattedServiceListWriter.java?rev=1134283&r1=1134282&r2=1134283&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/UnformattedServiceListWriter.java (original)
+++ cxf/branches/2.4.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/UnformattedServiceListWriter.java Fri Jun 10 11:39:36 2011
@@ -34,21 +34,23 @@ public class UnformattedServiceListWrite
return "text/html; charset=UTF-8";
}
- public void writeServiceList(PrintWriter writer,
+ public void writeServiceList(PrintWriter writer,
+ String baseAddress,
AbstractDestination[] soapDestinations,
AbstractDestination[] restDestinations) throws IOException {
if (soapDestinations.length > 0 || restDestinations.length > 0) {
- writeUnformattedSOAPEndpoints(writer, soapDestinations);
- writeUnformattedRESTfulEndpoints(writer, restDestinations);
+ writeUnformattedSOAPEndpoints(writer, baseAddress, soapDestinations);
+ writeUnformattedRESTfulEndpoints(writer, baseAddress, restDestinations);
} else {
writer.write("No services have been found.");
}
}
private void writeUnformattedSOAPEndpoints(PrintWriter writer,
+ String baseAddress,
AbstractDestination[] destinations) throws IOException {
for (AbstractDestination sd : destinations) {
- String address = sd.getEndpointInfo().getAddress();
+ String address = getAbsoluteAddress(baseAddress, sd);
writer.write(address);
if (renderWsdlList) {
@@ -60,11 +62,20 @@ public class UnformattedServiceListWrite
}
private void writeUnformattedRESTfulEndpoints(PrintWriter writer,
+ String baseAddress,
AbstractDestination[] destinations) throws IOException {
for (AbstractDestination sd : destinations) {
- String address = sd.getEndpointInfo().getAddress();
+ String address = getAbsoluteAddress(baseAddress, sd);
writer.write(address + "?_wadl&_type=xml\n");
}
}
+ private String getAbsoluteAddress(String basePath, AbstractDestination d) {
+ String endpointAddress = d.getEndpointInfo().getAddress();
+ if (basePath == null || endpointAddress.startsWith(basePath)) {
+ return endpointAddress;
+ } else {
+ return basePath + endpointAddress;
+ }
+ }
}
Modified: cxf/branches/2.4.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java?rev=1134283&r1=1134282&r2=1134283&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java (original)
+++ cxf/branches/2.4.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ServletControllerTest.java Fri Jun 10 11:39:36 2011
@@ -26,6 +26,7 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.cxf.message.Message;
import org.apache.cxf.transport.MessageObserver;
import org.apache.cxf.transport.http.AbstractHTTPDestination;
import org.apache.cxf.transport.http.DestinationRegistry;
@@ -57,7 +58,7 @@ public class ServletControllerTest exten
EasyMock.expectLastCall().andReturn("");
req.getServletPath();
EasyMock.expectLastCall().andReturn("");
- req.setAttribute("org.apache.cxf.transport.endpoint.address", "http://localhost:8080");
+ req.setAttribute(Message.BASE_PATH, "http://localhost:8080");
EasyMock.expectLastCall().anyTimes();
req.getRequestURI();
EasyMock.expectLastCall().andReturn(requestUri).times(2);
@@ -109,7 +110,7 @@ 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");
+ req.setAttribute(Message.BASE_PATH, "http://localhost:8080");
EasyMock.expectLastCall().anyTimes();
registry.getDestinationsPaths();
EasyMock.expectLastCall().andReturn(Collections.emptySet()).atLeastOnce();
@@ -170,7 +171,7 @@ public class ServletControllerTest exten
}
@Override
- protected void updateDests(HttpServletRequest request, AbstractHTTPDestination d) {
+ protected void updateDestination(HttpServletRequest request, AbstractHTTPDestination d) {
}
@Override