Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JavaMail & Proxy  RSS feed

 
Brian Mulholland
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a java program that must poll an Http site, scrape certain content that will be in a known format, and then email confirmation that it did so to recipients. The program must connect to the Http server through a proxy. I am doing this by turning java.net.useSystemProxies system property to true, and then getting the proxy and creating the HttpUrlConnection via that proxy. This works.

However, later, when I go to send the email, if I set the system property, the email send times out every time just saying it cannot connect. If I comment that out, the email sends fine (but the Http part fails). I have tried clearing or setting the property to false (it was clear before my program) after the Http section, but this doesn't seem to matter. Once set, the JavaMail bit fails.

So the code for each is fine, but they seem to have this mutually exclusive relationship on this property, and resetting it with clearProperty or setProperty doesn't work. Ideas?
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian Mulholland wrote:I am doing this by turning java.net.useSystemProxies system property to true, and then getting the proxy and creating the HttpUrlConnection via that proxy.


And that seems to be the part which messes up the SMTP connection. I haven't ever had to use that system property to connect via an HTTP proxy; are you sure you need to use it?
 
Brian Mulholland
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I understand it, that property is what allows me to get the proxies already configured on the box (as opposed to creating an extra config file or hard-coding). I am using java.net.ProxySelector to get them, and it seem to require this property. I think I tried it without the property and it failed to return a proxy (even though there was one configured). I can try that again though.

There are two mysteries here to me. One is why this setting messes up JavaMail. The other is why my resetting/clearing the value does not REALLY clear the property. JavaMail clearly is being affected by the fact that the property was set even though I cleared the property.

The mail server is inside the firewall, so it doesn't want/need the proxy server, but the HTTP does need it. Worst case scenario I suspect that I can softcode the proxy and therefore never set the property. But I'd PREFER to use the proxy configured on the box.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dunno. I've only ever used the http.proxyHost and http.proxyPort system properties. I'm accessing SMTP (locally) and HTTP (through the proxy) with no problems that way.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!