How do I set up Glassfish to go via a proxy server? - java

I have been having issues with running a Glassfish v2.1.1 instance on my local machine from within the office, where we have a proxy server for outgoing connections. My initial workaround has been to work from home.
I am calling a SOAP service on a HTTPS server outside of the company. As Glassfish is not going via the company's proxy server, I get the following error when trying to initialise my SOAP clients:
javax.xml.ws.WebServiceException: Failed to access the WSDL at: https://www.hostname.com...
and
Caused by: java.net.UnknownHostException: www.hostname.com
I have proxy environment variables set on my command line, as well as my system proxy settings all working correctly so that I can get to the WSDL with the browser. How should I configure Glassfish?

I had a lot of trouble finding an answer to this, as the topic isn't covered in a lot of detail on the web. One link told me how to configure the HTTP proxy, but mentioned nothing about HTTPS, so it took me a while to figure it out.
Open up the admin console on your Glassfish server and go to:
Application Server -> JVM Settings -> JVM Options. Click "Add JVM Option" 4 times and enter the following 4 options
-Dhttp.proxyHost=proxyhostname
-Dhttp.proxyPort=8080
-Dhttps.proxyHost=proxyhostname
-Dhttps.proxyPort=8080
Where proxyhostname and the port number are correct for your setup. Then you need to restart the server.
Note that I couldn't find any options for setting up the proxy from a PAC file, nor for proxies which require auth. In this case, you may need to install a local auth proxy handler like Authoxy for Mac OS X, which turns your localhost into a non-auth proxy and masks the authentication request from the central auth proxy.
Also, this link was good for various proxy options to the JVM:
http://download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html

You have to explicitly set the proxy server. Several options are available depending on the Glassfish version. In general you can set the proxy by either using JVM arguments or the Glassfish Admin console. An intro for GF3 is available here (sorry for only providing a link, but I do not want to repeat all the details here).

Just to make the answer complete, if the proxy requires user name and password, set the following in Glassfish:
-Dhttp.proxyUser=someUserName
-Dhttp.proxyPassword=somePassword

The host cannot be resolved, are you sure you use a hostname resolvable by an internet DNS server or are you using something that can only be resolved from within your network or even worse, a hosts entry local to your machine?
Aside from that, the proxy server might be denying you access to some ports, but this is probably not your problem right now. If the proxy allows access to port 80, try running your Glassfish on port 80 as well if you get any connection timeout errors.

Related

Multiple spring boot instances on different ports - login/logout problem

I'm setting up a new dev environment on a windows 10 pro installation. Therefore i am exporting my spring-boot applications as .jar file and start it as windows service on different ports.
Spring boot app 1 on port 10001
Spring boot app 2 on port 10002
and so on
I already unlocked those ports in my firewall and everything seems working perfectly fine.
When I log into the application with port 10001, everything seems fine as well. However as soon as i log into another application (10002) i get automatically logged off on the 10001 application.
To sum it up, I am only able to be logged into one application at a time.
I am using a MySql8 Server installation. All applications have their own databaseschema. Additionally i am using spring security for authentication.
Because all those applications are running perfectly fine on our productive server (jelastic web hosting) it should have something to do with my dev environment instead of a code issue.
I'm happy you solved your problem. I don't think that using SSL and subdomains is the most simplistic solution to your problem though, especially if you are running automated tests in that environment, ssl might slow you down a bit.
There is a well known address you can bind your application to: 127.0.0.1. However, most people don't know, that your loop back device is actually listening to 127.0.0.1/8 in other numbers 127.0.0.1 with a netmask of 255.0.0.0 which means you can bind your services to any address in a whole class a subnet.
TLDR: try binding your application 1 to 127.0.0.2 and application 2 to 127.0.0.3. That should help with the cookies and later on, if you add monitoring ports, will make your life of managing port numbers easier.
As already mentioned in my comment above, the problem is not related to any software bug, instead its just how http is defined:
"Cookies do not provide isolation by port. If a cookie is readable by a service running on one port, the cookie is also readable by a service running on another port of the same server."
Are HTTP cookies port specific?
I solved my issue by using SSL encryption and different subdomains.

How to debug Java Server working for localhost but not public IP

Noob question but I'm not sure where to look:
I'm running a Java Web App on a remote linux machine (Jersey RESTful API is the goal). The server successfully runs and can handle requests locally to localhost:8080/foobar but I cannot make requests to the various urls from anywhere else (For example, my laptop through a browser).
This is a simple problem I've have many times but have no idea what terms to search on google or where to look for help debugging the problem, so any leads or advice would be greatly appreciated.
Further details:
Project is code added to a Maven2 generated archetype of a Jersey Service
This is most likely caused by firewalling on the server or in front of the internal network your server is running on. Talk to your network administrators about opening a hole for port 8080, or consider using a reverse proxy on port 80 (if open) to forward requests to port 8080. See http://en.wikipedia.org/wiki/Reverse_proxy if you are not familiar with the idea of a reverse proxy or load balancers.
Change the localhost entry in your "/etc/hosts" file, with the network configs, and if server is tomcat, edit the $CATALINA_HOME/conf/server.xml to add IP the relevant <Connector> element.
Make sure you have better idea handling /etc/hosts

Get server Port in web application at server start

I need to retrieve server information like Server IP and Port at server startup.
I am using Spring and hibernet in my project and Glassfish (and tomcat) is the application server.
I know that I can get the IP and Port information from request, but there is no request at server startup.
I found on net after some search that IP address can be retrieved as follows:
InetAddress.getLocalHost().getHostName();
but I did not find any method to retrive the current Port of the server. I am hoping to find API from app server which will provide this information. I am using Spring in my application and thus any indications from Spring API will also be helpful.
Well you should configure port in your web.xml as param and read it out in your code using ServletContext or you can use this poor hack
A server may be listening to multiple ports on multiple names, so you cannot be certain that the one chosen automatically is the one you really want.
Question is what you need it for.
If it is for giving URL backs in requests then use the information in requests.
If it is for logging or announcement with ZeroConf, then consider writing application server specific code asking it about its configuration.
If all else fails, explicitly pass in the information through e.g. system properties or JNDI.

407 unable to tunnel through proxy

We have one webservice which invokes third party webservice. To test this implementation we have different environments.
Local Developer Machine: When we run the application, everything works fine and our webservice is able to hit the third party URL. (Local Machine uses Windows OS)
Local Development Server: After deploying the application on development server, we are not able to access the third party URL and get Http Proxy 407 error. (We are having Linux, with IBM J9 JVM.)
To get around this problem, we tried setting -Dhttps.proxyUser XXX -Dhttps.proxyPassword XXX, but we continued to get the error. The second option we tried is using Authenticator.setDefault(new CustomImplAuthenticator()). But surprisingly, the JVM didnt invoke getPasswordAuthentication and continued to throw error.
We ran the same application again on local developer machine with authenticator.setdefault code. We could access the URL as said earlier, but this time again JVM didnt invoke getPasswordAuthentication method. After searching over net, we found that through NTLM the authentication data is resolved and hence we feel that the code is working on windows.
Can anyone let me know what settings, we should configure on application deployed in Linux box so that at least implementation assigned for Authenticator.setDefault will be invoked.
It depends on how you build up your http connection.
if you for example use the Apache HTTPClient you can set the proxy configuration into the DefaultHttpClient by invoking setProxyAuthenticationHandler.
Your implementation that does the http call needs to know about the proxy.

How do I access Glassfish V3 Administration Console Website from a remote host

I have installed Glassfish v3 on a standalone server running ubuntu-server 9.10.
I can open the Admin website if I use a browser running on the server by browsing to:
http:// localhost:4848/
I would like to access it from a remote machine by browsing to something like
http:// mydomain.com:4848/
The firewall is definitely allowing traffic through on that port (4848) and I can access the application server by browsing to:
http:// mydomain.com:8080/
How can I allow remote access to the administration website?
It is 'allowed' by default, so there may be some you may need to ask a different question...
This answer mentions the configuration of listeners for the admin console. Although it focusses on SSL, this configuration area may be the place where you can enable/disable access to the admin console from other other host.

Categories

Resources