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 09:28:15 UTC
svn commit: r1464314 - in /cxf/branches/2.7.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 07:28:15 2013
New Revision: 1464314
URL: http://svn.apache.org/r1464314
Log:
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.7.x-fixes/systests/jaxrs/src/test/resources/wadl/bookstoreImportResource.wadl
cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/wadl/bookstoreImportResourceType.wadl
Modified:
cxf/branches/2.7.x-fixes/ (props changed)
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml
Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
svn:mergeinfo = /cxf/trunk:1464017,1464302
Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java?rev=1464314&r1=1464313&r2=1464314&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java Thu Apr 4 07:28:15 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.7.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.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=1464314&r1=1464313&r2=1464314&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java Thu Apr 4 07:28:15 2013
@@ -139,7 +139,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;
@@ -174,13 +174,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;
@@ -861,15 +861,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();
}
@@ -883,18 +889,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();
}
@@ -906,7 +928,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);
@@ -914,13 +936,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());
}
}
}
@@ -1372,7 +1403,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.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java?rev=1464314&r1=1464313&r2=1464314&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java (original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java Thu Apr 4 07:28:15 2013
@@ -134,10 +134,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
@@ -169,7 +177,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"));
@@ -193,6 +225,8 @@ public class JAXRSClientServerSpringBook
DOMUtils.getChildrenWithName(resourcesEl,
WadlGenerator.WADL_NS, "resource");
assertEquals(size, resourceEls.size());
+ return resourceEls;
+
}
@Test
@@ -208,7 +242,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.7.x-fixes/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml?rev=1464314&r1=1464313&r2=1464314&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml (original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml Thu Apr 4 07:28:15 2013
@@ -209,7 +209,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>
Added: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/wadl/bookstoreImportResource.wadl
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/wadl/bookstoreImportResource.wadl?rev=1464314&view=auto
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/wadl/bookstoreImportResource.wadl (added)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/wadl/bookstoreImportResource.wadl Thu Apr 4 07:28:15 2013
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<application xmlns="http://wadl.dev.java.net/2009/02" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:prefix1="http://superbooks">
+
+ <grammars>
+ <include href="schemas/book.xsd"/>
+ </grammars>
+ <resources base="http://localhost:8080/baz">
+ <resource path="/bookstore" id="{wadl.model.jaxrs.cxf.apache.org}BookStore">
+
+ <resource path="/books/{bookid}">
+ <param name="bookid" style="template" type="xs:int"/>
+
+ <method name="POST" id="addBook">
+ <request>
+ <representation mediaType="application/xml" element="prefix1:thebook"/>
+ </request>
+ </method>
+ </resource>
+ </resource>
+ <resource path="/bookstore2" type="bookstoreImportResourceType.wadl#bookstoreType"/>
+
+</resources>
+
+</application>
Added: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/wadl/bookstoreImportResourceType.wadl
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/wadl/bookstoreImportResourceType.wadl?rev=1464314&view=auto
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/wadl/bookstoreImportResourceType.wadl (added)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/resources/wadl/bookstoreImportResourceType.wadl Thu Apr 4 07:28:15 2013
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<application xmlns="http://wadl.dev.java.net/2009/02" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:prefix1="http://superbooks">
+
+ <grammars>
+ <include href="schemas/book.xsd"/>
+ </grammars>
+
+ <method name="POST" id="addBook">
+ <request>
+ <representation mediaType="application/xml" element="prefix1:thebook"/>
+ </request>
+ </method>
+
+ <resource_type id="bookstoreType">
+ <resource path="/books/{bookid}">
+ <param name="bookid" style="template" type="xs:int"/>
+
+ <method href="#addBook"/>
+
+ </resource>
+ </resource_type>
+
+</application>