Getting "java.net.ConnectException: Connection refused (Connection refused)"exception | Rest Assured Forum
R
Rajan Kumar Kaushik Posted on 16/04/2023

Hi Ashish,

 

I am practicing module 12 i.e, module. I am practicing GetAllStudentTest program as explaind by you in the video of the same module.All things< I have done as explained by you,even I have satrted my StudentApp, I am not getting my checked exception but when I am exceuting the code, I getting "java.net.ConnectException: Connection refused (Connection refused)"exception.Could you please,look into this ASAP and help out to me. Thanks in advance.

 

I am attaching studentApp screenshot,my code and console output as well for your reference:-

 

 

Student App Running Or Not Checked Manually :-

 

 

My Code:-

package basics;

import static io.restassured.RestAssured.given;
import org.testng.annotations.Test;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;

public class GetAllStudentsTest {

@Test
public void getAllStudents() {

RestAssured.baseURI="https://localhost";
RestAssured.port=8080;
RestAssured.basePath="/student/list";

RequestSpecification requestspecification=given();
//Set the content type of request - json/xml
requestspecification=requestspecification.contentType(ContentType.JSON);
//Setting the headers
requestspecification=requestspecification.header("X","Y");

Response response=requestspecification.get();
response.print();
}

}

Console Output:-

 

[RemoteTestNG] detected TestNG version 7.0.0

FAILED: getAllStudents

java.net.ConnectException: Connection refused (Connection refused)

at java.net.PlainSocketImpl.socketConnect(Native Method)

at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:476)

at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:218)

at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:200)

at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:394)

at java.net.Socket.connect(Socket.java:606)

at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:542)

at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:414)

at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)

at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:326)

at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610)

at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445)

at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835)

at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)

at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)

at org.apache.http.client.HttpClient$execute$0.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)

at io.restassured.internal.RequestSpecificationImpl$RestAssuredHttpBuilder.doRequest(RequestSpecificationImpl.groovy:2128)

at io.restassured.internal.http.HTTPBuilder.doRequest(HTTPBuilder.java:494)

at io.restassured.internal.http.HTTPBuilder.request(HTTPBuilder.java:451)

at io.restassured.internal.http.HTTPBuilder$request$2.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:141)

at io.restassured.internal.RequestSpecificationImpl.sendHttpRequest(RequestSpecificationImpl.groovy:1531)

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 org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:810)

at io.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)

at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:48)

at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:58)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)

at io.restassured.internal.RequestSpecificationImpl.sendRequest(RequestSpecificationImpl.groovy:1290)

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 org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:810)

at io.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)

at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:48)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149)

at io.restassured.internal.filter.SendRequestFilter.filter(SendRequestFilter.groovy:30)

at io.restassured.filter.Filter$filter$0.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at io.restassured.filter.Filter$filter.call(Unknown Source)

at io.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:72)

at io.restassured.filter.time.TimingFilter.filter(TimingFilter.java:56)

at io.restassured.filter.Filter$filter.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:141)

at io.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:72)

at io.restassured.filter.FilterContext$next.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)

at io.restassured.internal.RequestSpecificationImpl.applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy:1731)

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 org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:810)

at io.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)

at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:48)

at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:58)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:182)

at io.restassured.internal.RequestSpecificationImpl.applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy:1737)

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 org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:810)

at io.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)

at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:48)

at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:58)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:182)

at io.restassured.internal.RequestSpecificationImpl.get(RequestSpecificationImpl.groovy:170)

at io.restassured.internal.RequestSpecificationImpl.get(RequestSpecificationImpl.groovy)

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 org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:810)

at io.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)

at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:48)

at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:58)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)

at io.restassured.internal.RequestSpecificationImpl.get(RequestSpecificationImpl.groovy:254)

at io.restassured.internal.RequestSpecificationImpl.get(RequestSpecificationImpl.groovy)

at basics.GetAllStudentsTest.getAllStudents(GetAllStudentsTest.java:25)

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 org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)

at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:584)

at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:172)

at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)

at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:804)

at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:145)

at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)

at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)

at java.util.ArrayList.forEach(ArrayList.java:1259)

at org.testng.TestRunner.privateRun(TestRunner.java:770)

at org.testng.TestRunner.run(TestRunner.java:591)

at org.testng.SuiteRunner.runTest(SuiteRunner.java:402)

at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)

at org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)

at org.testng.SuiteRunner.run(SuiteRunner.java:304)

at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)

at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)

at org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)

at org.testng.TestNG.runSuitesLocally(TestNG.java:1102)

at org.testng.TestNG.runSuites(TestNG.java:1032)

at org.testng.TestNG.run(TestNG.java:1000)

at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)

at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)

at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

 

 

===============================================

Default test

Tests run: 1, Failures: 1, Skips: 0

===============================================

 

 

===============================================

Default suite

Total tests run: 1, Passes: 0, Failures: 1, Skips: 0

===============================================

 

 


R
Rajan Kumar Kaushik Replied on 16/04/2023

I have attached attachment also for your reference.