Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/java/com/mockey/model/UriTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class UriTemplate {
private static final Pattern NAMES_PATTERN = Pattern.compile("\\{([^/]+?)\\}");

/** Replaces template variables in the URI template. */
private static final String VALUE_REGEX = "\\{(.*?)\\}";
private static final String VALUE_REGEX = "(.*)";

private final List<String> variableNames;

Expand Down Expand Up @@ -169,7 +169,7 @@ public boolean matches(String uri) {
if (uri == null) {
return false;
}
Matcher matcher = this.matchPattern.matcher(uri.toLowerCase());
Matcher matcher = this.matchPattern.matcher(uri);
return matcher.matches();
}

Expand Down
23 changes: 7 additions & 16 deletions src/java/com/mockey/storage/InMemoryMockeyStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
package com.mockey.storage;

import java.net.MalformedURLException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
Expand Down Expand Up @@ -247,29 +245,21 @@ public Service getServiceByUrl(String url) {
* @return service if url pattern matches
*/
private Service findServiceBasedOnUrlPattern(String url, Service serviceToEvaluate) {
Service foundService = null;
String decodedUrl = null;
try {
decodedUrl = URLDecoder.decode(url, "UTF-8");
}catch(Exception e) {
System.out.println(e);
return foundService;
}
Url fullUrl = new Url(serviceToEvaluate.getUrl());

Service foundService = null;
// EXAMPLE: "http://example.com/hotels/{hotel}/bookings/{booking}"
UriTemplate template = new UriTemplate(fullUrl.getFullUrl());

// EXAMPLE: "http://example.com/hotels/1/bookings/42"
@SuppressWarnings("rawtypes")
Map results = template.match(decodedUrl);
if (results.size() > 0 && template.matches(decodedUrl)) {
Map results = template.match(url);
if (results.size() > 0) {
// Possible match
foundService = serviceToEvaluate;
} else {

// OK, not found based on template URL.
if (fullUrl.getFullUrl().equalsIgnoreCase(decodedUrl)) {
if (fullUrl.getFullUrl().equalsIgnoreCase(url)) {
foundService = serviceToEvaluate;
} else {
// Let's look at secondary list of real URLs
Expand All @@ -285,8 +275,9 @@ private Service findServiceBasedOnUrlPattern(String url, Service serviceToEvalua
// be
// matched against the url of the request instead.
template = new UriTemplate(altUrl.getFullUrl());
results = template.match(decodedUrl);
if (results.size() > 0 && template.matches(decodedUrl)) {
results = template.match(url);

if (results.size() > 0) {
// Possible match
foundService = serviceToEvaluate;
break;
Expand Down