use of com.teamdev.jxbrowser.net.callback.InterceptUrlRequestCallback in project JxBrowser-Examples by TeamDev-IP.
the class LoadHtmlThroughInterceptRequest method main.
public static void main(String[] args) {
InterceptUrlRequestCallback interceptCallback = params -> {
if (params.urlRequest().url().endsWith("?load-html")) {
byte[] bytes = "<html><body>Hello!</body></html>".getBytes();
UrlRequestJob job = params.newUrlRequestJob(UrlRequestJob.Options.newBuilder(HttpStatus.OK).addHttpHeader(HttpHeader.of("Content-Type", "text/html")).build());
job.write(bytes);
job.complete();
return InterceptUrlRequestCallback.Response.intercept(job);
}
return InterceptUrlRequestCallback.Response.proceed();
};
Engine engine = Engine.newInstance(EngineOptions.newBuilder(HARDWARE_ACCELERATED).addScheme(Scheme.HTTP, interceptCallback).build());
Browser browser = engine.newBrowser();
SwingUtilities.invokeLater(() -> {
BrowserView view = BrowserView.newInstance(browser);
JFrame frame = new JFrame("Load Local Files");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
browser.navigation().loadUrl("http://localhost?load-html");
}
Aggregations