axis proxy Connection timed out: connect - java

Here is the code of the client class.
try {
//System.getProperties().put("https.proxyHost", "127.0.0.1");
//System.getProperties().put("https.proxyPort", "7575");
String endpoint = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName("AddSMSList"); // Change this to call
call.addParameter("validation", XMLType.XSD_STRING,
ParameterMode.IN); // Define Parameters
call.addParameter("XML", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
Object[] obj = new Object[] {
"POWERU-SMS",
getXML("13627621277", "testtime", "testtype", "testname",
"FAIL") }; // Assign value for the parameters
for (Object i : obj) {
System.out.println(i.toString());
}
String ret = (String) call.invoke(obj); // Call web service
System.out.println("Result : " + ret);
} catch (Exception e) {
e.printStackTrace();
}
The code itself i think is ok. The problem is the connection.
The Server is in china. And i use the code in Europe trying to reach the server.
I have to first start a vpn and after that i need to set up a jump server using putty(tunnel) When these are done i can acess the server via browser(proxy). But the java-client always gets a time out says
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.net.ConnectException: Connection timed out: connect
faultActor:
faultNode:
faultDetail:
Could someone please help me. Ive been working on it for 1 week.
Thanks in advance

I struggled with this on this and found a solution. If you're using Websphere add port 8080 to your virtual host's host aliases. The virtual host bound to the app you're trying to access. Hope this helps.

To me you seem to be experiencing a firewall issue and not a code issue, try the following from you command line. First do a telnet serverName port if this fails call your network admin and complete a traceroute with him sitting on the other side and the issue will be resolved.

Finally found the answer.
System.getProperties().put("socksProxyHost", "127.0.0.1");
System.getProperties().put("socksProxyPort", "7575");
instead of adding the https proxy i should've add the socks proxy!!!

This is a proxy server issue. It will be resolved if you provide the proxy server details in jboss standalone.xml file
-Dhttp.proxyHost=<proxy host>-Dhttp.proxyPort=<proxy port number>

Related

redis.clients.jedis.exceptions.JedisConnectionException: java.net.UnknownHostException

I'm using Jedis to connect to my Redis instance/cluster in AWS, but I kept getting this error, here's the code, I searched extensively on SO, found the closest one is: String hostname from properties file: Java
I tried both ways, neither worked for me.
So please help.
Here's my Java code:
public static void main(String[] args) {
AWSCredentials credentials = null;
try {
credentials = new ProfileCredentialsProvider("default").getCredentials();
} catch (Exception e) {
throw new AmazonClientException("Cannot load the credentials from the credential profiles file. "
+ "Please make sure that your credentials file is at the correct "
+ "location (/Users/USERNAME/.aws/credentials), and is in valid format.", e);
}
AmazonElastiCacheClient client = new AmazonElastiCacheClient(credentials);
client.setRegion(Region.getRegion(Regions.AP_NORTHEAST_2));
DescribeCacheClustersRequest dccRequest = new DescribeCacheClustersRequest();
dccRequest.setShowCacheNodeInfo(true);
DescribeCacheClustersResult clusterResult = client.describeCacheClusters(dccRequest);
List<CacheCluster> cacheClusters = clusterResult.getCacheClusters();
for (CacheCluster cacheCluster : cacheClusters) {
for (CacheNode cacheNode : cacheCluster.getCacheNodes()) {
String addr = cacheNode.getEndpoint().getAddress();
int port = cacheNode.getEndpoint().getPort();
String url = addr + ":" + port;
System.out.println("formed url is: " + url);
Jedis jedis = new Jedis(url);
System.out.println("Connection to server sucessfully");
// check whether server is running or not
System.out.println("Server is running: " + jedis.ping());
}
}
The last line in the above code keeps throwing this error, here's the stacktrace:
Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.UnknownHostException: REDISNAME.nquffl.0001.apn2.cache.amazonaws.com:6379
at redis.clients.jedis.Connection.connect(Connection.java:207)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
at redis.clients.jedis.Connection.sendCommand(Connection.java:126)
at redis.clients.jedis.Connection.sendCommand(Connection.java:121)
at redis.clients.jedis.BinaryClient.ping(BinaryClient.java:106)
at redis.clients.jedis.BinaryJedis.ping(BinaryJedis.java:195)
at sporadic.AmazonElastiCacheClientExample.main(AmazonElastiCacheClientExample.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)Caused by: java.net.UnknownHostException: REDISNAME.nquffl.0001.apn2.cache.amazonaws.com:6379
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at redis.clients.jedis.Connection.connect(Connection.java:184)
... 11 more
What am I doing wrong?
Please point out.
Your setting shoud be this way :
Jedis jedis = new Jedis("REDISNAME.nquffl.0001.apn2.cache.amazonaws.com",6379);
NOT this way :
Jedis jedis = new Jedis("REDISNAME.nquffl.0001.apn2.cache.amazonaws.com:6379");
According to AWS Documentation http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/Access.Outside.html
Amazon ElastiCache is an AWS service that provides cloud-based
in-memory key-value store. On the back end it uses either the
Memcached or Redis engine. The service is designed to be accessed
exclusively from within AWS. However, if the ElastiCache cluster is
hosted inside a VPC, you can use a Network Address Translation (NAT)
instance to provide outside access.
So you have below two options :-
Either you host your app inside the AWS and have proper security group setting to allow access to your elastic-cache cluster from your ec2-instance where your app is deployed.
If you want to run your app outside of AWS then you have to modify the Network Address Translation (NAT) to provide outside access.
IMO, its easy to deploy the code in AWS-Ec2 instance and test it if you are not very familiar with the networking and NAT.
I used to have locally memcache and redis instance where i used to connect for local developement and for other environment like qa,stg,prod used to deploy it in AWS ec2 instance.
Let me know if you any issues.
In my case the 6379 port was not accepting connections, so I changed I configured Redis with different port, and it worked.

wsdl client java

I have created web service client using NetBeans.
Some of the code:
...
mtsvmi.MGWPUBLICFUNCTIONSService service = new mtsvmi.MGWPUBLICFUNCTIONSService();
mtsvmi.MGWPUBLICFUNCTIONSPortType proxy = (service.getMGWPUBLICFUNCTIONSPort());
((BindingProvider)proxy).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "username");
((BindingProvider)proxy).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "password");
QName portQName = new QName("http://xmlns.oracle.com/orawsv/SISTEMA_MOKA/MGW_PUBLIC_FUNCTIONS", "MGW_PUBLIC_FUNCTIONSPort");
String req = "<INSERT_RECEIVES xmlns=\"https://IP:PORT/orawsv/test/SISTEMA_MOKA/MGW_PUBLIC_FUNCTIONS\"><parameters>"+pingKonteineris+"</parameters></INSERT_RECEIVES>";
try { // Call Web Service Operation
Dispatch<Source> sourceDispatch = null;
sourceDispatch = service.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD);
Source result = sourceDispatch.invoke(new StreamSource(new StringReader(req)));
// System.out.println("---Ans: "+result.toString()+"---");
} catch (Exception ex) {
System.out.println(ex);
}
...
gives me:
com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.ConnectException: Connection refused: connect
What did I do wrong? How do I fix this? What other info do you need to help me out in here?
The ConnectException you get means that your app was not able to establish a socket connection to its target. Typically this means that you've given the wrong hostname or port, or that the service on the other end isn't running.
From what you've posted it's not clear exactly what line of code threw the failure, or what address the connection attempt was made to. However I would hazard a guess that it's the line where you call sourceDispatch.invoke - and that the MGWPUBLICFUNCTIONSService class is responsible for providing the address.
I suggest that you look into the logs, error messages and/or configuration to find out what address is being used and why a connection can't be established to that address. Using telnet to try and establish connections yourself may be very helpful in preliminary investigation.
I faced this issue. and i resolved it by changing in .wsld file
<service name="CalculatorService">
<port binding="tns:CalculatorPortBinding" name="CalculatorPort">
<soap:address
location="http://localhost:6060/WebServiceProject/CalculatorPort" />
</port>
</service>
whre my port number was 8080 and changed to 6060 which i am using.
may it ll help u. try it.

JedisConnectionException: java.net.SocketTimeoutException: connect timed out

I'm using jedis for simple key-value data store... My code is as follows
private static final String HOST = "50.30.35.9";
private static final int PORT = 2863;
Jedis jedis = new Jedis(HOST, PORT);
try {
jedis.set("foo", "bar");
jedis.get("foo");
} catch (Exception e) {
System.err.println("Unable to connect to Redis");
e.printStackTrace();
}
When i test redis server with jedis client, i got the following
exception.
redis.clients.jedis.exceptions.JedisConnectionException:
java.net.SocketTimeoutException: connect timed out
at redis.clients.jedis.Connection.connect(Connection.java:124)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java: 54)
at redis.clients.jedis.Connection.sendCommand(Connection.java: 77)
at redis.clients.jedis.BinaryClient.set(BinaryClient.java:71)
at redis.clients.jedis.Client.set(Client.java:21)
at redis.clients.jedis.Jedis.set(Jedis.java:48)
Can someone please help?
The question is:
Why you are getting a SocketTimeoutException
The answer is:
Because you cannot connect to the host and port you have in your code, since you cannot telnet 50.30.35.9 2863 to it.
The follow up question is:
I am unable to reach the Redis instance hosted by Redis4you even via telnet, even though the Redis4you portal claims it is running. How do I debug the root cause of this issue?
The answer is:
Contact Redis4You, and find out. From Redis4You contact page:
=> You can contact us with questions or for support issues at following email: redis (#) e-nick . org In case of problems with status of the servers, please follow our Twitter account: redis4you. You can also post comments and questions there, but email will be easier and faster way.
Also looking at their Twitter feed on October 17th they "have upgraded the system to newly released Redis 2.4.0. You need to stop and then start your instance so the upgrade to happen for you."
if ubuntu:
sudo ufw allow 2863/tcp
or close your firewall

Java Web Service Client which access the .Net Webservice

I'm trying to access online .Net Webservice through Java Webservice client.
But unfortunately, am getting an error "Connection timed out: connect"
Below is my code:
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
public class WebServiceMain {
public static void main(String[] args) {
try {
String endpoint = "http://wsf.cdyne.com/SpellChecker/check.asmx";
Service service = new Service();
Call call = (Call)service.createCall();
call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true));
call.setProperty(Call.SOAPACTION_URI_PROPERTY, "http://ws.cdyne.com/CheckTextBodyV2");
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setPortName(new QName("http://ws.cdyne.com/", "check"));
call.setOperationName(new QName("http://ws.cdyne.com/", "CheckTextBodyV2"));
System.out.println(call.invoke(new Object[] {"helo is my name"}));
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
Connection timeout comes because of network issues.try to acess URL in browser.also try to append ?wsdl at the end of URL,you should see the wsdl.if this doesn't work troubleshoot network settings.
Connection timed out: connect
This means that your client application cannot even talk to the Web Service. This is not a programmatic issue.
Check and see whether you can access the end-point through your web browser. If not, then that service is not available. So it doesn't work.
If your browser can access it, and if you are connecting to Internet through a proxy, then you need to specify the proxy details to Java Client. To do that, you can use -Dhttp.proxyHost=10.2.240.11 and -Dhttp.proxyPort=8080 (replace with your values) system properties when you start up your client application.
Download the soapui software and get installed it.
then load the wsdl file and create the project.
Then test your web service via soap ui.
you can edit the connection timeout value of the soap ui. chane it for big vlue and test.still your getiong time out ping to the ip addres of the service

Why would a "java.net.ConnectException: Connection timed out" exception occur when URL is up?

I'm getting a ConnectException: Connection timed out with some frequency from my code. The URL I am trying to hit is up. The same code works for some users, but not others. It seems like once one user starts to get this exception they continue to get the exception.
Here is the stack trace:
java.net.ConnectException: Connection timed out
Caused by: java.net.ConnectException: Connection timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.Socket.connect(Socket.java:516)
at java.net.Socket.connect(Socket.java:466)
at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:365)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:477)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:214)
at sun.net.www.http.HttpClient.New(HttpClient.java:287)
at sun.net.www.http.HttpClient.New(HttpClient.java:299)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:796)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:748)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:673)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:840)
Here is a snippet from my code:
URLConnection urlConnection = null;
OutputStream outputStream = null;
OutputStreamWriter outputStreamWriter = null;
InputStream inputStream = null;
try {
URL url = new URL(urlBase);
urlConnection = url.openConnection();
urlConnection.setDoOutput(true);
outputStream = urlConnection.getOutputStream(); // exception occurs on this line
outputStreamWriter = new OutputStreamWriter(outputStream);
outputStreamWriter.write(urlString);
outputStreamWriter.flush();
inputStream = urlConnection.getInputStream();
String response = IOUtils.toString(inputStream);
return processResponse(urlString, urlBase, response);
} catch (IOException e) {
throw new Exception("Error querying url: " + urlString, e);
} finally {
IoUtil.close(inputStream);
IoUtil.close(outputStreamWriter);
IoUtil.close(outputStream);
}
Connection timeouts (assuming a local network and several client machines) typically result from
a) some kind of firewall on the way that simply eats the packets without telling the sender things like "No Route to host"
b) packet loss due to wrong network configuration or line overload
c) too many requests overloading the server
d) a small number of simultaneously available threads/processes on the server which leads to all of them being taken. This happens especially with requests that take a long time to run and may combine with c).
If the URL works fine in the web browser on the same machine, it might be that the Java code isn't using the HTTP proxy the browser is using for connecting to the URL.
The error message says it all: your connection timed out. This means your request did not get a response within some (default) timeframe. The reasons that no response was received is likely to be one of:
a) The IP/domain or port is incorrect
b) The IP/domain or port (i.e service) is down
c) The IP/domain is taking longer than your default timeout to respond
d) You have a firewall that is blocking requests or responses on whatever port you are using
e) You have a firewall that is blocking requests to that particular host
f) Your internet access is down
g) Your live-server is down i.e in case of "rest-API call".
Note that firewalls and port or IP blocking may be in place by your ISP
I'd recommend raising the connection timeout time before getting the output stream, like so:
urlConnection.setConnectTimeout(1000);
Where 1000 is in milliseconds (1000 milliseconds = 1 second).
try to do the Telnet to see any firewall issue
perform tracert/traceroute to find number of hops
I solved my problem with:
System.setProperty("https.proxyHost", "myProxy");
System.setProperty("https.proxyPort", "80");
or http.proxyHost...
Why would a “java.net.ConnectException: Connection timed out”
exception occur when URL is up?
Because the URLConnection (HttpURLConnection/HttpsURLConnection) is erratic. You can read about this here and here.
Our solution were two things:
a) set the ContentLength via setFixedLengthStreamingMode
b) catch any TimeoutException and retry if it failed.
This can be a IPv6 problem (the host publishes an IPv6 AAAA-Address and the users host thinks it is configured for IPv6 but it is actually not correctly connected). This can also be a network MTU problem, a firewall block, or the target host might publish different IP addresses (randomly or based on originators country) which are not all reachable. Or similliar network problems.
You cant do much besides setting a timeout and adding good error messages (especially printing out the hosts' resolved address). If you want to make it more robust add retry, parallel trying of all addresses and also look into name resolution caching (positive and negative) on the Java platform.
There is a possibility that your IP/host are blocked by the remote host, especially if it thinks you are hitting it too hard.
The reason why this happened to me was that a remote server was allowing only certain IP addressed but not its own, and I was trying to render the images from the server's URLs... so everything would simply halt, displaying the timeout error that you had...
Make sure that either the server is allowing its own IP, or that you are rendering things from some remote URL that actually exists.

Categories