-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Add field to change HTTP port #13479
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
Conversation
koppor
left a comment
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.
Did you use a web browser connecting? (http://localhost:23119 is default)
Try to change the port to 8892 and then connect to http://localhost:8892.
If if fails, you probably did not change getHttpServerUri() {
| public @NonNull URI getHttpServerUri() { | ||
| try { | ||
| return new URI("http://" + RemotePreferences.getIpAddress().getHostAddress() + ":23119"); | ||
| return new URI("http://" + RemotePreferences.getIpAddress().getHostAddress() + ":" + getHttpPort()); |
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.
Do you think, you are able to add another validator for checking that an URI can be constructed?
Extract this line into a new method. The validator calls it and if there is an exception, the host is invalid.
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'll attempt to do that.
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.
Do you mean attempt to test an HTTP connection or just making sure the IP Address is in the correct format along with everything else?
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.
just ensuring that new URI( does not throw any exception - no self-implemented checks, just re-use waht's offered by JAva
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'm confused since new URI throws the URISyntaxException - before my changes. I changed the code a few days ago to have a method isUriValid, but I'm not sure if it is necessary. Unfortunately, I believe I need some guidance on this.
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.
Maybe, its too complicated. Just add a validator. Don't use isValid here - just construct the URL
However, construct the URL in isValid and here THE SAME WAY.
THERE: With multiple parameters to URI constructor (which is better than the existing code)
HERE: Stirng concatination (existing code)
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.
So do not use isValid here - which I'm assuming is above the return statement on line 100 (or line 110 with recent push with my changes). But construct the URL in isValid and here the same way - confused by this.
However, what I believe is meant by there is the declaration of the isValid method - I changed this to only accept two params.
Based on my recent push, I put the validator above the returned URI - which includes the construction of the concatenated string in the param.
Just making sure I'm understanding this correctly.
| <Label styleClass="sectionHeader" text="%HTTP Server" /> | ||
| <CheckBox fx:id="enableHttpServer" text="%Enable HTTP Server (e.g., for JabMap)" /> | ||
| <HBox alignment="CENTER_LEFT" spacing="10.0"> | ||
| <CheckBox fx:id="enableHttpServer" text="%Enable HTTP Server (e.g., for JabMap)" /> |
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.
Maybe also add on port to the end of the text to clarify that the integer value refers to a port
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.
What about line 88? Would the id name httpServerPort be enough to clarify that's it's a port?
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.
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.
Oh! Okay, I understand now.
…ableHttpServer in GeneralTab.fxml
| return InetAddress.getByName("localhost"); | ||
| } | ||
|
|
||
| private boolean isUriValid(String protocol, String hostAddress, int port) { |
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.
Try to use this in a validator...
Create a method accepting host AND port. - Nothing else
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.
So I changed the validator to only accept host and port. This has been pushed. Is it fine as it is to only return a boolean?
| public @NonNull URI getHttpServerUri() { | ||
| try { | ||
| return new URI("http://" + RemotePreferences.getIpAddress().getHostAddress() + ":23119"); | ||
| isUriValid(RemotePreferences.getIpAddress().getHostAddress(), getHttpPort()); |
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.
The isUriValid method's return value is ignored, making the call redundant. The method should either be removed or its result should be used to handle invalid URIs.
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 can change the return statement here to use isUriValid to return a URI object instead of a boolean.
koppor
left a comment
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 think, I was wrong with the validation idea.
I streamlined the isValid method - and now its good to go. Thank you for your work.
|
@trag-bot didn't find any issues in the code! ✅✨ |
|
|
||
| @Test | ||
| void isDifferentHttpPortTrue() { | ||
| assertTrue(preferences.isDifferentHttpPort(4000)); |
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.
Using assertTrue with a boolean condition instead of asserting the actual values. Should use assertEquals to compare the actual HTTP port values for better test clarity and error messages.
|
|
||
| @Test | ||
| void isDifferentHttpPortFalse() { | ||
| assertFalse(preferences.isDifferentHttpPort(3000)); |
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.
Using assertFalse with a boolean condition instead of asserting the actual values. Should use assertEquals to compare the actual HTTP port values for better test clarity and error messages.
Thank you for the feedback. Yeah, I looked into how URI construction can use parameters instead of a string. Aside from that, I definitely believed I missed the big picture at some point |
* upstream/main: Also label PR if good first issue is made (#13526) New Crowdin updates (#13529) chore(deps): update dependency org.apache.logging.log4j:log4j-to-slf4j to v2.25.1 (#13528) chore: bump-okhttp-4.12.0-to-5.0.0 (#13521) Have the picker always on top (#13525) Refactor PushToApplications and split into logic and GUI (#13514) Add field to change HTTP port (#13479) Fix trigger of comment Use Java 11 isBlank (#13523) Add run openrewrite (#13524) Comment ion PR just opened (#13522) Improve merge logic to prefer valid year and entry type (#13506) Update dependency com.konghq:unirest-modules-gson to v4.4.12 (#13517) Add rpm target (#13516) Revert module name changes for remaining 'unnamed' Jars (#13515) fix: revert Java module names to restore Status Log compatibility in JabRef 5.15 (#13511) update java vendor in devcontainer and sdkmanrc (#13513)

Closes #13463
My intended steps is to update all classes and configuration files to be able to change the HTTP port. I would like feedback to accomplish this which includes removing or adding lines of code.
Steps to test
You can test this task by building the application and checking JabRef preferences -> general -> HTTP Server and check to see if the box in the section has the port number 23119. Next, run the test on line 10 in the RemotePreferencesTest class.
Mandatory checks
CHANGELOG.mddescribed in a way that is understandable for the average user (if change is visible to the user)