Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

Java Error: java.net.UnknownHostException


#1

I am new user to Test Rail, i am trying to integrate with SOAP UI.
I have referred your site and created a package com.gurock.testrail and added the APIClient & APIException to that package in Eclipse IDE.
And a new class i have created and working and using your code as below
public static void main(String[] args) throws Exception
{
APIClient client = new APIClient(“https://viveksrinivas.testrail.net/index.php?/auth/login”);
client.setUser(“Valid_User”);
client.setPassword(“Password”);
//System.out.println(“Login Successful”);
JSONObject c = (JSONObject) client.sendGet(“get_cases/:project_id”);
System.out.println(c.get(“title”));
}

When i run this i ma getting the following error: (When we launch in browser for this URL https://viveksrinivas.testrail.net/index.php?/auth/login, it is working fine from eclipse unable to hit)
Exception in thread “main” java.net.UnknownHostException: viveksrinivas.testrail.net
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.security.ssl.SSLSocketImpl.connect(Unknown Source)
at sun.security.ssl.BaseSSLSocketImpl.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown Source)
at com.gurock.testrail.APIClient.sendRequest(APIClient.java:151)
at com.gurock.testrail.APIClient.sendGet(APIClient.java:91)
at sample.Program.main(Program.java:17)


#2

Hello,

The address you specified is wrong. You need to specify just the base address, without including index.php etc.

APIClient(“https://viveksrinivas.testrail.net/”)

Please refer to our examples here:

http://docs.gurock.com/testrail-api2/bindings-java


#3

I tried with both the URL still i am getting the same error like (java.net.UnknownHostException: viveksrinivas.testrail.net) https://viveksrinivas.testrail.net/ & https://viveksrinivas.testrail.net/index.php?/auth/login. And also i tried with HTTP / S as well.

But the same URL if we provide in browser and able to connect. From eclipse i am trying connect unable establish the connection.

Any other solution to mitigate from this issue.


#4

This looks like a DNS issue with your Java environment. Or you might have a proxy configured in your browser which results in the site access working in your browser but not from other processes on your machine. So this looks like a problem unrelated to TestRail; have you tried looking up the address for other host names from your Java code, e.g. cnn.com or similar?

Thanks.


#5

Thanks for the reply, i will check it how to solve proxy / DNS issue.

I have one more query, i have to integrate Test Rail with SOAP UI.
SOAP UI will support Groovy & Java Script and also java can be called in SOAP UI using .Jar file, and SOAP UI will not recognize .Java or .Class file, Test Rail providing json-simple-1.1.1.jar & APIClient.Java, APIException.Java, in this case if i want to integrate how to use the (APIClient.Java, APIException.Java) java files, do we need to convert into one more .Jar (APIClient.Java, APIException.Java) or simply we can use json-simple-1.1.1.jar alone.


#6

The .java files are just the source files (the Java source code). The .jar files are just compiled Java packages. The JSON library is just a library our example bindings use. Do you have a colleague who is familiar with Java who can assist?

Thanks!


#7

Thanks for the reply
I have added the Json .Jar into SOAP UI/bin/ext folder.
And i am trying with the code as mentioned in your site. but i am unable to proceed.
import java.net.;
import java.io.
;
import java.util.HashMap;
import org.json.simple.JSONObject;

public class Program {

public static void main(String[] args) throws Exception
{
	test client = new test("http://viveksrinivas.testrail.net/");
	client.setUser("viveksrinivas_rs@yahoo.com");
	client.setPassword("######");
	//System.out.println("Login Successful");
	JSONObject c = (JSONObject) client.sendGet("get_cases/:project_id");
	System.out.println(c.get("title"));
}

}

Can you please assist me like a process, how i can proceed with SOAP UI to Integrate the TestRail.


#8

Hello,

Thanks for the feedback! There are various issues with your code such as not importing the correct namespace, not using the correct class and you are also not using the correct URL (it should be HTTPS). Do you have a person on your team familiar with Java who can assist with your code? Also you don’t necessarily have to use our basic API binding. You can also just call the API directly via simple HTTP requests so you don’t need to use our example binding:

http://docs.gurock.com/testrail-api2/accessing


#9

Hi there,

I am running into the same issue. Any further investigation on this?

Pratik


#10

Hello Pratik,

Can you let me know the exact error you see? If you also see the UnknownHostException, then this is likely a configuration issue (e.g. incorrect TestRail address), or a network issue when you try to access the API.

Cheers,
Tobias