Skip to content

Commit

Permalink
[#9502] Backport: Fix path of reactor-netty server
Browse files Browse the repository at this point in the history
  • Loading branch information
jaehong-kim committed Dec 13, 2022
1 parent cddbcc1 commit fdd293e
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@

package com.pinpoint.test.plugin;

import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -82,4 +87,22 @@ public String clientError() {
}
return "OK";
}

@GetMapping("/client/get/param")
@ResponseBody
public String clientGetParam(@RequestParam String id, @RequestParam(name = "password") String pwd) {
return "OK";
}

@PostMapping("/client/post/param")
@ResponseBody
public String clientPostParam(@RequestParam String id, @RequestParam(name = "password") String pwd) {
return "OK";
}

@PostMapping("/client/post/body")
@ResponseBody
public String clientPostParam(@RequestBody String body) {
return "OK";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;
Expand Down Expand Up @@ -74,4 +76,22 @@ public Mono<String> clientUnknown() {
.uri("").retrieve();
return response.bodyToMono(String.class);
}

@GetMapping("/client/get/param")
public Mono<String> clientGetParam(@RequestParam String id, @RequestParam(name = "password") String pwd) {
final String param = "id=" + id + "&password=" + pwd;
return Mono.just(param);
}

@PostMapping("/client/post/param")
public Mono<String> clientPostParam(@RequestParam String id, @RequestParam(name = "password") String pwd) {
final String param = "id=" + id + "&password=" + pwd;
return Mono.just(param);
}

@PostMapping("/client/post/body")
@ResponseBody
public String clientPostParam(@RequestBody String body) {
return "OK";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public Collection<String> getHeaderNames(HttpServerRequest request) {
@Override
public String getRpcName(HttpServerRequest request) {
try {
return request.uri();
final String path = UriUtils.path(request.uri());
return path;
} catch (Exception ignored) {
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public HttpServerParameterExtractor(int eachLimit, int totalLimit) {
public String extractParameter(HttpServerRequest request) {
final Map<String, String> parameterMap = request.params();
if (parameterMap == null) {
// If parametersResolver object is not specified.
final String params = UriUtils.params(request.uri());
if (params != null) {
return StringUtils.abbreviate(params, totalLimit);
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2022 NAVER Corp.
*
* Licensed 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.
*/

package com.navercorp.pinpoint.plugin.reactor.netty.interceptor;

public class UriUtils {

public static String path(final String uri) {
if (uri == null) {
return null;
}

String path = uri;
int index = path.indexOf('?');
if (index > -1) {
path = path.substring(0, index);
}
index = path.indexOf('#');
if (index > -1) {
path = path.substring(0, index);
}

return path;
}

public static String params(final String uri) {
if (uri == null) {
return null;
}

String params = uri;
int index = params.indexOf('?');
if (index == -1) {
return null;
}
params = params.substring(index + 1, params.length());
index = params.indexOf('#');
if (index > -1) {
params = params.substring(0, index);
}

return params;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2022 NAVER Corp.
*
* Licensed 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.
*/

package com.navercorp.pinpoint.plugin.reactor.netty.interceptor;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class UriUtilsTest {

@Test
public void path() throws Exception {
assertEquals("", UriUtils.path(""));
assertEquals("/", UriUtils.path("/"));
assertEquals("//", UriUtils.path("//"));
assertEquals("///", UriUtils.path("///"));
assertEquals("/foo", UriUtils.path("/foo"));
assertEquals("/foo/", UriUtils.path("/foo/"));
assertEquals("/", UriUtils.path("/?bar"));
assertEquals("/foo", UriUtils.path("/foo?bar"));
assertEquals("/", UriUtils.path("/#bar"));
assertEquals("/foo", UriUtils.path("/foo#bar"));
assertEquals("/foo", UriUtils.path("/foo?bar#baz"));
assertEquals("/foo", UriUtils.path("/foo?bar={}"));
}

@Test
public void params() throws Exception {
assertEquals(null, UriUtils.params("/"));
assertEquals(null, UriUtils.params("/foo"));
assertEquals(null, UriUtils.params("/foo&bar"));
assertEquals("bar=baz", UriUtils.params("/foo?bar=baz"));
assertEquals("bar=baz", UriUtils.params("/?bar=baz"));
assertEquals("bar=baz", UriUtils.params("?bar=baz"));
assertEquals("bar", UriUtils.params("?bar"));
assertEquals("bar={}", UriUtils.params("/foo?bar={}"));
}
}

0 comments on commit fdd293e

Please sign in to comment.