I had a Swing dialog that uses JavaFX WebView to display oAuth 2.0 URLs from a Google server.
public class SimpleSwingBrowser extends JDialog { private final JFXPanel jfxPanel = new JFXPanel(); private WebEngine engine; private final JPanel panel = new JPanel(new BorderLayout()); public SimpleSwingBrowser() { super(MainFrame.getInstance(), JDialog.ModalityType.APPLICATION_MODAL); initComponents(); } private void initComponents() { createScene(); panel.add(jfxPanel, BorderLayout.CENTER); getContentPane().add(panel); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); setBounds((screenSize.width-460)/2, (screenSize.height-680)/2, 460, 680); } private void createScene() { Platform.runLater(new Runnable() { @Override public void run() { final WebView view = new WebView(); engine = view.getEngine(); engine.titleProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, final String newValue) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { SimpleSwingBrowser.this.setTitle(newValue); } }); } }); engine.getLoadWorker() .exceptionProperty() .addListener(new ChangeListener<Throwable>() { public void changed(ObservableValue<? extends Throwable> o, Throwable old, final Throwable value) { if (engine.getLoadWorker().getState() == FAILED) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JOptionPane.showMessageDialog( panel, (value != null) ? engine.getLocation() + "\n" + value.getMessage() : engine.getLocation() + "\nUnexpected error.", "Loading error...", JOptionPane.ERROR_MESSAGE); } }); } } });
Each time, I get the following URL from Google. I will use SimpleSwingBrowser to load the following URL.
https://accounts.google.com/o/oauth2/auth?client_id=xxx&redirect_uri=http://localhostORE5757/Callback&response_type=code&scope=email%20https://www.googleapis.com/auth/drive.appdata% 20profile
During the first time , the following user interface will be displayed.
Screen 1

Screen 2

After I
- Log in successfully on the One screen.
- Presented with screen 2.
- Click Accept.
- Close the web browser dialog.
- Again, create the same URL as the first time.
- Create a completely new instance of
SimpleSwingBrowser to load the URL generated in step
I expect Google to show me Screen One again, as this is a new browsing session. However, what I get the second time is Screen Two.
It appears that WebView has several stored sessions / cache / cookie, although this is a completely new instance.
I expect to return to Screen One to support multiple user accounts.
How to clear session / cache / cookie in WebView ?
Cheok yan cheng
source share