JxBrowser does not refresh - caching

I am currently using JxBrowser as an embedded browser in my Java application. I create a browser like below:
public static void main(String[] args) {
Browser browser = new Browser();
BrowserView browserView = new BrowserView(browser);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.add(browserView, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
browser.loadURL("https://developer.microsoft.com/en-us/graph");
frame.addWindowListener(new WindowListener() {
#Override
public void windowClosing(WindowEvent e) {
}
#Override
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void windowClosed(WindowEvent arg0) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(browserView, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
browser.getCacheStorage().clearCache();
browser.loadURL("https://developer.microsoft.com/en-us/graph");
}
#Override
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
});
}
When the first URL is opened, I sign in and choose to not keep me signed in. I then close that window and when the second window opens, I see that my user is still logged in. As you can see I am clearing cache as well before opening the URL the second time. But the cache is not cleared.

I am not sure that the issue is related to caching. Would you please create a simple sample that can be used for reproducing the issue from my end?

Related

Spring AOP Not working properly

I'm trying to handle exceptions with AOP approach in my Spring/Swing Application and I couldn't make it work.
Main Class:
public class MainFrame extends JFrame {
private JPanel mainPanel;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainFrame frame = new MainFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public MainFrame() {
initializeMainPanel();
}
private void initializeMainPanel() {
exitLabel.addMouseListener(new MouseAdapter() {
#Override
public void mouseClicked(MouseEvent arg0) {
throw new Exception("test");
}
});
}
}
Aspect Class:
#Aspect
public class AspectTest{
#AfterThrowing(pointcut = "execution(* com.test.MainFrame.*(..))", throwing = "ex")
public void logError(Exception ex) throws Throwable {
// ex.printStackTrace();
}
}
So, I throw an exception within my Mouse Listener and expect to catch it in my AspectTest class' AfterThrowing method but it does not work.
Can someone please help me to understand what I'm missing here?
#AfterThrowing cannot catch exceptions, only notice them and log them or do something similar. If you want to handle exceptions in an aspect you need to use an #Around advice.

Update JavaFX scene graph from a Thread

I need to update my GUI based on client input. Calling my controller class method, from the background task works. But it can't update the GUI, because it is not the JavaFX application thread..please help.
I tried many of the related Q & A, but I am still confused.
Should I use Platform. runLater or Task ?
Here's my class where I create an instance of controller class
public class FactoryClass {
public static Controller_Gui1 createGUI() {
FXMLLoader fxLoader = new FXMLLoader();
fxLoader.setLocation(MainApp_Gui1.class.getResource("/com/Gui_1.fxml"));
AnchorPane anchorPane = null;
try {
anchorPane = (AnchorPane) fxLoader.load();
} catch (IOException e) {
e.printStackTrace();
}
Controller_Gui1 controller_Gui1 = (Controller_Gui1) fxLoader
.getController();
Scene scene = new Scene(anchorPane);
//System.out.println(scene);
controller_Gui1.setScene(scene);
return controller_Gui1;
}
}
Controller class
#FXML
Button B1 = new Button();
#FXML
public void handleButton1() {
B1.setDisable(true);
}
Application class
public class MainApp_Gui1 extends Application {
Controller_Gui1 cGui;
#Override
public void start(Stage primaryStage) throws Exception {
initScene(primaryStage);
primaryStage.show();
System.out.println("asdasd");
SceneSetting sceneSetting = new SceneSetting();
//handleEvent();
System.out.println("after");
sceneSetting.setSceneAfter();
System.out.println("after2");
}
// creating scene
private void initScene(Stage primaryStage) throws IOException {
primaryStage.setScene(getScene(primaryStage));
}
public Scene getScene(Stage primaryStage) {
Controller_Gui1 cGui;
cGui = FactoryClass.createGUI();
return cGui.getScene();
}
public void ExcessFromOutside() {
Platform.runLater(new Runnable() {
public void run() {
System.out.println(Platform.isFxApplicationThread());
cGui.handleButton1();
}
});
}
public static void main(String[] args) {
launch(args);
}
}
I want to call ExcessFromOutside() method from another thread.
I got a null pointer exception while trying to update the GUI
Here's my application class
public class MainAppGui1 extends Application {
Controller_Gui1 controller_Gui1;
#Override
public void start(Stage primaryStage) throws Exception {
initScene(primaryStage);
primaryStage.show();
}
// creating scene
public void initScene(Stage primaryStage) throws IOException {
FXMLLoader fxLoader = new FXMLLoader();
fxLoader.setLocation(MainApp_Gui1.class.getResource("/com/Gui_1.fxml"));
AnchorPane anchorPane=new AnchorPane();
anchorPane = (AnchorPane) fxLoader.load();
Controller_Gui1 controller_Gui1 = (Controller_Gui1) fxLoader.getController();
Scene scene = new Scene(anchorPane);
primaryStage.setScene(scene);
}
#FXML
public void ExcessFromOutside()
{
Platform.runLater(new Runnable() {
#Override
public void run() {
System.out.println("called atleast");
controller_Gui1.handleButton1();
}
});
}
public static void main(String[] args) {
launch(args);
}
}
and this is the class from where i tried to update the GUI
public class Hudai {
public static void main(String args[]) throws InterruptedException
{
new Thread()
{
public void run()
{
MainAppGui1.main(null);
}
}.start();
Thread.sleep(5000);
MainAppGui1 m = new MainAppGui1();
m.ExcessFromOutside();
}
}
To disable your button in a different thread you can use Task's updateValue.
Task<Boolean> task = new Task<Boolean>() {
#Override
public Boolean call() {
... // The task that this thread needs to do
updateValue(true);
...
return null;
}
};
button.disableProperty().bind(task.valueProperty());
If you want to use a new thread to call a method, which alters the scene graph, the best chance you have is to use Platform.runLater() in it.
//code inside Thread
...
// code to run on the JavaFX Application thread
Platform.runLater(new Runnable() {
#Override
public void run() {
handleButton1();
}
});
...
You should get a NullPointerException when you run this program.
The problem is, the member of MainApp_Gui1
Controller_Gui1 cGui;
never gets a value.
Remove line "Controller_Gui1 cGui;" from this code:
public Scene getScene(Stage primaryStage) {
// Hudai hudai = new Hudai(primaryStage);
// return hudai.getScene();
Controller_Gui1 cGui;
cGui = FactoryClass.createGUI();
return cGui.getScene();
}

OutOfMemoryError while using Universal Image Loader in gridview

I have around 53 images to show in gridview from drwable. But i was getting oom while doing that. So i started using universal image loader to cache these images on to disc and pull it from there..! But i am still getting oom.
Here is my configuration
imageLoader =ImageLoader.getInstance();
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"icons");
else
cacheDir=mContext.getCacheDir();
if(!cacheDir.exists())
cacheDir.mkdirs();
config= new ImageLoaderConfiguration.Builder(mContext)
.memoryCache(new WeakMemoryCache())
.denyCacheImageMultipleSizesInMemory()
.threadPoolSize(2)
.offOutOfMemoryHandling()
.discCache(new UnlimitedDiscCache(cacheDir))
.enableLogging()
.build();
imageLoader.init(config);
options = new DisplayImageOptions.Builder()
.cacheOnDisc()
.bitmapConfig(Bitmap.Config.RGB_565)
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.build();
and this is my getview() of BaseAdapter
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView==null)
{
ViewHolder holder=new ViewHolder();
inflator = mContext.getLayoutInflater();
convertView = inflator.inflate(R.layout.imagelayout, null);
holder.imageView=(ImageView)convertView.findViewById(R.id.imgDet);
convertView.setTag(holder);
}
ViewHolder hold=(ViewHolder)convertView.getTag();
try
{
imageLoader.displayImage("drawable://" +mThumbIds[position], hold.imageView, options,new ImageLoadingListener() {
#Override
public void onLoadingStarted(String arg0, View arg1) {
// TODO Auto-generated method stub
}
#Override
public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
// TODO Auto-generated method stub
}
#Override
public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
// TODO Auto-generated method stub
}
#Override
public void onLoadingCancelled(String arg0, View arg1) {
// TODO Auto-generated method stub
}
});
}catch(OutOfMemoryError oom)
{
oom.printStackTrace();
}
catch(Exception ex)
{
ex.printStackTrace();
}
return convertView;
}
please help me with this.
Always Consider the native way to load drawables first.
ImageView.setImageResource(...) instead of using of ImageLoader.

OSGI expose An "ClassNotFoundException: org.w3c.dom.***" Error when release

I only wrote the following codes in Activator.start() function
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
Node node = new Node() {
#Override
public Object setUserData(String arg0, Object arg1, UserDataHandler arg2) {
// TODO Auto-generated method stub
return null;
}
#Override
public void setTextContent(String arg0) throws DOMException {
// TODO Auto-generated method stub
}
#Override
public void setPrefix(String arg0) throws DOMException {
// TODO Auto-generated method stub
}
#Override
public void setNodeValue(String arg0) throws DOMException {
// TODO Auto-generated method stub
}
#Override
public Node replaceChild(Node arg0, Node arg1) throws DOMException {
// TODO Auto-generated method stub
return null;
}
#Override
public Node removeChild(Node arg0) throws DOMException {
// TODO Auto-generated method stub
return null;
}
#Override
public void normalize() {
// TODO Auto-generated method stub
System.out.println("normalize 方法调用");
}
#Override
public String lookupPrefix(String arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public String lookupNamespaceURI(String arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public boolean isSupported(String arg0, String arg1) {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean isSameNode(Node arg0) {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean isEqualNode(Node arg0) {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean isDefaultNamespace(String arg0) {
// TODO Auto-generated method stub
return false;
}
#Override
public Node insertBefore(Node arg0, Node arg1) throws DOMException {
// TODO Auto-generated method stub
return null;
}
#Override
public boolean hasChildNodes() {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean hasAttributes() {
// TODO Auto-generated method stub
return false;
}
#Override
public Object getUserData(String arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public String getTextContent() throws DOMException {
// TODO Auto-generated method stub
return null;
}
#Override
public Node getPreviousSibling() {
// TODO Auto-generated method stub
return null;
}
#Override
public String getPrefix() {
// TODO Auto-generated method stub
return null;
}
#Override
public Node getParentNode() {
// TODO Auto-generated method stub
return null;
}
#Override
public Document getOwnerDocument() {
// TODO Auto-generated method stub
return null;
}
#Override
public String getNodeValue() throws DOMException {
// TODO Auto-generated method stub
return null;
}
#Override
public short getNodeType() {
// TODO Auto-generated method stub
return 0;
}
#Override
public String getNodeName() {
// TODO Auto-generated method stub
return null;
}
#Override
public Node getNextSibling() {
// TODO Auto-generated method stub
return null;
}
#Override
public String getNamespaceURI() {
// TODO Auto-generated method stub
return null;
}
#Override
public String getLocalName() {
// TODO Auto-generated method stub
return null;
}
#Override
public Node getLastChild() {
// TODO Auto-generated method stub
return null;
}
#Override
public Node getFirstChild() {
// TODO Auto-generated method stub
return null;
}
#Override
public Object getFeature(String arg0, String arg1) {
// TODO Auto-generated method stub
return null;
}
#Override
public NodeList getChildNodes() {
// TODO Auto-generated method stub
return null;
}
#Override
public String getBaseURI() {
// TODO Auto-generated method stub
return null;
}
#Override
public NamedNodeMap getAttributes() {
// TODO Auto-generated method stub
return null;
}
#Override
public short compareDocumentPosition(Node arg0) throws DOMException {
// TODO Auto-generated method stub
return 0;
}
#Override
public Node cloneNode(boolean arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public Node appendChild(Node arg0) throws DOMException {
// TODO Auto-generated method stub
return null;
}
};
node.normalize();
}
Everything goes well when run in eclipse environment, but, when release the product, ERRORS in log when runs:
Root exception:
java.lang.NoClassDefFoundError: org/w3c/dom/Node
Caused by: java.lang.ClassNotFoundException: org.w3c.dom.Node
Anyone can give some help?
OSGi gives access to system packages but only java.* packages by default, this does not include other packages like: javax.net , javax.xml , com.sun
Thus it is necessary to specify any of such packages for OSGi framework to export them through the system bundle making them accessible to other bundles that import them.
To do that you need to set a configuration property with the additional packages required by your bundles, try setting it as a system property before starting the OSGi framework such that it picks up this property when it first starts.
Assuming you are on OSGi 4.2, that property would be configured like:
org.osgi.framework.system.packages.extra=org.w3c.dom
You may want to check the Apache Felix Framework Configuration Properties for more details, though this property is part of the OSGi spec and thus should be available in other implementations as well
Please update your question to include the bundle's MANIFEST.MF
It looks like org.w3c.dom is not implicitly provided in your production. Check the Import-Package header, may be you don't have Import-Package: org.w3c.dom
If you are using Equinox, you can edit the config.ini and add "org.w3c.dom" to org.osgi.framework.system.packages key and import the same packages in your MANIFEST.MF
in my case adding
org.osgi.framework.bootdelegation=xx...xxx,org.w3c.dom
solved my problem.

"pushModalScreen called by a non-event thread" thrown on event thread

I am trying to get my Blackberry application to display a custom modal dialog, and have the opening thread wait until the user closes the dialog screen.
final Screen dialog = new FullScreen();
...// Fields are added to dialog
Application.getApplication().invokeAndWait(new Runnable()
{
public void run()
{
Application.getUiApplication().pushModalScreen(dialog);
}
});
This is throwing an Exception which says "pushModalScreen called by a non-event thread" despite the fact that I am using invokeAndWait to call pushModalScreen from the event thread.
Any ideas about what the real problem is?
Here is the code to duplicate this problem:
package com.test;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
public class Application extends UiApplication {
public static void main(String[] args)
{
new Application();
}
private Application()
{
new Thread()
{
public void run()
{
Application.this.enterEventDispatcher();
}
}.start();
final Screen dialog = new FullScreen();
final ButtonField closeButton = new ButtonField("Close Dialog");
closeButton.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
Application.getUiApplication().popScreen(dialog);
}
});
dialog.add(closeButton);
Application.getApplication().invokeAndWait(new Runnable()
{
public void run()
{
try
{
Application.getUiApplication().pushModalScreen(dialog);
}
catch (Exception e)
{
// To see the Exception in the debugger
throw new RuntimeException(e.getMessage());
}
}
});
System.exit(0);
}
}
I am using Component Package version 4.5.0.
Building on Max Gontar's observation that the Exception is not thrown when using invokeLater instead of invokeAndWait, the full solution is to implement invokeAndWait correctly out of invokeLater and Java's synchronization methods:
public static void invokeAndWait(final Application application,
final Runnable runnable)
{
final Object syncEvent = new Object();
synchronized(syncEvent)
{
application.invokeLater(new Runnable()
{
public void run()
{
runnable.run();
synchronized(syncEvent)
{
syncEvent.notify();
}
}
});
try
{
syncEvent.wait();
}
catch (InterruptedException e)
{
// This should not happen
throw new RuntimeException(e.getMessage());
}
}
}
Unfortunately, the invokeAndWait method cannot be overridden, so care must be used to call this static version instead.
Seems as though there's a bunch of code in there that's unnecessary.
public class Application extends UiApplication {
public static void main(String[] args)
{
new Application().enterEventDispatcher();
}
private Application()
{
final Screen dialog = new FullScreen();
final ButtonField closeButton = new ButtonField("Close Dialog");
closeButton.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
Application.getUiApplication().popScreen(dialog);
}
});
dialog.add(closeButton);
// this call will block the current event thread
pushModalScreen(dialog);
System.exit(0);
}
}
Use this:
UiApplication.getUiApplication().invokeAndWait(new Runnable() {
public void run() {
pushScreen(new MyScreen());
}
});

Resources