Can't connect to server - java

I'm using this. I changed my base URL and database name, but when I try to sign up, I get the following error.
Any ideas? And if you can help and guide me towards what the base URL for couchDB would be great.
My current URL public static final String BASE_URL ="http://10.0.2.2:5984/_utils/database.html?colourity";

That exception basically means that you're trying to speak a protocol to the server that it doesn't handle. For example, if you're trying to connect to a SOCKS4 proxy but the server is a HTML server, it will return you that response.
Basically, I'd try to debug a bit further. See via Log.d() what are you sending to the server, what is it issuing, what it might be answering, and see why the information you're sending to them is not correct.

Related

Rest Assured - Getting Operation Timed Out Error while testing using RestAssured. But The same endpoint working fine in browser

I have an endpoint to be tested using RestAssured. The same endpoint is working fine while opening it in browser/Postman. But, while trying to test the same using RestAssured,
I am getting Operation Timed Out Error.
I had to connect to proxy to make that end point working in browser. used the same proxy in the rest assured also.
Sample Code below:
given().proxy("My_Proxy_URL_HERE",8080).when().get("My_API_URL_Here").then().log().all();
I am getting the response as
"Operation Timed Out" with Status Code 503.
I need your suggestion, what could be the possible issue, how to debug etc. Any suggestion is appreciated. Thanks in advance.
There can be many reasons for this behavior:
The address is just wrong and given there is some load balancer/proxy it can be configured to wait for a certain period of time and then respond with 503 status code.
Note, 503 is not a "request timed out", but "Service Unavailable".
The request url is good, but the request lacks some headers so that the load balancer/proxy won't be able to route the request to the required server.
How to check this? there exist tools that can come handy in this situation:
Check the access logs of the load balancer/proxy and even of your server if its possible - and see the request.
If it doesn't help, try to compare requests coming from rest-assured vs regular request. You can use tools like Burp for example, there are others, or you can even roll your own.
The idea is simple:
Start the "interceptor" on some port of your local computer (say, 9999 for example)
Configure the interceptor to forward all the requests to proxy of your choice (identified by URL - My_Proxy_URL_HERE and port 8080).
Now rest-assured must call localhost:9999 and the request will be intercepted by this tool. You'll be able to inspect its contents - headers, body, http method - everything.
Do the same for browser request and compare.

Get the URLs - HTTP Connection

I know that there are a lot of questions regarding this subject, but I still don't get it.
I want to get the current URL from my browser in my program. What do I need to succeed?
The connection has to be made with HTTP Connection? A proxy server would help me more? because i have to filter those URLs. Help me please, I am so confused.
request.getRequestURL();
will get you the URL from HttpServletRequest. More documentation can be found in https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html

Java HTTP getResponseCode returns 200 for non-existent URL

I was expecting this code to return a 404, however it produces the output :
"Response code is 200"
Would it be possible to learn how to differentiate between existent and non-existent web pages . . . thanks so much,
try
{
// create the HttpURLConnection
URL url = new URL("http://www.thisurldoesnotexist");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
System.out.println("Response code is " + connection.getResponseCode());
}
EDIT: I see you've call openConnection() but not connect() - could that be the problem? I would expect getResponseCode() to actually make the request if it hasn't already, but it's worth just trying that...
That suggests you've possible got some DNS resolver which redirects to a "helper" (spam) page, or something like that.
The easiest way to see exactly what's going on here is to use Wireshark - have that up and capturing traffic (HTTP-only, to make life easier) and then run your code. You should be able to see what's going on that way.
Note that I wouldn't have expected a 404 - because that would involve being able to find a web server to talk to to start with. If you're trying to go to a host which doesn't involve, there shouldn't be an HTTP response at all. I'd expect connect() to throw an exception.
try adding a "connection.connect();" or look at the contents returned...
it could be a dns issue, ie: your dns is being sent to a parking place... for example: freedns does this.
You could:
Resolve the IP from the host of the page
Try to connect to port 80 on the resolved IP using plain sockets
This is a bit low level however and will add complexity since you will need to make a simple GET request through the socket. Then validate the response so you're sure that its actually a HTTP server running on port 80.
NMap might be able to help you here.
Ideally you should be getting this error:
java.net.UnknownHostException: www.thisurldoesnotexist
But it looks like your URL is resolved by you DNS provider.
For instance on my company's network running your code with URI "http://profile/" displays
the employee profile.
Please also check etc.home file if you are on windows to check if any settings have been changed.
Like #spgennard - I think this is most likely a DNS issue.
The URL you have chosen is owned by a DNS speculator.
The URL you have chosen is "parked" by a DNS provider.
Your ISP is messing with your DNS results to send your browser to some search page.
It is also possible that you are accessing the web via a proxy, and the proxy is doing something strange.
The way to diagnose this is to look at the other information in the HTTP responses you are getting, particularly the response body.

Java and Pubsubhubbub

I just wanted to try out the java client for pubsubhubbub from google code (https://code.google.com/p/pubsubhubbub-java/downloads/list). So I downloaded the code, signed up at SuperFeedr and tried to connect to their hub. In fact I modified the test class the is provided with the subscriber client.
sb.subscribe("http://superfeedr.com/hubbub",
"https://some.blog", hostname, null, null);
hostname is the name of the server I created by using the class Web . Server is reachable from the web.
But I all get is this exception in the GetThread class:
org.apache.http.auth.MalformedChallengeException: Authentication challenge is empty
Does anybody have a hint?
Cheers,
Andi
PS: Up to now it's quite tedious to get PuSH working, e.g. at SuperFeedr they tell you what to do (http://superfeedr.com/documentation#pubsubhubbub_implementation) but not how? I tried to implement what's necessary for push my self (HttpClient, PostMethod with parameters,etc.) but nothing works....

How to read response from Https urls?

I am using following code to retrieve response code from https based urls, but when i run a prog it just hangs cont.
code:
import java.net.;
import javax.net.ssl.;
import java.io.*;
class Https2
{
public static void main(String args[]) throws Exception
{
URL u = new URL("https://myurl");
HttpsURLConnection hc = (HttpsURLConnection)u.openConnection();
hc.setConnectTimeout(3000);
hc.setReadTimeout(5000);
System.out.println("Response Code: " + hc.getResponseCode());
hc.disconnect();
}
}
How can make successfull connection to Https urls ?
any help or ideas will be well appreciated.
Thanks
Don't know if it helps but I've never had much joy with the JDK HTTP classes and have typically wound up using the Jakarta Common HTTP Client API (http://hc.apache.org/httpclient-3.x/).
I tried the attached sample with https://mail.google.com/mail/, and it worked flawlessly on linux and Mac OS X.
The authentication of the server is required by default. You need to set the javax.net.ssl.trustStore system property as the name of a keystore containing the server's certificate.
BTW, it's a good idea to catch and print the exceptions to help diagnostics.
https://mail.google.com/mail/ works on my Windows XP box. Maybe your windows firewall settings does not contain the java.exe as exception? Or the site you want to connect to uses HTTP Basic Authentication over the HTTPS connection.
Or the site needs you to identify yourself with a certificate as suggested by others?
Edit: Try your code without the timeout parameters. HTTPS connection and handshake is usually slower than a regular HTTP call. Your connection might time out due this before it can read the requested data.
I thing hc.setConnectionTimeout() might not even work because when you get to that point you already have a working connection according to the javadoc.

Categories

Resources