Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 25fa5d9

Browse files
Marek PotociarGerrit Code Review
authored andcommitted
Merge "Path formatting fixed - double slash eliminated."
2 parents 1840c67 + d819f81 commit 25fa5d9

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

core-server/src/main/java/org/glassfish/jersey/server/internal/monitoring/MonitoringStatisticsImpl.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2013-2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2013-2015 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -110,14 +110,21 @@ public int compare(final Class<?> o1, final Class<?> o2) {
110110
for (final Resource resource : resourceModel.getRootResources()) {
111111
processResource(resource, "");
112112
for (final Resource child : resource.getChildResources()) {
113-
processResource(child, "/" + resource.getPath());
113+
final String path = resource.getPath();
114+
processResource(child, path.startsWith("/") ? path : "/" + path);
114115
}
115116
}
116117

117118
}
118119

119120
private void processResource(final Resource resource, final String pathPrefix) {
120-
uriStatistics.put(pathPrefix + "/" + resource.getPath(), new ResourceStatisticsImpl.Builder(resource, methodFactory));
121+
final StringBuilder pathSB = new StringBuilder(pathPrefix);
122+
if (!pathPrefix.endsWith("/") && !resource.getPath().startsWith("/")) {
123+
pathSB.append("/");
124+
}
125+
pathSB.append(resource.getPath());
126+
127+
uriStatistics.put(pathSB.toString(), new ResourceStatisticsImpl.Builder(resource, methodFactory));
121128

122129
for (final ResourceMethod resourceMethod : resource.getResourceMethods()) {
123130
getOrCreateResourceBuilder(resourceMethod).addMethod(resourceMethod);

core-server/src/test/java/org/glassfish/jersey/server/internal/monitoring/MonitoringStatisticsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2013-2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2013-2015 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -70,7 +70,7 @@
7070
*/
7171
public class MonitoringStatisticsTest {
7272

73-
@Path("test-resource")
73+
@Path("/test-resource")
7474
public static class TestResource {
7575

7676
@GET
@@ -109,7 +109,7 @@ public String get() {
109109
public void post() {
110110
}
111111

112-
@Path("world")
112+
@Path("/world")
113113
@GET
114114
public String childGet() {
115115
return "hello-world";
@@ -146,7 +146,7 @@ private MonitoringStatisticsImpl getSimpleStats() {
146146

147147
private MonitoringStatisticsImpl.Builder getProgStats() {
148148
final Resource.Builder testBuilder = Resource.builder(TestResource.class);
149-
testBuilder.addChildResource("prog-child").addMethod("GET").handledBy(MyInflector.class);
149+
testBuilder.addChildResource("/prog-child").addMethod("GET").handledBy(MyInflector.class);
150150
final List<Resource> resources = Lists.newArrayList(testBuilder.build(),
151151
Resource.from(HelloResource.class));
152152
final Resource.Builder prog = Resource.builder("prog");

0 commit comments

Comments
 (0)