How to set proxy for JavaFX WebView URL? - java

My computer is running behind proxy. I want to access url from JavaFX WebView.
i used methods like System.setProperty() to set proxy for javafx.But it didnt work.Please help.

According to the JavaFX deployment documentation.
3.2.3 Built-In Proxy Support
Properly packaged JavaFX application have proxy settings initialized according to Java Runtime configuration settings. By default, this means proxy settings will be taken from the current browser if the application is embedded into a web page, or system proxy settings will be used. Proxy settings are initialized by default in all execution modes.
Information on how to "properly package JavaFX applications" is in the deployment documentation previously referenced.

You can use
System.setProperty("http.proxyHost","proxy.esrf.fr");
System.setProperty("http.proxyPort","3128");
As said in this answer.

The key idea is that:
"proxy settings will be taken from the current browser if the
application is embedded into a web page, or system proxy settings will
be used"
So, if you need to use custom proxy settings (strings) using:
System.setProperty(
"http.proxyHost",
MY_PROXY_HOST);
System.setProperty(
"http.proxyPort",
MY_PROXY_PORT);
in Netbeans you can disable setting proxy at application start to override it in code, by going to:
Project - Properties - Deployment - Disable proxy detection on
application startup
.

Related

How to debug a GWT application using an external server

I need help to run/debug my GWT application on an external server and not using the default jetty server.
I read several related topics to that question, e.g.
Where to write GWT -noserver option to avoid jetty?
How to set up eclipse with GWT and (regular servlet) Jetty backend
Is it possible to debug GWT client code on a REMOTE server using IntelliJ 9 Community Edition?
http://www.gwtproject.org/doc/latest/DevGuideCompilingAndDebugging.html
and the overall-conclusion is to
add parameter -noserver (either directly or using the google plugin for eclipse)
specify the URL of the desired server within the arguments-tab of the run/debug configuration
in run/debug configuration for a webApplication.
But after doing this, for me it seems that still the default jetty server is tried to be invoked by the provided launch URL:
http://127.0.0.1:8888/ApplicationName.html?gwt.codesvr=127.0.0.1:9997
Of course, the server can not be started due to the -noserver flag, but why is it tried to launch at all?
When following the GWT-guide:
Configure your server however you need to; note the URL which contains the host page for your GWT application.
.......
Add the -noserver command line argument. Change the URL at the end of the argument list to match the URL you recorded in step #1.
How do I change the URL at the end of the argument list? In my project, there is no URL at the end of the argument list which looks like:
-noserver -nosuperDevMode -remoteUI "${gwt_remote_ui_server_port}:${unique_id}" -logLevel INFO -codeServerPort 9997 -war C:...\MyWebApp\war com.mycompany.mywebapp.MyWebApp
Which flag do I use to specify the URL of the desired server, -bindAddress, -server, -startupUrl?
Is my assumption correct, that after proper configuration the provided launch URL must not contain any 127.0.0.1, but (only) the URL of the dedicated server?
Any tipps are very welcome - I'm rather confused at the moment.
Best Regards!
First: The URL that is shown after starting the devmode is just for your convenience(the jetty code server was not started).
You can check that by starting the devmode and then opening the URL to your external server, for example http://localhost:8888/your_app_path/index.html, add just add ?gwt.codesvr=127.0.0.1:9997. Usually the devmode should start now anyway.
By setting up the startup url to http://localhost:8888/your_app_path/index.html the plugin will show you the correct URL: http://localhost:8888/your_app_path/index.html?gwt.codesvr=127.0.0.1:9997
I think one of the best options is to run the GWT Development Mode (CodeServer) instead of DevMode with -noServer to debug with an external web server.
Example of Using a WTP runtime configuration with a GWT Development Mode with Codeserver
https://www.youtube.com/watch?v=LtH4KzmguL0&index=7&list=PLBbgqtDgdc_TqzA-qXrjgTFMC_6DKAQyT&ab_channel=BrandonDonnelson
Example of using a Simple external web server with GWT Development Mode (CodeServer)
https://www.youtube.com/watch?v=pOwUpBuVtWE&index=5&list=PLBbgqtDgdc_TqzA-qXrjgTFMC_6DKAQyT&ab_channel=BrandonDonnelson

How to Access Websphere Custom Properties with j2e app?

We have an application running on websphere 8.5 and we'd like to pull the value of a custom property created using the following method in websphere admin console:
Servers->Application Servers->server1->Process Definition->Java Virtual Machine->Custom Properties -> (new)
In the code, we are trying System.getProperty("property_name") to retrieve the property but to no avail as the result is coming out null. We've seen examples online but they are only pulling websphere variables.
Has anyone encountered and fixed this issue before ? We are using this code in static block (though we don't think that it'll make a difference).
Thanks,
JVM "custom properties" in the admin console are just system properties used to start the JVM, so System.getProperty should work, but you must restart the JVM for the system properties to be used.

would system properties set in one web app contradict another app in the same server?

If a server is started with a property java.awt.headless=true
and if i set a system property in a web application with the context,say "/web_app1", like
System.setProperty("java.awt.headless","false");
and from another web app with the context "/web_app2", if i call
System.getProperty("java.awt.headless");
would it be true or false..?
The answer to your question is that if web_app2 is started while the system property of the JVM is set to true it will still be true after web_app1 has executed the setProperty method.
System properties are in the scope of the process and does not leave the boundary of the JVM. They are basically just a key-value mappings of the JVM and it's environment.
This article from the IBM Knowledge Center explains it very well.
Looking at the API for System.setProperties might be helpful.

Replace Class files in the server stack

Is there a way to find out the java classes loaded in the server stack and replace the same with the latest version of the same without restarting the web or application server?
On Tomcat, there is an attribute called reloadable which support automatic reloading of changed classes/libraries. From Tomcat site:
reloadable
"Set to true if you want Catalina to monitor classes in /WEB-INF/classes/ and /WEB-INF/lib for changes, and automatically reload the web application if a change is detected. This feature is very useful during application development, but it requires significant runtime overhead and is not recommended for use on deployed production applications. That's why the default setting for this attribute is false. You can use the Manager web application, however, to trigger reloads of deployed applications on demand."
Sample usages is (Add following line in server.xml file):
<Context path="/webdev" docBase="/webdev" reloadable="true"></Context>
for more info, please refer http://tomcat.apache.org/tomcat-6.0-doc/config/context.html

Setting Runtime Property in Web Application

I am planning to use JGroups in a web application.
JGroups by default uses IPv6 for multicasting of messages. JGroups can only be configured to use IPv4 by setting a property like the following (see docs)
-Djava.net.preferIPv4Stack=true
This does not work if set in code. What are my options when running a war file in an application server for setting this property, specifically tomcat and glassfish?
It seems to me the following route might work. First, add a ServletContextListener to your web app and register it in web.xml before JGroups is loaded.
Now, inside the contextInitialized method, use System.setProperty("java.net.preferIPv4Stack", "true").
Disclaimer: not tested.
Unless you have a specific reason to put this in code, it can easily be configured for Tomcat by setting the environment variable CATALINA_OPTS (to -Djava.net.preferIPv4Stack=true). I think the proper place to do this is to create ${CATALINA_HOME}/bin/setenv.sh and place the setting in there.

Categories