swangkkb / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

rest-assured tries to connect to port 8080? #290

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

I'm trying to upgrade to 2.1.0 to get the namespaceContext fix (thanks for 
that!).

I have a simple test:

resp = return given().auth().digest(username, 
password).head("http://localhost:8002/...");

I get this stack trace:

org.apache.http.conn.HttpHostConnectException: Connection to 
http://localhost:8080 refused
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:190)
    at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:294)
    at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:643)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
    at org.apache.http.client.HttpClient$execute$0.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at org.apache.http.client.HttpClient$execute$0.call(Unknown Source)
    at com.jayway.restassured.internal.RequestSpecificationImpl$RestAssuredHttpBuilder.doRequest(RequestSpecificationImpl.groovy:1654)
    at com.jayway.restassured.internal.http.HTTPBuilder.doRequest(HTTPBuilder.java:481)
    at com.jayway.restassured.internal.http.HTTPBuilder.request(HTTPBuilder.java:430)
    at com.jayway.restassured.internal.http.HTTPBuilder$request$2.call(Unknown Source)
    at com.jayway.restassured.internal.RequestSpecificationImpl.sendHttpRequest(RequestSpecificationImpl.groovy:1112)
    at com.jayway.restassured.internal.RequestSpecificationImpl.this$2$sendHttpRequest(RequestSpecificationImpl.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1085)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:730)
    at com.jayway.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)
    at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45)
    at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:55)
    at com.jayway.restassured.internal.RequestSpecificationImpl.sendRequest(RequestSpecificationImpl.groovy:965)
    at com.jayway.restassured.internal.RequestSpecificationImpl.this$2$sendRequest(RequestSpecificationImpl.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1085)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:730)
    at com.jayway.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)
    at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
    at com.jayway.restassured.internal.filter.SendRequestFilter.filter(SendRequestFilter.groovy:31)
    at com.jayway.restassured.filter.Filter$filter.call(Unknown Source)
    at com.jayway.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:49)
    at com.jayway.restassured.filter.FilterContext$next.call(Unknown Source)
    at com.jayway.restassured.internal.RequestSpecificationImpl.invokeFilterChain(RequestSpecificationImpl.groovy:846)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1085)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:730)
    at com.jayway.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)
    at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45)
    at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:55)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)
    at com.jayway.restassured.internal.RequestSpecificationImpl.applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy:1312)
    at com.jayway.restassured.internal.RequestSpecificationImpl.this$2$applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1085)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:730)
    at com.jayway.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)
    at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45)
    at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:55)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)
    at com.jayway.restassured.internal.RequestSpecificationImpl.head(RequestSpecificationImpl.groovy:147)
    at PackageCreateTests.packageExists(PackageCreateTests.java:239)
    at PackageCreateTests.setup(PackageCreateTests.java:57)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:65)
Caused by: java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:382)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:241)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:228)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:431)
    at java.net.Socket.connect(Socket.java:527)
    at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:127)
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
    ... 99 more

Where did port 8080 come from?

Other requests succeed, so I'm not sure why this one goes off the rails...

Original issue reported on code.google.com by normanwalsh on 13 Dec 2013 at 10:37

GoogleCodeExporter commented 9 years ago
Looks like a bug! As a work-around try setting the port statically  
(RestAssured.port = 8002) or perhaps try to use given().port(8002) and see if 
that works.

Original comment by johan.ha...@gmail.com on 20 Dec 2013 at 8:41

GoogleCodeExporter commented 9 years ago
I cannot reproduce this. Could you please provide some more info?

Original comment by johan.ha...@gmail.com on 20 Dec 2013 at 8:51

GoogleCodeExporter commented 9 years ago
Closing because no response from user

Original comment by johan.ha...@gmail.com on 28 Dec 2013 at 3:08

GoogleCodeExporter commented 9 years ago
Sorry for the delay. I finally got the time to work through it. My mistake was 
attempting to do this:

    private static final String BASE = "http://localhost:8002/manage/v2/packages";
    ...
    req.head("{BASE}/{pkgname}", BASE, packageName);

But it's pretty clear that applyPathParmasAndEncodePath() doesn't support 
having the base URI parts in parameters that way. Ultimately 
getTargetPath(path) returns "http://localhost:8080"

Original comment by normanwalsh on 9 Jan 2014 at 9:49

GoogleCodeExporter commented 9 years ago
Thanks, I'll look into it when I get the opportunity.

Original comment by johan.ha...@gmail.com on 10 Jan 2014 at 7:12

GoogleCodeExporter commented 9 years ago
I thought about this some more and I actually don't think I ought to implement 
this because it leads to inconsistencies. Perhaps you have an API that expects 
a call to http://localhost:8080 with a path param to a URI. For example 
(JAX-RS):

@GET
@Path("/{uri}/{pkgname}");
public String x(..) {}

Now REST Assured should be able to send the following:

get("{uri}/{pkgname}", "http://localhost:8002/manage/v2/packages", 
"packageName"). ..

Which means that the URI must be URL encoded as a parameter. So your example is 
really a special case and I think you should just do like this:

req.head(BASE + "/{pkgname}", packageName);

or:

RestAssured.baseURI = BASE;
req.head("/{pkgname}", packageName);

Original comment by johan.ha...@gmail.com on 18 Jan 2014 at 5:16

GoogleCodeExporter commented 9 years ago
Sure, that's fine. I do think it's worth documenting somewhere that what I 
tried won't work. Finding it by debugging the Groovy library that does the 
substitution was a little, uh, tedious ;-)

Original comment by normanwalsh on 28 Jan 2014 at 6:18

GoogleCodeExporter commented 9 years ago
Probably a good idea :) You're very welcome to help out and submit a pull 
request.

Original comment by johan.ha...@gmail.com on 28 Jan 2014 at 7:08

GoogleCodeExporter commented 9 years ago
Touche. I'll put it on my todo list.

Original comment by normanwalsh on 28 Jan 2014 at 7:13

GoogleCodeExporter commented 9 years ago
:)

Original comment by johan.ha...@gmail.com on 28 Jan 2014 at 7:29

GoogleCodeExporter commented 9 years ago
Issue 313 has been merged into this issue.

Original comment by johan.ha...@gmail.com on 21 Feb 2014 at 10:07

GoogleCodeExporter commented 9 years ago
Issue 313 has been merged into this issue.

Original comment by johan.ha...@gmail.com on 21 Feb 2014 at 10:08

GoogleCodeExporter commented 9 years ago
Issue 313 has been merged into this issue.

Original comment by johan.ha...@gmail.com on 21 Feb 2014 at 10:08

GoogleCodeExporter commented 9 years ago
Issue 313 has been merged into this issue.

Original comment by johan.ha...@gmail.com on 21 Feb 2014 at 10:09