I am facing an intermittent issue on tomcat while making a rest call.
Setup:
ApplicationA running on standalone tomcat on portX
ApplicationB running on another standalone tomcat on portY
both the tomcat installations are on the same machine.
Java version is JRE6
Following parameters are added to the JVM_OPTS in bash profile
-Dhttp.proxyHost=[host] -Dhttp.proxyPort=[port] -Dhttp.nonProxyHosts=localhost
Application A makes a rest call to application B using Spring RestTemplate and gets a 503 error (Service unavailable) response.
The URL being used is http://localhost:portY/ApplicationB/restapipath
I cause is that the requests to localhost are going through the proxy defined in JVM_OPTS, but as per my understanding all localhost urls should be called without using any proxy.
This issue is happening intermittently, but once it starts it continues till I restart the ApplicationA tomcat server.
Also, my understanding is that any calls made through Spring RestTemplate will honour the JAVA_OPTS proxy settings without any additional handling in the code.
Any pointers, help is appreciated.
After hours of frustration I found the solution.
The problem was that my understanding about JVM proxy parameters was incorrect.
Parameters in JVM_OPTS in bash profile -Dhttp.proxyHost=[host] -Dhttp.proxyPort=[port] are actually not used automatically when using Spring RestTemplate. These parameters have to be fetched using System.getProperty('http.proxyHost') and then explicitly set in the DefaultHttpClient
Now the issue in my code was that there was a single httpClient bean defined in the applicationContext.xml which was being used by both the rest calls. The non-proxy rest call worked fine until the with-proxy rest call updated httpClient object with the proxy details.
Solution was to user separate httpClient objects for both rest calls.
Related
I am using spring.data.elasticsearch with Elasticsearch 7.14.1 in my Spring Boot (2.5.4) application.
My application.properties is something like this
spring.elasticsearch.rest.uris=elasticsearch:9200
spring.data.elasticsearch.cluster=elasticsearch:9200
spring.data.elasticsearch.repositories.enabled=true
This works fine as long as the invocation is from localhost, no issues. However, when I try to bring up my Spring Boot container, I see a failure with NoReachableHostException
reactor.core.Exceptions$ErrorCallbackNotImplemented: org.springframework.data.elasticsearch.client.NoReachableHostException: Host 'localhost:9200' not reachable. Cluster state is offline.
blah-blah-service
Caused by: org.springframework.data.elasticsearch.client.NoReachableHostException: Host **'localhost:9200'** not reachable. Cluster state is offline.
blah-blah-service
at org.springframework.data.elasticsearch.client.reactive.SingleNodeHostProvider.lambda$lookupActiveHost$3(SingleNodeHostProvider.java:101)
Clearly, my suggestion to use "elasticsearch" host (defined network, that is tested and accessible from within and outside docker containers), hasn't gone well with Spring Data for whatever reason. I have even used
#PropertySource("classpath:mysearch.properties")
in my application to try and coax these properties into the app, but doesn't look like anything works. Is there something I am missing in my Elasticsearch configuration or otherwise?
PS: I have exercised curl http://elasticsearch:9200 from within the container and find no issues
These configurations are Spring Boot specific, Spring Data Elasticsearch does not use them. But as far as I can see, you are configuring the transport client (cluster entry, should not be used anyway) and the imperative REST client, but according to the error message you are using the reactive REST client.
According to the Spring Boot documentation you would need to set spring.data.elasticsearch.client.reactive.endpoints
In the .properties file, I used the below and solved the issue for me;
spring.elasticsearch.rest.uris=http://localhost:<port_number>
spring.data.elasticsearch.client.reactive.endpoints=localhost:<port_number>
Currently working an application that is moving from JBOSS 4 (java 6) to JBOSS 7.1 (Java 8). It had no REST WS - only SOAP and worked with Servlets.
I added my WAR containing a basic REST Service (ApplicationPath class with 1 resource class and a web.xml (empty since I'm using RESTEasy implementation which should scan my classes)) to the main EAR.
During deployment, I see no errors in my logs and it says my .war has been deployed and my web context registered.
However, whenever I call one of my resource's endpoint I get the default JBOSS response for Error 404 Not Found (the url is correct though) and when I try to call the same URL but by using PUT or POST I get the message "Http Method POST is not supported by this URL" which is typically an error from Custom Servlets.
Is it possible that another Servlet is listening to my path or taking over things? Even if outside of my web context? How could I investigate/debug this?
The problem came from the old RESTeasy Version - 3.0.7-Final that was being used, which has some known bugs with the #ApplicationPath annotation and web.xml configuration. After using the provided version of RESTeasy from the JBOSS 7 (version 3.6.1-SP2), everything worked like a charm.
I have an application that uses spring to the calling rest services. Specifically, the RestTemplate class. Right before I make the call to:
restTemplate.execute(
url,
method,
new JSONRequestCallback(headerParams),
new JSONResponseExtractor(containerType, cls));
method, I check the value url in the call. I quite literally can copy and paste the value of that url (lets call it http://myHost.net:8081) into a browser in the same network domain as my tomcat 8 (the web container I am using in eclipse), and the service response is successfully returned from the browser. However, the execute method throws an exception upon return:
org.springframework.web.client.ResourceAccessException: I/O error: myHost.net; nested exception is java.net.UnknownHostException: myHost.net
Now, the web service I am calling is on the internet while my dev environment is not. To address, we opened an appropriate port in our firewall and I can successfully access the service endpoint from a browser (as indicated above) by properly configuring the proxy settings on the browser. Similarly, from my Tomcat 8 configuration within eclipse, I have added the following launch configuration VM arguments:
-Dhttp.proxySet=true
-Dhttp.proxyHost=myHost.net
-Dhttp.proxyPort=8080
but as I have indicated above, I still get the unknown host exception.
By the way, I did see a similar issue here (Spring RestTemplate and Proxy Auth) but that required a coding solution in the spring code. I was hoping for a configuration solution as our system will not have the proxy issue in the operational environement.
I am hoping someone might have some ideas as to either what I might be doing wrong, and/or how I might be able to better diagnose my problem. Thank you!
I have created application from Jhipster's template,
I have changed almost nothing in the project and it's working fine on local machine but when I deploy it to my server (ubuntu, apache, tomcat - all are the last versions) weird things start to happen.
I have AJAX call to "/api/account" which on local machine get's in response the following json
{
"timestamp":1440703613150,
"status":401,
"error":"Unauthorized",
"message":"Access Denied",
"path":"/api/account"
}
and on the production server (you can check it here) same call get's json WITHOUT "path" field in it
{
"timestamp":1440703613150,
"status":401,
"error":"Unauthorized",
"message":"Access Denied"
}
I stuck on this for long period of time, so, please help me if you can :)
As you have an Apache front-end, have a look at your mod_http_proxy settings, ProxyPass and ProxyPassReverse.
You should also have a look at your Apache logs.
Or disable Apache and access JHipster directly, so you know if this is caused by Apache or not.
I can't see why this would be an issue.
Your setup is probably different somehow, if you want to have same setup the best is to use the executable jar embedding TOmcat rather than deploying it to a server.
Are you running in prod profile for both your local machine and production server?
I am building a cluster environment with weblogic 12c as application server and I am using weblogic as LOADBALANCER,
my problem that every time I send the request to the load balancer it sends it to a different node although it should send it to the same node !!
I am sure there is a missing property to enable affility (stickiness).
any suggestions guys !
I am assuming you are using " WebLogic Proxy Plug-In " - can you confirm this is true.
The default loadbalancing algorithm is round robin When using weblogic proxy plug-in hence the behaviour you are observing is expected.
Session Stickiness comes into play only when you have an application which is using sessions, and you have defined WLCookieName parameter to the correct cookie name value in the plug-in.
http://docs.oracle.com/cd/E21764_01/web.1111/e14395/plugin_params.htm#CIHFFGEB
Tell us what request are you sending to the loadbalancer ?
is it to a static resource (like index.htm)
or is it to an application where you are maintaining a session.
Share some bit of the plugin configuration you have done.