Skip to content

feat: [REQ-008] Add CockpitServer on port 6051#14711

Closed
sonthien22501 wants to merge 3 commits intoJabRef:mainfrom
sonthien22501:feat/researcher-cockpit-server
Closed

feat: [REQ-008] Add CockpitServer on port 6051#14711
sonthien22501 wants to merge 3 commits intoJabRef:mainfrom
sonthien22501:feat/researcher-cockpit-server

Conversation

@sonthien22501
Copy link
Copy Markdown
Contributor

Summary

This PR implements the backend infrastructure for the "Researcher Cockpit" browser extension, satisfying REQ-008 (Bidirectional Communication).

It introduces a lightweight HTTP server (CockpitServer) running inside JabRef that allows external browser plugins to communicate with the active JabRef instance.

Technical Details

  • New Class: org.jabref.gui.remote.CockpitServer
  • Port: 6051 (Chosen to avoid conflict with JabRef's existing internal remote port 6050).
  • Endpoints Implemented:
    • GET /ping: Returns connectivity status.
    • POST /check-existence: Accepts a JSON payload ({"url": "..."}) and currently returns a mocked response.
  • Concurrency: The server runs on a separate thread to avoid blocking the JavaFX UI.

How to Test

  1. Run JabRef from IntelliJ.
  2. Verify console log: Researcher Cockpit Server started on port 6051.
  3. Open a terminal or browser and access http://localhost:6051/ping.
  4. Expected response: {"status": "connected", "message": "JabRef is listening!"}.

Checklist

  • Server starts/stops with JabRef.
  • CORS headers enabled (allows browser extension access).
  • No conflict with existing remote listener.

Closes _____

Steps to test

Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • [.] I manually tested my changes in running JabRef (always required)
  • [.] I added JUnit tests for changes (if applicable)
  • [.] I added screenshots in the PR description (if change is visible to the user)
  • [.] I described the change in CHANGELOG.md in a way that is understandable for the average user (if change is visible to the user)
  • [.] I checked the user documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request updating file(s) in https://github.com/JabRef/user-documentation/tree/main/en.

@github-actions
Copy link
Copy Markdown
Contributor

Hey @sonthien22501! 👋

Thank you for contributing to JabRef!

We have automated checks in place, based on which you will soon get feedback if any of them are failing.

After all automated checks pass, a maintainer will also review your contribution. Once that happens, you can go through their comments in the "Files changed" tab and act on them, or reply to the conversation if you have further inputs.

Please re-check our AI Usage Policy to ensure that your pull request is in line with it. It also contains links to our contribution guide in case of any other doubts related to our contribution workflow.

@jabref-machine
Copy link
Copy Markdown
Collaborator

Note that your PR will not be reviewed/accepted until you have gone through the mandatory checks in the description and marked each of them them exactly in the format of [x] (done), [ ] (not done yet) or [/] (not applicable). Please adhere to our pull request template.

@github-actions github-actions Bot added the status: changes-required Pull requests that are not yet complete label Dec 24, 2025
Copy link
Copy Markdown
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code should go into jabsrv

@koppor
Copy link
Copy Markdown
Member

koppor commented Dec 24, 2025

Code should go into jabsrv

I mean: integrated there. Read the code there. Especially resources and GSon.

@sonthien22501
Copy link
Copy Markdown
Contributor Author

Changes in this update:

  • Moved Logic: Extracted the business logic out of CockpitServer into a dedicated resource: org.jabref.http.server.resources.CheckExistenceResource.

  • Implemented DTOs: Created CheckExistenceRequest and CheckExistenceResponse in org.jabref.http.dto to strictly define the JSON structure.

  • Adopted Gson: Replaced all manual string concatenation with Gson serialization for safety and consistency.

  • Package Structure: Ensured all files are correctly placed in the jabsrv module.

@jabref-machine
Copy link
Copy Markdown
Collaborator

Your code currently does not meet JabRef's code guidelines. IntelliJ auto format covers some cases. There seem to be issues with your code style and autoformat configuration. Please reformat your code (Ctrl+Alt+L) and commit, then push.

In special cases, consider using // formatter:off and // formatter:on annotations to allow deviation from the code style.

Copy link
Copy Markdown
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that the AI is not configured properly. Please guide it to follow AGENTS.md. Maybe, it need to be refined.


private static final Logger LOGGER = LoggerFactory.getLogger(CockpitServer.class);
private static final int PORT = 6051;
private HttpServer server;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Use existing framework

import org.slf4j.LoggerFactory;

/**
* It reads the JSON, checks the logic, and sends back JSON.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sonthien22501
Copy link
Copy Markdown
Contributor Author

sonthien22501 commented Dec 24, 2025

Following our discussion regarding the previous PR, I have decided to close it and delete that codebase to ensure I fully understand every line I commit. I want to align strictly with the project's quality standards.

Current Progress: Instead of generating a new server implementation, I dug into the existing jabsrv module. I discovered that JabRef already has a robust HttpServerManager based on Grizzly.

I have successfully:

Located the existing server logic and identified why it wasn't starting (hidden preferences).

Enabled the server locally (port 6051) and verified the connection from a browser using the existing REST endpoints.

@koppor
Copy link
Copy Markdown
Member

koppor commented Dec 24, 2025

@sonthien22501 Nice. Its a learning path. No need to know everything right at the beginning. Its a journey. Aim is knowledge and experience growth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

first contrib status: changes-required Pull requests that are not yet complete

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants