I'm behind a squid HTTP proxy requiring authentication and want to make API requests to an external server. However when I do so, I get the following error :
Caused by: java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.0 407 Proxy Authentication Required"
I've tried setting the proxy configuration by going to Control Panel > Java > Network Settings, but to no avail.
How to solve this?
You should set the proxy-settings in java.
System.getProperties().put("http.proxyHost", "someProxyURL");
System.getProperties().put("http.proxyPort", "someProxyPort");
System.getProperties().put("http.proxyUser", "someUserName");
System.getProperties().put("http.proxyPassword", "somePassword");
Copy from http://www.it.iitb.ac.in/~roshan/articles/javahttpproxy.html:
Tomcat Settings: catalina.properties
Append these properties to the catalina.properties file in Tomcat: ${CATALINA_OME}/conf/catalina.properties file:
http.proxyHost=yourProxyURL
http.proxyPort=yourProxyPort
http.proxyUser=yourUserName
http.proxyPassword=yourPassword
Tomcat Settings: catalina.bat
Add all the parameters defined above in the ${CATALINA_HOME}/bin/catalina.bat (for Windows) or ${CATALINA_HOME}/bin/catalina.bat (for *nix):
JAVA_OPTS="-Dhttp.proxyHost=yourProxyURL ..."
(Each option is seperated by spaces.)
Related
I created a soap client with wsimport and a given wsdl. I also used SoapUI to test the service. Using SoapUI I had no problem but when using my Java client I get
java.net.ConnectException: Connection timed out: connect
The default values I have in the requestContext are as follows
com.sun.xml.internal.ws.connect.timeout=100000
javax.xml.ws.service.endpoint.address=[fully qualified domain name endpoint]
com.sun.xml.internal.ws.request.timeout=100000
javax.xml.ws.soap.http.soapaction.use=null
com.sun.xml.internal.ws.client.ContentNegotiation=none
javax.xml.ws.soap.http.soapaction.uri=null
I've tried increasing the timeout but it still doesn't connect.
Has anyone else had a similar problem?
As you mentioned the problem is of proxy, it has been answered in below links.
How to use an HTTP proxy in java
Proxy settings in a java program
If you are using proxy with authentication then you have set authenticator along with the proxy. This is answered here.
Authenticated HTTP proxy with Java
EDIT:
As correctly mentioned by William Burnham, you have set to set the properties before calling them.
Morever, I recommend you to clear the property soon after getting response using System.clearProperty(key) as the property is set for complete instance of jvm till it is restarted and hence can cause problems for other outgoing connections.
The problem was I was behind a proxy. I did different tests and found that using a web browser (or SoapUI) I was able to access the resource but from the command line it wasn't working.
After much searching, it was a simple fix: either passing the property as a jvm argument or manually setting it in the code with System.setProperty("java.net.useSystemProxies", "true"). The JVM wasn't using the proxy on its own.
EDIT
As I used wsimport I have a jax-ws client. It's important that proxy settings be configured prior to instantiantion.
ANOTHER EDIT
If by chance you're having problems and you're using an application server to make the soap request through the proxy, you may have to specify java.net.useSystemProxies=true (or similar) in the server's configuration--for example catalina.properties if using tomcat.
I'm using apache jmeter for testing my java application. When I hit the GTM(global traffic manager: this routes the traffic to specific server depending on the load) url https:// on port 443 everything works fine.
When I try to hit the specific server on which the the application is deployed using the url http:// on port 8080, I get 401 unauthorized error because cookies are coming as null in the request.
How can I fix this?
It's hard to guess what is the problem when you don't provide any code/configuration.
Probably you are running into issue because of same origin policy (browser and tools are sending only cookies which belongs to the origin to which you are sending request).
I guess that you are retrieving cookies from https://someApp.com:443 and try to reuse them with http://someapp.com:8080. The problem is, that they are not same origins (port number is treated as part of origin URL).
Check out this links:
JMeter Issue with SSO and Cookies
https://bz.apache.org/bugzilla/show_bug.cgi?id=56358
You could try disabling JMeter cookies checking:
Temporarily (once only), via -J command-line argument like:
jmeter -JCookieManager.check.cookies=false -n -t test.jmx -l result.jtl
Permanent, by adding the next line to user.properties file (located in "bin" folder of your JMeter installation)
CookieManager.check.cookies=false
JMeter restart will be required to pick the property up.
References:
Configuring JMeter
Apache JMeter Properties Customization Guide
HTTP Cookie Manager documentation
Notice that you have only 1 Cookie Manager.
If there is more than one Cookie Manager in the scope of a Sampler,
there is currently no way to specify which one is to be used. Also, a
cookie stored in one cookie manager is not available to any other
manager, so use multiple Cookie Managers with care
I'm trying to connect JVisualVM, running on my local machine, to a remote machine which is running a WildFly server (version 8.1.0, to be specific.)
I didn't configure the WildFly server myself, and I don't know who did, but I do know that I can log in as an administrative user from my local machine by pointing my browser at:
https://[ip address of the remote machine]:9443/console
Note that it's https, not ordinary http, and that the port for that has been set to 9443 (I think the default is 8080 or 9990 or something... IDK, I saw a lot of port numbers online. I have been explicitly told that http was disabled for this WildFly server).
I can SSH into the remote machine. I can navigate to the bin directory for WildFly and run jboss-client.sh. I have to connect on port 9999 (I think the default is 9990 for that?)
I copied the jboss-client.jar (under bin/client) to my local machine and ran JVisualVM from the command line like this:
.\jvisualvm.exe -cp:a C:\[path to]\jboss-client.jar
It launches fine. File > Add Remote Host: Then I entered the IP. OK. I right clicked on it under Remote in the tree and picked Add JMX Connection. I entered
service:jmx:http-remoting-jmx://[ip]:9999
I checked off that I wanted to use the security credentials and entered the username and password. Checked off to save the security credentials. Left "Do not require SSL Connection" unchecked. Hit OK. It immediately spat out the message
Cannot connect to admin#service:jmx:http-remoting-jmx://[ip]:9999 using service:jmx:http-remoting-jmx://[ip]:9999
I also tried the port 9443, 9990, and 8080 instead. None of those worked. I tried https instead of http in the protocol name. That also didn't work.
What am I missing? How is it that I can access the console, and connect with jboss-client.sh, but I can't use JVisualVM? Is there some log I can use somewhere to see what's wrong? Maybe someone can point out a configuration I've missed somewhere?
Not sure if it's important or not, but my local machine is running Windows 10 with JDK8 installed. The WildFly server is using Java 6 on CentOS 6.3.
You need to add the jboss-client.jar (or jboss-cli-client.jar) to the class path for JVisualVM. The library can be found in the bin/client directory of the WildFly install.
I used the following command to add the library to the class path.
jvisualvm --cp:a ~/servers/wildfly-10.0.0.Final/bin/client/jboss-client.jar
Then I used service:jmx:remote+http://[ip]:[port] and was able to connect.
I don't know if someone else is also (still) having the same issue (Wildfly10 on a remote machine where management console is available at 9443 with HTTPS). The following worked for me.
For ssh connections:
Starting jvisualvm with jboss-client.jar
jvisualvm --cp:a #JBOSS_HOME/bin/client/jboss-client.jar
Using the following connection string:
service:jmx:remote+https://remote-server:9443
NOTE: I used here remote+https
Provide username and password
Hope this helps.
you missed run jstatd command in remote host ,
this little program is RMI server that possible connection from client to remote host though you using jmx connection it used jmxrmi protocol for that connection .
so first in remote host create file name as security.policy with this contain :
grant codebase "file:${java.home}/../lib/tools.jar" {
permission java.security.AllPermission;
};
off course you must in file section for linux put explicit path and then of creation this file put it in bin directory of jdk.home
then you should run this command on remote host
$JAVA_HOME/bin/jstatd -J-Djava.security.policy=path of /security.policy -J-Djava.rmi.server.hostname=remote ip address -J-Djava.net.preferIPv4Stack=true
then you could connect to server off course with correct settings.
Include jboss-cli-client.jar and jboss-client.jar under \lib\visualvm\platform\lib and restart jvisualvm to pickup new jars.
I working in an Java application. I am using Struts2 and Hibernate. The application was working fine in Tomcat7 , But when I deployed that On IBM"S Websphere I am getting the following error for the following URL
http://localhost:8080/MYAPPS
Error 404: There is no Action mapped for action name .
http://localhost:8080/MYAPPS/
Error 404: There is no Action mapped for namespace [/] and action name [] associated with context path
The default port is 9080. Change the port in url as others suggested.
Check the following:
Login to the console , click on servers -> serverName -> ports -> WC_defaulthost (webcontainer port )
For example if it shows as 9080
Click on Environment -> Virtual Host -> default host (or the host the application is mapped to)- > Click on Host Aliases . Make sure the port is defined, if not add the port and the restart the server.
access the application as follow.
http://localhost:9080/MYAPPS/
http://hostname:9080/MYAPPS/
If the problem persists, open the systemout.log file and look for more details.
Try this, it may help to find the port number for web host or secure web host,
Go for the following path,
/opt/IBM/WebSphere/AppServer/profiles/Dmgr01_demo/config/cells/localhostCell01/nodes/Dmgr_node,
try find this file serverindex.xml,
there you can find the "WC_adminhost" port number.
Hope this help !
thanks!.
I don't think this is the virtual host issue. You obviously have configured it right as there's no virtualhost error.
What's your WAS's version? WAS V6.1.X has the notorious reputation not to support whatever is popular. Try adding this as a customized web container property:
com.ibm.ws.webcontainer.invokefilterscompatibility
set its value to true
I want to capture data that my web application sends and receives from a CAS server via HTTPS. I tried using Fiddler2, but couldn't make it capture traffic from Java web application. It seems I need to configure it to use Fiddler2 as a proxy. How do I do it correctly?
Some additional info. I have already imported Fiddler's certificate with keytool. Running web application on Tomcat 7. Using IntelliJ Idea.
Run the JVM with these parameters:
-Dhttps.proxyHost=yourhostwithfiddler -Dhttps.proxyPort=8888
Alternately, you could set the Java default proxy through a GUI - see http://www.java.com/en/download/help/proxy_setup.xml
In addition to Piskvor answer, make sure you configure Fiddler to capture the HTTPS traffic: Tools --> Fiddler Options --> HTTPS --> Capture HTTPS CONNECTs
You can also use directly the settings screen:
"File / Settings...", then choose"IDE Settings / HTTP Proxy".
Then tick "Use proxy", "Host name": localhost, "Port number": 8888