How to read cookie from org.eclipse.swt.browser.Browser?

Viewed 1910

I want to read JSESSIONID from cookie org.eclipse.swt.browser.Browser. I try to open browser from Eclipse plug-in. I am using below snippet

public static void main(String[] args)
{
    Display display = new Display();

    Shell shell = new Shell(display);
    shell.setText("StackOverflow");
    shell.setLayout(new FillLayout());

    final Browser browser = new Browser(shell, SWT.NONE);

    final String url = "https://....";
    browser.setUrl(url);
    browser.addProgressListener(new ProgressAdapter() {
        @Override
        public void completed(ProgressEvent event) {
            String cookieText = "cookie=" + Browser.getCookie("JSESSIONID", url);
            System.out.println(cookieText);
        }
    });
    shell.setSize(400, 300);
    shell.open();

    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
        {
            display.sleep();
        }
    }

    display.dispose();
}

But I am not getting cookie value.

Something like this : c# Get httponly cookie

2 Answers
Related