473,581 Members | 2,285 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

system.setprope rty problem

hsn
237 New Member
hello everyone.
i am trying to use the system.setprope rty to set the proxy in my computer.

Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args) {
  2.  
  3.     // TODO Auto-generated method stub
  4.  
  5.  
  6.         System.setProperty("http.proxyHost","192.222.222.2");
  7.         System.setProperty("http.proxyPort","808");
  8.         System.setProperty("http.nonProxyHosts","yahoo.com");
  9.  
  10.         detect2();
  11.  
  12.  
  13.  
  14.     }
  15.  
  16.  
  17.  
  18.     public static void detect2() {
  19.  
  20.         try {
  21.             //System.setProperty("java.net.useSystemProxies","true");
  22.  
  23.             List l = ProxySelector.getDefault().select(new URI("http://www.yahoo.com/"));
  24.  
  25.             for (Iterator iter = l.iterator(); iter.hasNext(); ) {
  26.             Proxy proxy = (Proxy) iter.next();
  27.             System.out.println("proxy type : " + proxy.type());
  28.             InetSocketAddress addr = (InetSocketAddress)
  29.             proxy.address();
  30.             if(addr == null) {
  31.  
  32.             System.out.println("No Proxy");
  33.             } else {
  34.  
  35.             System.out.println("proxy hostname : " +addr.getHostName());
  36.             System.out.println("proxy port : " +addr.getPort());
  37.  
  38.             }
  39.  
  40.             }
  41.  
  42.         } 
  43.         catch (Exception e) {
  44.             e.printStackTrace();
  45.         }
  46.  
  47.  
  48.  
  49.  
  50.  
  51.     }
  52.  
  53.     public static void detect(String location)
  54.  
  55.     {
  56.  
  57.         String proxyHost;
  58.  
  59.         int proxyPort;
  60.  
  61.         try {
  62.  
  63.             ProxyInfo info[] = ProxyService.getProxyInfo(new URL(location));
  64.  
  65.             if(info != null && info.length>0)
  66.  
  67.             {
  68.  
  69.             proxyHost = info[0].getHost();
  70.  
  71.             proxyPort = info[0].getPort();
  72.  
  73.             System.out.println("PROXY = " + proxyHost + ":" + proxyPort);
  74.  
  75.             }
  76.  
  77.         }
  78.         catch (Exception ex) {
  79.             System.err.println("could not retrieve proxy configuration, attempting direct connection." + ex);
  80.         }
  81.  
  82.     }
  83.  
  84.  
IF YOU run this code you will find that the proxy has been changed from direct to http and the host and the port will be as it is specified in the code.
after you run it the first time please comment the following line of code
Expand|Select|Wrap|Line Numbers
  1. System.setProperty("http.proxyHost","192.222.222.2");
  2. System.setProperty("http.proxyPort","808");
  3. System.setProperty("http.nonProxyHosts","yahoo.com");
  4.  
and run the program again.
you will find that the proxy returned to Direct.

i need to know how can i set save the changes i added to system.property so all the browsers will use this proxy.

kind regards
hsn
Nov 30 '08 #1
7 5910
hsn
237 New Member
if someone else knows who to set the proxy in the computer so it could be used by the browsers in a different way. please help

hsn
Nov 30 '08 #2
JosAH
11,448 Recognized Expert MVP
System properties aren't persistent; i.e. all properties are gone when the JVM has stopped. You can set your properties on the command line:
-Dkey=value associates key with value as a system property before your main() is run.

kind regards,

Jos
Nov 30 '08 #3
hsn
237 New Member
hello Jos.
i have never used the terminal to run java code. after u posted you reply, i search online and i learned it.
after compiling the java code i enter this command

java MainTest -D http.proxyHost= "yahoo.com" -D http.proxyPort= 999

is this the correct syntax??

hsn
Nov 30 '08 #4
JosAH
11,448 Recognized Expert MVP
Put those -Dkey=value parameter(s) at the start (following 'java'), otherwise they are just arguments for your main() method.

kind regards,

Jos
Nov 30 '08 #5
hsn
237 New Member
hello Jos.
i have tried your advice. i was able to use -D and the data was changed.
but then when i try to run the program again just to make sure that the data were saved, but the proxy was returned to Direct.
Nov 30 '08 #6
JosAH
11,448 Recognized Expert MVP
@hsn
Reread my reply #3: properties aren't persisten. When your program stops running all those properties are gone.

kind regards,

Jos
Nov 30 '08 #7
hsn
237 New Member
thanks Jos. at least now i know how useful are setproperties
Dec 1 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2993
by: Pat Kelley | last post by:
I am trying to feed database column data into a bean using JSTL expression language: <jsp:setProperty name="fileWrite" property="fileText" value="1"/> <c:set var="test" value="test"/> <c:forEach items="${query.rowsByIndex}" var="row"> <jsp:setProperty name="fileWrite" property="curColValue" value="${test}"/> <c:out value="${row}"/>
3
2573
by: nos | last post by:
Just curious about how I would specify the location of a system file like this one public static String getenv(String name) {} if I wanted to override it in my file C:\eclipse\workspace\newdraw\MyClass.java
1
4422
by: DelboyJay | last post by:
I have found a strange resource problem, but luckily I have also found the solution which was not obvious from the runtime exception. I really think that the compiler should pick up this problem and fix it. What do you people think? Try the following: 1. Create a new c# windows application called MyTestApp 2. Create a notifyIcon on the form...
1
2540
by: matic74 | last post by:
Salve a tutti, sto sviluppando un'applicazione web piuttosto complessa in java che utilizza il framework Bluprint della Sun. In particolare, la mia problematica &egrave; legata alla gestione degli oggetti di business nell'interfaccia con l'utilizzo, nelle jsp, dei metodi setProperty e getProperty java.
11
942
by: ptass | last post by:
Hi I've installed win2k3 sp1 on a machine where an openRead on any given file was previously working. After installation, I get a webException as follows... ..message "An exception occurred during a webclient request" .._Hresult = "-2146233079" .._COMPlusExceptionCode ="-532459699" Sorry I don't have the whole error, but this seems to...
3
12168
by: Michael BÝcker-Larsen | last post by:
Hi I'v been stuck on this problem for ages now. I have found that I'm not the only one with this problem, by looking through the different newsgroups. Hope you can help me! I know there is a lot of information, but if you need more (e.g. the code) please write michael@mblarsen.dk. The problem is this error messages (the code is build...
0
819
by: Michal | last post by:
Hi, i'm trying in C# to turn on/off task pane in powerpoint. I can check the status, but i can not set it. this is example how can i check if task pane is visible string property = "Task Pane"; object cbs = app.CommandBars; object cbp; object cbv1;
2
3758
by: james | last post by:
Hey Guys, Is there any way to attach to the onLoad property of a page, outside of the page itself? In porting an application from jsp to aspx, I added attributes like <script runat="server"> /** @attribute useBean() */ /** @attribute setProperty("*") */
0
7789
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8144
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8301
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7894
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8169
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5670
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Duprť who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3803
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1132
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.