JDK-8307211 : WEBBROWSER BLOCKED BY CLOUDFLARE (LOOP)
  • Type: Bug
  • Component: javafx
  • Sub-Component: web
  • Affected Version: 8u371
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2023-04-23
  • Updated: 2023-05-02
  • Resolved: 2023-05-02
Related Reports
Duplicate :  
Description
ADDITIONAL SYSTEM INFORMATION :
WINDOWS 10 
JRE8u371

A DESCRIPTION OF THE PROBLEM :
LOOP WHEN CONNECTING TO WEBSITE




---------- BEGIN SOURCE ----------
package Application;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

import com.sun.javafx.application.PlatformImpl;

import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
import javafx.concurrent.Worker.State;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

public class CL_Application {

	private JTabbedPane tab = null;
	
	public static void main(String[] args) {
		System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
		System.setProperty("sun.webkit.useHTTP2Loader", "false");
		//System.setProperty("java.net.useSystemProxies", "false");
		
		Thread.currentThread().setPriority(Thread.MIN_PRIORITY); 
		
		new CL_Application();
	}
	
	public CL_Application() {
		JFrame f = new JFrame();
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		tab = new JTabbedPane();
		tab.setPreferredSize(new Dimension(800, 600));
		tab.addTab("#0#", new CL_SwingFXWebView());
		tab.addTab("#1#", new CL_SwingFXWebView());
		tab.addTab("#2#", new CL_SwingFXWebView());
		f.add(tab, BorderLayout.CENTER);
		f.pack();
		f.setLocationRelativeTo(null);
		f.setVisible(true);
		
		((CL_SwingFXWebView)tab.getComponentAt(0)).load("https://www.google.com/");
		((CL_SwingFXWebView)tab.getComponentAt(1)).load("https://www.yell.com/");
		((CL_SwingFXWebView)tab.getComponentAt(2)).load("https://www.pagesjaunes.fr/");
	}

	public class CL_SwingFXWebView extends JPanel {  

		private static final long serialVersionUID = 8990771757800321056L;
		
		private Stage stage = null;
		private WebView browser = null;  
		private JFXPanel jfxPanel = null;
		private WebEngine webEngine = null;  

		public CL_SwingFXWebView() {
			jfxPanel = new JFXPanel();  
			
			PlatformImpl.startup(new Runnable() {  

				public void run() {  
					stage = new Stage();
					Group root = new Group();  
					Scene scene = new Scene(root);
					stage.setScene(scene);  

					browser = new WebView();
					browser.setContextMenuEnabled(false);
					webEngine = browser.getEngine();
	                webEngine.setJavaScriptEnabled(true);

					TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
						
						public void checkClientTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws java.security.cert.CertificateException {}

						public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException {}
						
						public java.security.cert.X509Certificate[] getAcceptedIssuers() {
							return null;
						}
					}};

					SSLContext sc = null;
					try {
						sc = SSLContext.getInstance("SSL");
						sc.init(null, trustAllCerts, new java.security.SecureRandom());
					} catch (NoSuchAlgorithmException e) {
						e.printStackTrace();
					} catch (KeyManagementException e) {
						e.printStackTrace();
					}
	              	
					HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
					
					webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {

						public void changed(ObservableValue<? extends State> ov, State oldState, State newState) {

							if (newState == State.RUNNING) {
							}
							if (newState == State.SUCCEEDED) {
							}
						}
					});

					ObservableList<Node> children = root.getChildren();
					children.add(browser);                     

					jfxPanel.setScene(scene);  
				}  
			});

			setLayout(new BorderLayout());  
			add(jfxPanel, BorderLayout.CENTER);
		}

		public void load(final String _sURL) {
	        
	    	Platform.runLater(new Runnable() {

	        	public void run() {
	        		webEngine.load(_sURL);
	        	}
	        });
	    }
	}
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
Duplicate of JDK-8281048
02-05-2023