-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat[ServletAdapter]: Ability remove context path when get method name #11730
Conversation
Could you please describe the problem you are trying to solve? |
I use Wildfly 24 and need use non root context( |
No.
They are not real clients, but UI tools to send arbitrary requests to server for development purposes. |
Yeah, there's not going to be clients that work with this. It sounds like you would get testing infrastructure running, but once you try to make real clients you're going to have problems. |
@ejona86 local fork works great on Wildfly 24, my patch do not break backward compatibility |
The server is irrelevant. We were saying the clients won't support this as gRPC doesn't support this. |
This will work with proxy. Nginx > Wildfly > GRPCServlet works. I do not see limitations for support this for GRPCServlet. |
@long76 Do you mean ngx_http_grpc_module ? |
😏Just try this config for nginx:
P.S. i don't know it's bug or feature nginx but i glad this flexibility) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't REMOVE_CONTEXT_PATH mean that you must put the servlet under its own "folder" because it will need a wildcard for the full service/method. So where your app may be /app1, you'd then have to do something like /app1/grpc/* for the servlet so that the requested path is /app1/grpc/helloworld.Greeter/SayHello?
@@ -110,7 +111,8 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOExc | |||
* <p>Do not modify {@code req} and {@code resp} before or after calling this method. However, | |||
* calling {@code resp.setBufferSize()} before invocation is allowed. | |||
*/ | |||
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleting this breaks compatibility. If you have to modify the helloworld example (hard-coding a string no less!), then that clearly is API-breaking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree that hard-coded
string is bad but for now i dont found better solution, i need more time or you can suggest smth
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't follow the difficulty.
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
doPost(req.getRequestURI().substring(1), req, resp);
}
@@ -58,6 +59,16 @@ private static ServletAdapter loadServices(List<? extends BindableService> binda | |||
return serverBuilder.buildServletAdapter(); | |||
} | |||
|
|||
private String getMethod(HttpServletRequest req) { | |||
Boolean removeContextPath = Boolean.parseBoolean(getInitParameter(REMOVE_CONTEXT_PATH)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be done per-request. We should do this in init instead, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree, fix it soon
@@ -58,6 +59,16 @@ private static ServletAdapter loadServices(List<? extends BindableService> binda | |||
return serverBuilder.buildServletAdapter(); | |||
} | |||
|
|||
private String getMethod(HttpServletRequest req) { | |||
Boolean removeContextPath = Boolean.parseBoolean(getInitParameter(REMOVE_CONTEXT_PATH)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Boolean/boolean/
String method = req.getRequestURI(); | ||
if (removeContextPath) { | ||
// remove context path used in application server | ||
method = method.substring(req.getContextPath().length()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this mostly the same as req.getPathInfo()
? I wouldn't expect to need to do any string manipulation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, at first I thought the same thing. only getContextPath()
needed. see https://coderanch.com/t/610432/certification/getContextPath-getServletPath-getPathInfo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, you are making it relative to the deployment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah)
in our case we create dedicated |
new pull #11825 |
@long76 Have you considered name-based virtual hosting? and then deploy this code as ROOT.war in the "mygrpc" host. |
yeah, but we need our business logic from our app. we use ejb for access data from other |
@long76 There is also an "enterprise" way - you could use a servlet filter. |
yeah but it doesn't work) it's was first that i try) maybe i make mistake somewhere |
@long76 it seems like in your gRPC servlet class in new HttpServletRequestWrapper(req) {
@Override
public String getRequestURI() {
return super.getRequestURI().replaceFirst("^/grpc", "");
}
}; As your setup does not quite match the current state of gRPC- not clear if the related changes should be in the library. |
Yeah, but no)
Yes my changes does not match grpc library but it's very useful for application server users and finally it's easy realize in library) |
@long76 you can copy |
Copy paste 😒 i better use our release with patch) |
Refs: #5066
Complex application may have many
war
-s and do not allow monopolize root context path(/
). Add ability to remove context path(usual it'swar
name) from application server use@WebInitParam
or just overridegetInitParameter
for parameterGrpcServlet.REMOVE_CONTEXT_PATH
https://stackoverflow.com/a/42706412