-
Notifications
You must be signed in to change notification settings - Fork 3.9k
feat(ServletAdapter): Ability remove context path when get method name #11825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
long76
wants to merge
21
commits into
grpc:master
Choose a base branch
from
long76:task-5066-context-path
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
2495095
feat[ServletAdapter]: Ability remove context path when get method name
long76 4bb9d65
fix: getMethod must be not static
long76 2f4aea5
fix: wrong realisation
long76 33ed4c6
fix[ServletAdapter]: java doc
long76 9ffaeb7
fix: code style
long76 bb7a6d4
fix[ServletServerBuilderTest]: compile test
long76 2c1c2f1
fix[bb7a6d4]: var name
long76 27a99bc
fix[HelloWorldServlet]: example
long76 21e48be
fix[ServletServerBuilderTest]: use verify
long76 ed0fdbd
fix: use hardcoded method
long76 2609bca
Merge branch 'grpc:master' into task-5066-context-path
long76 e20b3df
refactor: tests and realization
long76 6c0c161
Merge branch 'grpc:master' into task-5066-context-path
long76 ecb51d4
fix(GrpcServlet): check getServletConfig on null before getInitParam…
long76 8956729
fix(GrpcServlet): getInitParameter in init
long76 68fe5ac
tests: add GrpcServletTest for getMethod
long76 a216eb9
fix(GrpcServlet): import ServletException
long76 76b49cf
style(GrpcServletTest): remove empty line
long76 462b92d
refactor(GrpcServlet): removeContextPath move this assignment to the …
long76 53018ca
docs(GrpcServlet): add comment for REMOVE_CONTEXT_PATH
long76 41a3f02
docs(GrpcServlet): fix typo
long76 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
servlet/src/test/java/io/grpc/servlet/GrpcServletTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2025 The gRPC Authors | ||
* | ||
* 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 io.grpc.servlet; | ||
|
||
import static io.grpc.servlet.GrpcServlet.REMOVE_CONTEXT_PATH; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.doCallRealMethod; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
@RunWith(JUnit4.class) | ||
public class GrpcServletTest { | ||
private static final String EXPECTED_METHOD = "hello/world"; | ||
private static final String CONTEXT_PATH = "/grpc"; | ||
private static final String REQUEST_URI = "/hello/world"; | ||
|
||
@Test | ||
public void defaultMethodTest() throws ServletException { | ||
HttpServletRequest request = mock(HttpServletRequest.class); | ||
GrpcServlet grpcServlet = mock(GrpcServlet.class); | ||
|
||
doCallRealMethod().when(grpcServlet).init(); | ||
grpcServlet.init(); | ||
|
||
doReturn(REQUEST_URI).when(request).getRequestURI(); | ||
when(grpcServlet.getMethod(request)).thenCallRealMethod(); | ||
|
||
assertEquals(EXPECTED_METHOD, grpcServlet.getMethod(request)); | ||
} | ||
|
||
@Test | ||
public void removeContextPathMethodTest() throws ServletException { | ||
HttpServletRequest request = mock(HttpServletRequest.class); | ||
GrpcServlet grpcServlet = mock(GrpcServlet.class); | ||
|
||
doReturn("true").when(grpcServlet).getInitParameter(REMOVE_CONTEXT_PATH); | ||
doCallRealMethod().when(grpcServlet).init(); | ||
grpcServlet.init(); | ||
|
||
doReturn(CONTEXT_PATH + REQUEST_URI).when(request).getRequestURI(); | ||
doReturn(CONTEXT_PATH).when(request).getContextPath(); | ||
when(grpcServlet.getMethod(request)).thenCallRealMethod(); | ||
|
||
assertEquals(EXPECTED_METHOD, grpcServlet.getMethod(request)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.