Skip to content

Commit

Permalink
Merge branch '2.5.x' into 3.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Jun 10, 2015
2 parents dd631d7 + 7ff0e68 commit 9df41e0
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ public class GrailsWrappedRuntimeException extends GrailsException {
*/
public GrailsWrappedRuntimeException(ServletContext servletContext, Throwable t) {
super(t.getMessage(), t);
cause = t;
this.cause = t;
Throwable cause = t;

FastStringPrintWriter pw = FastStringPrintWriter.newInstance();
cause.printStackTrace(pw);
stackTrace = pw.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ private UrlCreator resolveUrlCreator(final String controller,
@SuppressWarnings("unchecked")
protected UrlMapping lookupMapping(String controller, String action, String namespace, String pluginName, String httpMethod, String version, Map params) {
final UrlMappingsListKey lookupKey = new UrlMappingsListKey(controller, action, namespace, pluginName, httpMethod, version);
SortedSet mappingKeysSet = mappingsListLookup.get(lookupKey);
Collection mappingKeysSet = mappingsListLookup.get(lookupKey);

final String actionName = lookupKey.action;
boolean secondAttempt = false;
Expand Down Expand Up @@ -800,19 +800,23 @@ public String toString() {

class UrlMappingsList {
// A map from a UrlMappingsListKey to a list of UrlMappingKeys
private Map<UrlMappingsListKey, SortedSet<UrlMappingKey>> lookup =
new HashMap<UrlMappingsListKey, SortedSet<UrlMappingKey>>();
private Map<UrlMappingsListKey, List<UrlMappingKey>> lookup =
new HashMap<UrlMappingsListKey, List<UrlMappingKey>>();

public void put(UrlMappingsListKey key, UrlMappingKey mapping) {
SortedSet<UrlMappingKey> mappingsList = lookup.get(key);
List<UrlMappingKey> mappingsList = lookup.get(key);
if (null == mappingsList) {
mappingsList = new TreeSet<UrlMappingKey>();
mappingsList = new ArrayList<UrlMappingKey>();
lookup.put(key, mappingsList);
}
mappingsList.add(mapping);
if(!mappingsList.contains(mapping)) {

mappingsList.add(mapping);
Collections.sort(mappingsList);
}
}

public SortedSet<UrlMappingKey> get(UrlMappingsListKey key) {
public Collection<UrlMappingKey> get(UrlMappingsListKey key) {
return lookup.get(key);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.codehaus.groovy.grails.web.mapping

import grails.web.CamelCaseUrlConverter
import org.grails.web.mapping.DefaultLinkGenerator
import org.grails.web.mapping.DefaultUrlMappingEvaluator
import org.grails.web.mapping.DefaultUrlMappingsHolder
import org.springframework.mock.web.MockServletContext
import spock.lang.Issue
import spock.lang.Specification

/*
* Copyright 2014 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); resource: 'book', id: 1
* 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.
*/

/**
* @author graemerocher
*/
class OverlappingParametersReverseMappingSpec extends Specification{
def baseUrl = "http://myserver.com/foo"
def context = null

def mappings = {
"/books/$id(.$format)?"(controller:'book'){
action = [GET: 'show', PUT: 'update', POST: 'update', DELETE: 'delete']
}
"/books(.$format)?"(controller:'book'){
action = [GET: 'index', PUT: 'unsupported', POST: 'save', DELETE: 'unsupported']
}
}


@Issue('https://github.com/grails/grails-core/issues/657')
void "Test that reverse mapping with overlapping parameters works"() {
expect:
generator.link(resource: 'book', id: 1) == 'http://myserver.com/foo/books/1'
}


protected getGenerator() {
def generator = new DefaultLinkGenerator(baseUrl, context)
def evaluator = new DefaultUrlMappingEvaluator(new MockServletContext())
generator.urlMappingsHolder = new DefaultUrlMappingsHolder(evaluator.evaluateMappings(mappings ?: {}))
generator.grailsUrlConverter = new CamelCaseUrlConverter()
generator
}

}

0 comments on commit 9df41e0

Please sign in to comment.