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 2013/04/04 11:54:08 UTC
svn commit: r1464411 - in /cxf/branches/2.6.x-fixes: ./
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/
systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ systests/jaxr...
Author: sergeyb
Date: Thu Apr 4 09:54:07 2013
New Revision: 1464411
URL: http://svn.apache.org/r1464411
Log:
Merged revisions 1464314 via svnmerge from
https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes
................
r1464314 | sergeyb | 2013-04-04 10:28:15 +0300 (Thu, 04 Apr 2013) | 13 lines
Merged revisions 1464017,1464302 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1464017 | sergeyb | 2013-04-03 16:55:28 +0300 (Wed, 03 Apr 2013) | 1 line
[CXF-4924] Initial update WADLGenerator to support the retrieval of the documents containing the referenced resource_types
........
r1464302 | sergeyb | 2013-04-04 10:09:14 +0300 (Thu, 04 Apr 2013) | 1 line
[CXF-4924] Renaming the test resources to make it simpler to merge to 2.7.x
........
................
Added:
cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/wadl/bookstoreImportResource.wadl
- copied unchanged from r1464314, cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/wadl/bookstoreImportResource.wadl
cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/wadl/bookstoreImportResourceType.wadl
- copied unchanged from r1464314, cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/wadl/bookstoreImportResourceType.wadl
Modified:
cxf/branches/2.6.x-fixes/ (props changed)
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml
Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Thu Apr 4 09:54:07 2013
@@ -0,0 +1,2 @@
+/cxf/branches/2.7.x-fixes:1464314
+/cxf/trunk:1464017,1464302
Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java?rev=1464411&r1=1464410&r2=1464411&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java (original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java Thu Apr 4 09:54:07 2013
@@ -43,7 +43,8 @@ public class RequestPreprocessor {
private static final String CTYPE_QUERY = "_ctype";
private static final String METHOD_QUERY = "_method";
private static final String METHOD_HEADER = "X-HTTP-Method-Override";
-
+ private static final String SCHEMA_EXTENSION = ".xsd";
+ private static final String WADL_EXTENSION = ".wadl";
private static final Map<String, String> SHORTCUTS;
static {
@@ -198,7 +199,8 @@ public class RequestPreprocessor {
if (baseAddress.equals(requestURI)) {
return handleMetadataRequest(m);
}
- } else if (originalRequestURI != null && originalRequestURI.endsWith(".xsd")) {
+ } else if (originalRequestURI != null && (originalRequestURI.endsWith(SCHEMA_EXTENSION)
+ || originalRequestURI.endsWith(WADL_EXTENSION))) {
// trying WADLGenerator which may be caching schema resources won't
// interfere with custom schema handlers if any
return handleMetadataRequest(m);
Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=1464411&r1=1464410&r2=1464411&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java (original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java Thu Apr 4 09:54:07 2013
@@ -138,7 +138,7 @@ public class WadlGenerator implements Re
private List<URI> externalSchemaLinks;
private Map<String, List<String>> externalQnamesMap;
- private ConcurrentHashMap<String, String> schemaLocationMap =
+ private ConcurrentHashMap<String, String> docLocationMap =
new ConcurrentHashMap<String, String>();
private ElementQNameResolver resolver;
@@ -173,13 +173,13 @@ public class WadlGenerator implements Re
UriInfo ui = new UriInfoImpl(m);
if (!ui.getQueryParameters().containsKey(WADL_QUERY)) {
- if (!schemaLocationMap.isEmpty()) {
+ if (!docLocationMap.isEmpty()) {
String path = ui.getPath(false);
if (path.startsWith("/") && path.length() > 0) {
path = path.substring(1);
}
- if (schemaLocationMap.containsKey(path)) {
- return getExistingSchema(m, ui, path);
+ if (docLocationMap.containsKey(path)) {
+ return getExistingResource(m, ui, path);
}
}
return null;
@@ -860,15 +860,21 @@ public class WadlGenerator implements Re
WadlGenerator.WADL_NS,
"grammars");
if (grammarEls.size() == 1) {
- handleSchemaRefs(DOMUtils.getChildrenWithName(grammarEls.get(0),
+ handleExistingDocRefs(DOMUtils.getChildrenWithName(grammarEls.get(0),
WadlGenerator.WADL_NS, "include"), "href", loc, "", m, ui);
}
- List<Element> resourceEls = DOMUtils.getChildrenWithName(appEl,
+ List<Element> resourcesEls = DOMUtils.getChildrenWithName(appEl,
WadlGenerator.WADL_NS,
"resources");
- if (resourceEls.size() == 1) {
- DOMUtils.setAttribute(resourceEls.get(0), "base", getBaseURI(m, ui));
+ if (resourcesEls.size() == 1) {
+ DOMUtils.setAttribute(resourcesEls.get(0), "base", getBaseURI(m, ui));
+
+ List<Element> resourceEls = DOMUtils.getChildrenWithName(resourcesEls.get(0),
+ WadlGenerator.WADL_NS,
+ "resource");
+ handleExistingDocRefs(resourceEls, "type", loc, "", m, ui);
+
return Response.ok().type(mt).entity(new DOMSource(appEl)).build();
}
@@ -882,18 +888,34 @@ public class WadlGenerator implements Re
}
//TODO: deal with caching later on
- public Response getExistingSchema(Message m, UriInfo ui, String href) {
- String loc = schemaLocationMap.get(href);
+ public Response getExistingResource(Message m, UriInfo ui, String href) {
+ String loc = docLocationMap.get(href);
Endpoint ep = m.getExchange().get(Endpoint.class);
if (ep != null && loc != null) {
try {
+ int fragmentIndex = loc.lastIndexOf("#");
+ if (fragmentIndex != -1) {
+ loc = loc.substring(0, fragmentIndex);
+ }
InputStream is = ResourceUtils.getResourceStream(loc, (Bus)ep.get(Bus.class.getName()));
if (is != null) {
Element docEl = DOMUtils.readXml(is).getDocumentElement();
- handleSchemaRefs(DOMUtils.getChildrenWithName(docEl,
- XmlSchemaConstants.XSD_NAMESPACE_URI, "import"), "schemaLocation", loc, href, m, ui);
- handleSchemaRefs(DOMUtils.getChildrenWithName(docEl,
- XmlSchemaConstants.XSD_NAMESPACE_URI, "include"), "schemaLocation", loc, href, m, ui);
+ if (fragmentIndex != -1) {
+ List<Element> grammarEls = DOMUtils.getChildrenWithName(docEl,
+ WadlGenerator.WADL_NS,
+ "grammars");
+ if (grammarEls.size() == 1) {
+ handleExistingDocRefs(DOMUtils.getChildrenWithName(grammarEls.get(0),
+ WadlGenerator.WADL_NS, "include"), "href", loc, href, m, ui);
+ }
+ } else {
+ handleExistingDocRefs(DOMUtils.getChildrenWithName(docEl,
+ XmlSchemaConstants.XSD_NAMESPACE_URI, "import"), "schemaLocation", loc, href, m, ui);
+ handleExistingDocRefs(DOMUtils.getChildrenWithName(docEl,
+ XmlSchemaConstants.XSD_NAMESPACE_URI, "include"), "schemaLocation", loc, href, m, ui);
+ }
+
+
return Response.ok().type(MediaType.APPLICATION_XML_TYPE).entity(
new DOMSource(docEl)).build();
}
@@ -905,7 +927,7 @@ public class WadlGenerator implements Re
return null;
}
- private void handleSchemaRefs(List<Element> schemaRefEls, String attrName,
+ private void handleExistingDocRefs(List<Element> elements, String attrName,
String parentDocLoc, String parentRef, Message m, UriInfo ui) {
int index = parentDocLoc.lastIndexOf('/');
parentDocLoc = index == -1 ? parentDocLoc : parentDocLoc.substring(0, index + 1);
@@ -913,13 +935,22 @@ public class WadlGenerator implements Re
index = parentRef.lastIndexOf('/');
parentRef = index == -1 ? "" : parentRef.substring(0, index + 1);
- for (Element schemaRefEl : schemaRefEls) {
- String href = schemaRefEl.getAttribute(attrName);
- if (!StringUtils.isEmpty(href)) {
+ for (Element element : elements) {
+ String href = element.getAttribute(attrName);
+ String originalRef = href;
+ if (!StringUtils.isEmpty(href) && !href.startsWith("#")) {
+ int fragmentIndex = href.lastIndexOf("#");
+ String fragment = null;
+ if (fragmentIndex != -1) {
+ fragment = href.substring(fragmentIndex + 1);
+ href = href.substring(0, fragmentIndex);
+ }
+
String actualRef = parentRef + href;
- schemaLocationMap.put(actualRef, parentDocLoc + href);
- URI schemaURI = UriBuilder.fromUri(getBaseURI(m, ui)).path(actualRef).build();
- DOMUtils.setAttribute(schemaRefEl, attrName, schemaURI.toString());
+ docLocationMap.put(actualRef, parentDocLoc + originalRef);
+ UriBuilder ub = UriBuilder.fromUri(getBaseURI(m, ui)).path(actualRef).fragment(fragment);
+ URI schemaURI = ub.build();
+ DOMUtils.setAttribute(element, attrName, schemaURI.toString());
}
}
}
@@ -1371,7 +1402,7 @@ public class WadlGenerator implements Re
if (href.startsWith("classpath:")) {
int index = href.lastIndexOf('/');
href = index == -1 ? href.substring(9) : href.substring(index + 1);
- schemaLocationMap.put(href, s);
+ docLocationMap.put(href, s);
}
externalSchemaLinks.add(URI.create(href));
} catch (Exception ex) {
Modified: cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java?rev=1464411&r1=1464410&r2=1464411&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java (original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java Thu Apr 4 09:54:07 2013
@@ -105,10 +105,18 @@ public class JAXRSClientServerSpringBook
@Test
public void testGetWadlFromWadlLocation() throws Exception {
String address = "http://localhost:" + PORT + "/the/generated";
- checkWadlResourcesInfo(address, address + "/bookstore", "/schemas/book.xsd", 1);
-
+ List<Element> resources =
+ checkWadlResourcesInfo(address, address + "/bookstore", "/schemas/book.xsd", 2);
+ assertEquals("", resources.get(0).getAttribute("type"));
+ String type = resources.get(1).getAttribute("type");
+ String resourceTypeAddress = address + "/bookstoreImportResourceType.wadl#bookstoreType";
+ assertEquals(resourceTypeAddress, type);
+
checkSchemas(address, "/schemas/book.xsd", "/schemas/chapter.xsd", "include");
checkSchemas(address, "/schemas/chapter.xsd", null, null);
+
+ // check resource type resource
+ checkWadlResourcesType(address, resourceTypeAddress, "/schemas/book.xsd");
}
@Test
@@ -140,7 +148,31 @@ public class JAXRSClientServerSpringBook
}
- private void checkWadlResourcesInfo(String baseURI, String requestURI,
+ private void checkWadlResourcesType(String baseURI, String requestTypeURI, String schemaRef) throws Exception {
+ WebClient client = WebClient.create(requestTypeURI);
+ WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(1000000);
+
+ Document doc = DOMUtils.readXml(new InputStreamReader(client.get(InputStream.class), "UTF-8"));
+ Element root = doc.getDocumentElement();
+ assertEquals(WadlGenerator.WADL_NS, root.getNamespaceURI());
+ assertEquals("application", root.getLocalName());
+ List<Element> grammarEls = DOMUtils.getChildrenWithName(root,
+ WadlGenerator.WADL_NS, "grammars");
+ assertEquals(1, grammarEls.size());
+ List<Element> includeEls = DOMUtils.getChildrenWithName(grammarEls.get(0),
+ WadlGenerator.WADL_NS, "include");
+ assertEquals(1, includeEls.size());
+ String href = includeEls.get(0).getAttribute("href");
+ assertEquals(baseURI + schemaRef, href);
+ List<Element> resourcesEls = DOMUtils.getChildrenWithName(root,
+ WadlGenerator.WADL_NS, "resources");
+ assertEquals(0, resourcesEls.size());
+ List<Element> resourceTypeEls =
+ DOMUtils.getChildrenWithName(root, WadlGenerator.WADL_NS, "resource_type");
+ assertEquals(1, resourceTypeEls.size());
+ }
+
+ private List<Element> checkWadlResourcesInfo(String baseURI, String requestURI,
String schemaRef, int size) throws Exception {
WebClient client = WebClient.create(requestURI + "?_wadl&_type=xml");
Document doc = DOMUtils.readXml(new InputStreamReader(client.get(InputStream.class), "UTF-8"));
@@ -164,6 +196,8 @@ public class JAXRSClientServerSpringBook
DOMUtils.getChildrenWithName(resourcesEl,
WadlGenerator.WADL_NS, "resource");
assertEquals(size, resourceEls.size());
+ return resourceEls;
+
}
@Test
@@ -179,7 +213,6 @@ public class JAXRSClientServerSpringBook
String endpointAddress =
"http://localhost:" + PORT + "/the/thebooks/bookstore/semicolon%3B";
WebClient client = WebClient.create(endpointAddress);
- WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(1000000);
Book book = client.get(Book.class);
assertEquals(333L, book.getId());
assertEquals(";", book.getName());
Modified: cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml?rev=1464411&r1=1464410&r2=1464411&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml (original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml Thu Apr 4 09:54:07 2013
@@ -203,7 +203,7 @@ http://cxf.apache.org/schemas/core.xsd">
</jaxrs:server>
<jaxrs:server id="bookserviceGenerated" address="/generated"
- docLocation="classpath:/wadl/bookstoreImport.xml">
+ docLocation="classpath:/wadl/bookstoreImportResource.wadl">
<jaxrs:serviceBeans>
<bean class="org.apache.cxf.systest.jaxrs.codegen.service.BookStore"/>
</jaxrs:serviceBeans>