Giter Club home page Giter Club logo

httpbuilder's People

Contributors

adamhurwitz avatar dfernandez79 avatar jageay avatar jgritman avatar kamilszymanski avatar mbabineau avatar splix avatar spoonman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

httpbuilder's Issues

Groovy 2.3 Closure Params

I'd like to see groovy's closure param definitions added. It would make working within an IDE easier.

I would start plowing away on a pull request, but this required groovy 2.3, and right now you're tied to groovy 1.8.8.

I understand wanting to stick with an older version of groovy, so that users may use newer versions if they wish, but would you want to upgrade?

Services for test dependencies

Hi Jason,

I noticed you had to comment out some tests that relied on third-party services. I actually setup an appengine project a while ago called RestMirror that.. does what it sounds like. If you POST a blob it responds with that blob. And you could update it so it responds some way to GET requests too. So that might be a good way to support "real" functional HTTP tests that don't rely on Google, Twitter, etc. If you want I can add you as an admin to the project so you can enhance it. If you're not a fan of AppEngine you could probably do the same with a free Heroku dev account.

Support HttpClient 4.3.x, Removing Deprecated HttpClient methods and classes

This request is to update httpbuilder to use the most recent HttpClient APIs. Notable changes include the removal of HttpParams as a way of configuring settings (this is now RequestConfig), removing deprecated interfaces and abstract/concrete classes (HttpClient, DefaultHttpClient, AbstractHttpClient), and making sure httpbuilder uses non-deprecated CloseableHttpClient methods.

client.ignoreSSLissues doesnt work

I have been trying to use a gradle plugin to make some REST calls which uses httpbuilder in backend, and i need to ignore all the SSL issues, but this doesnt seem to work.

No way to encode forward-slash in path

I cannot find a way to encode a forward-slash (/) into a path in HTTPBuilder (as %2F).

Example:

def http = new HTTPBuilder('https://gitlab.com/api/v3/')
http.setHeaders ['PRIVATE-TOKEN': API_TOKEN]
http.get(path: 'projects/group-name%2Fproject-name') { resp, json ->
   // ...
}

I need to have %2F encoded in order to identify the project in the GitLab API. According to their API documentation:

If using namespaced projects call make sure that the NAMESPACE/PROJECT_NAME is URL-encoded, eg. /api/v3/projects/diaspora%2Fdiaspora (where / is represented by %2F).

However, if I make this call, the underlying code in HTTPBuilder calls a constructor of java.net.URI which escapes the % causing it to be %%2F, which then returns a 404 Not Found from the server. Similarly I can't just put /, because that also returns a 404 Not Found. I must send just %2F.

I can't find a way to pass the path so that URI doesn't escape the %.

Update to groovy 2.0.* or 2.1.* for android lint compatibility

It looks like the builder currently has a dependency on a pre-2.0 build of groovy (1.8.8) which means it is using asm 3.2. This is incompatible when run with other gradle tasks such as lint while building android projects. Would it be possible to get a version that is compatible with the lint versions which are currently built with asm 4.0? This would require upping the groovy dependency to one of the 2.0.* or 2.1.* versions.

How to generate JAR?

I built the project with mvn install but can't find a target to generate the correspondent JAR. I need the JAR for a project. Thanks.

URL placeholders with slash impossible / Add support for path variables

The current documented way of using path variables is as follows:

resp = twitter.delete( path: "destroy/${postID}.json" )

But what if the postID wasn't numeric and contained a forward slash? The URL would end up being something like destroy/mypost/4711.json whereas what we expected was destroy/mypost%2F4711.json. If we try to encode the parameter manually while concatenating the string, we end up with a double-escaped slash: destroy/mypost%252F4711.json. As of now, there doesn't seem to be any way to transmit a single encoded slash in the URL.

A good solution would be introducing path variables, like in Spring MVC. That could look something like this:

    resp = twitter.delete( path: 'destroy/{postID}.json', pathVariables: [postID: 'mypost/4711'] )

This could be escaped and used exactly as the query map in URIBuilder.

Is this Project dead?

Last leading zero version.
Last commit 2 Years ago.
1 Year old PRs.
The Maintainer does not answer the Questions since a while...

@jgritman looks pretty dead to me?

better timeout handling

Make it easier to specify connection and socket timeout parameters for an HttpBuilder instance.

Parsing JSON response error

Was curious if anyone has seen this issue? I have tested this call with insomnia and it returns with 200 Ok.

def https = new RESTClient('https://d.la10.salesforceliveagent.com/chat/rest/')

def payload = [
"organizationId":"00D28000000f5N9",
"deploymentId":"572280000008R6L",
"buttonId":"573D000000000OC",
"agentId":"005B0000000F3b2",
"doFallback":true,
"sessionId":sid,
"userAgent":"Lynx/2.8.8",
"screenResolution":"2560x1440",
"visitorName":"Gerald",
"prechatDetails":prechat,
"prechatEntities":PreEnt,
"receiveQueueUpdates":true,
"isPost":true,
"language":"en-US"
]
println(payload)
def myheaders = [
'Content-Type': 'application/json',
'X-LIVEAGENT-API-VERSION':'36',
'X-LIVEAGENT-SEQUENCE':'1',
'X-LIVEAGENT-SESSION-KEY': skey,
'X-LIVEAGENT-AFFINITY': stoken
]

try {
def resp = https.post(
path:'Chasitor/ChasitorInit',
requestContentType: JSON,
headers: myheaders,
body:payload,
)

}
catch(HttpResponseException e) {
r = e.response
println("Success: $r.success")
println("Status: $r.status")
println("Reason: $r.statusLine.reasonPhrase")
//println("Content: \n${JsonOutput.prettyPrint(JsonOutput.toJson(r.data))}")
}

I always get the following
May 15, 2016 10:06:22 AM groovyx.net.http.RESTClient handleResponse
WARNING: Error parsing 'application/json' response
groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object

The current character read is 'O' with an int value of 79
Unable to determine the current character, it is not a string, number, array, or object
line number 1
index number 0
OK��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

at groovy.json.internal.JsonParserCharArray.decodeValueInternal(JsonParserCharArray.java:207)
at groovy.json.internal.JsonParserCharArray.decodeValue(JsonParserCharArray.java:158)
at groovy.json.internal.JsonParserCharArray.decodeFromChars(JsonParserCharArray.java:46)
at groovy.json.internal.JsonParserCharArray.parse(JsonParserCharArray.java:386)
at groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:125)
at groovy.json.JsonSlurper.parse(JsonSlurper.java:221)
at groovyx.net.http.ParserRegistry.parseJSON(ParserRegistry.java:280)
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:497)
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:1212)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1079)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1021)
at groovy.lang.Closure.call(Closure.java:426)
at groovy.lang.Closure.call(Closure.java:442)
at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:551)
at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:480)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:1070)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:1044)
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:506)
at groovyx.net.http.RESTClient.post(RESTClient.java:141)
at groovyx.net.http.RESTClient$post.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:125)
at REST_API_CALLS.run(REST_API_CALLS.groovy:68)
at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)
at groovy.lang.GroovyShell.run(GroovyShell.java:518)
at groovy.lang.GroovyShell.run(GroovyShell.java:507)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:652)
at groovy.ui.GroovyMain.run(GroovyMain.java:384)
at groovy.ui.GroovyMain.process(GroovyMain.java:370)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:129)
at groovy.ui.GroovyMain.main(GroovyMain.java:109)
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:497)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131)
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:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Success: true
Status: 200
Reason: OK

Use charset from request content-type for body encoding if present

When using HTTPBuilder with grails-rest-plugin on a platform with default encoding set to US-ASCII we realized that by default HTTPBuilder will use the platform's default encoding to encode request bodies if not explicitly set to a different value by calling EncoderRegistry.setCharset(...).
Especially setting the charset on the request content-type (e. g. application/json; charset=UTF-8) did not change this behaviour.

It would be very convenient and also consistent in my opinion to use the charset from the request content-type for body encoding if present.

support relative paths

A REST API endpoint often has a "baseURI" such as https://api.mailgun.net/v3. A concrete endpoint has e.g. the full URI https://api.mailgun.net/v3/abc.ch/events.

It would now be very nice if we could write:

RESTClient client = new RESTClient("https://api.mailgun.net/v3")
client.get(path: "abc.ch/events")

Unfortunately this results in a GET request to https://api.mailgun.net/abc.ch/events instead of https://api.mailgun.net/v3/abc.ch/events (the v3 is missing!).

Therefore I propose that the path of the baseURI and the provided path (from the client.get() call) are merged to create the final URI. At the moment the path of the baseURI is replaced.

I think it would be a very simple change in groovyx.net.http.URIBuilder#setPath() which I could submit myself. What do you think?

Minor cleanup of Maven dependency on Groovy

I noticed that in pom.xml there is a compile-time dependency on Groovy 1.8.8. I have been using httpbuilder via the @Grab annotation in Groovy 2.1.6, and when I print out the classpath, I notice that the GroovyClassLoader has loaded the jars for Groovy 1.8.8 and all its dependent jars, even though the root class loader has loaded Groovy 2.1.6 and its dependencies already (through the running of the script).

Would it be more appropriate to have <scope>provided</scope> in the pom.xml for the Groovy dependency, so that the older version of Groovy is left out of the classpath? This does not appear to have negative effects on the build.

In the title I said this is a minor cleanup issue because it does not appear to be breaking anything. (I thought at first that it was, because my @Grab was failing to download the asm-tree and asm-common dependencies, but it appears that was only an intermittent problem, perhaps due to a fouled up Grape cache or bad connection to Maven Central.)

RESTClient use deprecated API org.apache.http.impl.client.DefaultHttpClient

groovyx.net.http.RESTClient (inherited of groovyx.net.http.HTTPBuilder) uses deprecated API from
org.apache.httpcomponents:httpclient lib - see HTTPBuilder.createClient(HttpParams param) method. It creates DefaultHttpClient which are deprecated in latest httpclient releases.

Such API (like DefaultHttpClient and other) has a several bugs related to SSL connection like:
https://issues.apache.org/jira/browse/HTTPCLIENT-1726
JDK issue also applicable for httpclient I think:
https://bugs.openjdk.java.net/browse/JDK-8144566

I believe that issue #68 SSL/TLS authentication has the same cause.

In my testing I got exception:
Caused by: javax.net.ssl.SSLException: Received fatal alert: internal_error
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2023)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1125)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:543)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:409)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:220)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:164)
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:515)
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:434)
at groovyx.net.http.HTTPBuilder.request(HTTPBuilder.java:383)
at groovyx.net.http.HTTPBuilder$request.call(Unknown Source)

I have rewritten single HTTPBuilder.createClient(HttpParams param) method for mine anonymous RESTClient instance: use org.apache.http.impl.client.HttpClientBuilder instead of deprecated DefaultHttpClient (as proposed in httpclient docs) and it solve the problem.

Dear developers, It will be fine to update httpclient dependency inside http-builder and use actual api instead of deprecated one.

Once Concern in implementation of REST Client

I am using REST client to recieve a arrayBuffer from REST API in my frontEnd Application. But I am not getting the expected response from the RESTClient. Does REST Client parsed the data internally or not?
I am getting the expected result from the browser while hitting through the frontEnd javascript without the involvement of RESTClient.

Inconsistent naming of access methods for RegistryParser in HTTPBuilder

HTTPBuilder#setRegistryParser() method is used to update the parsers property in HTTPBuilder while HTTPBuilder#getParser() method is used to get a current value of the same property.

Such naming of accessor methods is confusing and non-standard. Suggestion is to change it and make it uniform so that it follows setX / getX convention.

Support non-default Keystore types for Client authentication.

The AuthConfig.certificate() method only supports the system default Keystore type (typically 'jks'). That method should accept an optional parameter specifying a keystore type (e.g. 'PKCS12'), falling back to Keystore.getDefaultType() if no value is provided.

ignoreSSLIssues() not providing described functionality

Using the following code:

def http = new HTTPBuilder( params.uri )

// [ NOTE ] - We would need to do some configuration to setup ssl truststore.
// ignoreSSLIssues is convenient but less secure: https://github.com/jgritman/httpbuilder/wiki/SSL
http.ignoreSSLIssues()
http.request( POST ) {
    params.headers.each { k, v ->
        headers."${ k }" = "${ v }"
    }
    uri.path = params.path
    uri.query = params.query
    send( params.contentType ? params.contentType : JSON, params.body )

    response.success = params.success
    response.failure = params.failure
}

I am still getting javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated.

Using groovy 2.3.1 and in a grails 2.3.7 environment ( java 1.7 )

I have tried both 0.7.1 and 0.7.2 of httpbuilder:
org.codehaus.groovy.modules.http-builder:http-builder:0.7.1

When checking the classLoader class path it points to the proper 0.7.1 or 0.7.2 library.

Any thoughts?

Basic Authentication does not work with POST in AsyncHttpBuilder

Here's my code:

final client = new AsyncHTTPBuilder(uri: 'http://localhost:8443', contentType: JSON).with {
    auth.basic('client-one', '0ne!Secret')
    return it
}

final future = client.post(
        path: '/dev/oauth/token',
        body: ['scope'     : 'read write',
               'grant_type': 'client_credentials',
               'client_id' : 'client-one'],
) { resp, json ->
    assert resp.statusLine.statusCode == 200
    return json
} as Future

def json = future.get(*requestTimeout)

The server just does not receive the authorization header. Am I doing something wrong or is this a problem with the builder?

HTTPBuilder.ignoreSSLIssues() is not working

No signature of method: groovyx.net.http.HTTPBuilder.ignoreSSLIssues() is applicable for argument types: () values: []
groovy.lang.MissingMethodException: No signature of method: groovyx.net.http.HTTPBuilder.ignoreSSLIssues() is applicable for argument types: () values: []

Cannot post a json like string

Im trying to post something like this

{
"flag": false,
"data": "{a:2,b:2,c:2}"
}

where the value of "data" is a string with json format but not a json object.

My problem is that when I try to request with this body, httpbuilder transforms the "data" value from string to json object and this brake the api who receives that data.

Some ideas?

Thks

please add 'application/hal+json' to ContentType.JSON

please add 'application/hal+json' to ContentType.JSON

HAL is expressed in JSON so adding hal+json to the content type should just work.

Here's the proposed change in ContentType.java
JSON("application/json","application/javascript","text/javascript", "application/hal+json"),

No way to extract response content in case of a HTTP failure ?

Hi.

I had a look at what HttpResponseDecorator contains, but I don't see how to get the response body in case of a non-200 HTTP status :

@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.2')

import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.GET

new HTTPBuilder('https://echo.getpostman.com/status/404').request(GET, 'application/json') {
    response.success = { resp, json -> println "# Success !\n$json\n" }
    response.failure = { resp ->
        def resp_props = resp.properties.collect{it}.join('\n')
        println "# failure\n$resp_props\n"
    }
}

What I see is that data is null.

This is very limitating to bubble up error messages from HTTP services.

Is there a way to extract the JSON from getpostman.com response in this example ?

Regards.

ResponseParseException - HttpBuilder - RestCLient

I see the below exception when I submit my request:
groovyx.net.http.ResponseParseException: OK
Request:
def response = new RestClient().post([ "http://endpoint/path",
contentType: ContentType.JSON,
body:
{"s":a, "b":"af"}
])
Groovy version: 2.3.10
HttpBuilder version : 0.7.1
I know that the server responds 200 :OK for this request. I tested it using Advanced Rest Client chrome app.
I referred the thread http://www.groovy-lang.org/mailing-lists.html#nabble-td333800 but not helpful. Please let me know how I can resolve this issue.

StackTrace:
groovyx.net.http.ResponseParseException: Internal Server Error
at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:495)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:1070)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:1044)
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:515)
at groovyx.net.http.RESTClient.delete(RESTClient.java:219)
at com.scrippsnetworks.trs.api.test.AbstractTrsSpecification.cleanupSpec(AbstractTrsSpecification.groovy:33)
Caused by: groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object

The current character read is 'c' with an int value of 99
Unable to determine the current character, it is not a string, number, array, or object
line number 1
index number 0
could not execute statement; SQL [n/a]; constraint [trs_custom_transcode_fk1]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement����������������������������������������������������������������������������
^
at groovy.json.internal.JsonParserCharArray.decodeValueInternal(JsonParserCharArray.java:216)
at groovy.json.internal.JsonParserCharArray.decodeValue(JsonParserCharArray.java:166)
at groovy.json.internal.JsonParserCharArray.decodeFromChars(JsonParserCharArray.java:45)
at groovy.json.internal.JsonParserCharArray.parse(JsonParserCharArray.java:409)
at groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:121)
at groovy.json.JsonSlurper.parse(JsonSlurper.java:224)
at groovyx.net.http.ParserRegistry.parseJSON(ParserRegistry.java:280)
at groovy.lang.Closure.call(Closure.java:423)
at groovy.lang.Closure.call(Closure.java:439)
at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:560)
at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:489)
... 5 more

Build failure v0.7.3-SNAPSHOT

Tests run: 80, Failures: 1, Errors: 11, Skipped: 9

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:06 min
[INFO] Finished at: 2015-05-04T02:09:51-02:00
[INFO] Final Memory: 12M/29M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test (default-test) on project http-builder: There are test fa
ilures.
[ERROR]
[ERROR] Please refer to C:\Documents and Settings\pab\My Documents\Downloads\httpbuilder-master\target\surefire-reports for the individual test r
esults.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

java.lang.NoClassDefFoundError: oauth/signpost/exception/OAuthException

I have just tried to run a fairly simple application, and was presented with the following:

java.lang.NoClassDefFoundError: oauth/signpost/exception/OAuthException

    at groovyx.net.http.AuthConfig.oauth(AuthConfig.java:180)
    at io.byteshifter.plutora.rest.PlutoraRestClient.setOauth(PlutoraRestClient.groovy:68)
    at io.byteshifter.plutora.rest.PlutoraRestClient.executeRequest(PlutoraRestClient.groovy:88)
    at io.byteshifter.plutora.rest.PlutoraRestClientIntegSpec.OAuth works properly(PlutoraRestClientIntegSpec.groovy:75)
Caused by: java.lang.ClassNotFoundException: oauth.signpost.exception.OAuthException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 4 more

I have tried adding the signpost jar as a dependency using:
compile 'oauth.signpost:oauth-signpost:1.2.1.2'
I could see it wasn't being pulled in transitively. I'm all out of options now though.

Checked out http-builder-0.7.2, mvn install. Tests fail:

After checking out http-builder-0.7.2 tag, running mvn install gives:

Results :

Failed tests:
RESTClientTest.testHead:45 assert ex.response.status == 404
| | | |
| | 400 false
| groovyx.net.http.HttpResponseDecorator@33182c98
groovyx.net.http.HttpResponseException: Bad Request

Tests in error:
AsyncHTTPBuilderTest.testPostAndDelete:108 » Execution org.codehaus.groovy.run...
HTTPBuilderTest.testPOST:157 » HttpResponse Bad Request
HttpURLClientTest.testPOST:133 » HttpResponse Bad Request
HttpURLClientTest.testParsers:183 » HttpResponse Bad Request
RESTClientTest.testQueryParameters:125 » HttpResponse Bad Request
RESTClientTest.testGet:56 » HttpResponse Bad Request
RESTClientTest.testPost:68 » HttpResponse Bad Request
RESTClientTest.testDelete:85 » IllegalState No post ID from testPost()
RESTClientTest.testDefaultHandlers:109 » HttpResponse Bad Request
GAETest.testPOST:184 » HttpResponse Bad Request

Tests run: 80, Failures: 1, Errors: 10, Skipped: 9

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE


This works though:
mvn install -DskipTests

SSL/TLS authentication

I was working with a HTTPS API (Not sure SSL/TLS) but could not get it working. The documentation here mentions how to work with SSL but that's just bypassing/accepting the insecure certificates - which is not the problem I am dealing with.

Let's say I have a private key and a certificate and the API endpoint needs these for authentication. For example look at this implementation, is this something possible with RESTClient?

Also adding the certs/key to JVM manually is not an option.

Happy to provide more details if needed.

Can't set http headers for authentication

Http-builder: 0.7.1
Language: Groovy
Framework: Spock

import groovyx.net.http.HTTPBuilder
import spock.lang.Specification

/**
 * Created by Long Nguyen on 4/11/2017.
 *
 * Chatwork api documentation: http://developer.chatwork.com/ja/index.html
 */
class ChatworkApiSpec extends Specification {
    // https://api.chatwork.com/v2/contacts
    def apiRoot = "http://api.chatwork.com/v2"
    def contactsPath = "/contacts"
    def apiToken = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx"
    def http = new HTTPBuilder(apiRoot)

    /**
     * Endpoint: /contacts
     * You can access the list of users who are in contact with you.
     */
    def "Get your contact list"() {
        when:
        def response = http.get(path: contactsPath, headers: ["X-ChatWorkToken": apiToken])
        def responseData = response.responseData
        then:
        println responseData
    }
}

It always throws below exception. I don't know what i was wrong with setting headers.
(Of course this api works for me when I use Postman)

groovyx.net.http.HttpResponseException: Bad Request

at groovyx.net.http.HTTPBuilder.defaultFailureHandler(HTTPBuilder.java:652)
at groovy.lang.Closure.call(Closure.java:414)
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:508)
at groovyx.net.http.HTTPBuilder.get(HTTPBuilder.java:292)
at groovyx.net.http.HTTPBuilder.get(HTTPBuilder.java:262)
at testcase.ChatworkApiSpec.Get your contact list(ChatworkApiSpec.groovy:24)

issue in running mvn clean install / mvn install

Hi,

I'm getting below error while running mvn install.

[INFO] No sources to compile
[INFO]
[INFO] --- gmaven-plugin:1.4:testCompile (build) @ http-builder ---
[WARNING] Error injecting: org.codehaus.gmaven.plugin.compile.TestCompileMojo
java.lang.TypeNotPresentException: Type org.codehaus.gmaven.plugin.compile.TestC
ompileMojo not present
        at org.eclipse.sisu.space.URLClassSpace.loadClass(URLClassSpace.java:115
)
        at org.eclipse.sisu.space.NamedClass.load(NamedClass.java:46)
        at org.eclipse.sisu.space.AbstractDeferredClass.get(AbstractDeferredClas
s.java:48)
        at com.google.inject.internal.ProviderInternalFactory.provision(Provider
InternalFactory.java:86)
        at com.google.inject.internal.InternalFactoryToInitializableAdapter.prov
ision(InternalFactoryToInitializableAdapter.java:54)
        at com.google.inject.internal.ProviderInternalFactory$1.call(ProviderInt
ernalFactory.java:70)
        at com.google.inject.internal.ProvisionListenerStackCallback$Provision.p
rovision(ProvisionListenerStackCallback.java:115)
        at org.eclipse.sisu.bean.BeanScheduler$Activator.onProvision(BeanSchedul
er.java:176)
        at com.google.inject.internal.ProvisionListenerStackCallback$Provision.p
rovision(ProvisionListenerStackCallback.java:126)
        at com.google.inject.internal.ProvisionListenerStackCallback.provision(P
rovisionListenerStackCallback.java:68)
        at com.google.inject.internal.ProviderInternalFactory.circularGet(Provid
erInternalFactory.java:68)
        at com.google.inject.internal.InternalFactoryToInitializableAdapter.get(
InternalFactoryToInitializableAdapter.java:46)
        at com.google.inject.internal.InjectorImpl$2$1.call(InjectorImpl.java:10
09)
        at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.ja
va:1059)
        at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1005)

        at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:3
6)
        at org.eclipse.sisu.inject.LazyBeanEntry.getValue(LazyBeanEntry.java:81)

        at org.eclipse.sisu.plexus.LazyPlexusBean.getValue(LazyPlexusBean.java:5
1)
        at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContai
ner.java:263)
        at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContai
ner.java:255)
        at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfigu
redMojo(DefaultMavenPluginManager.java:546)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(Default
BuildPluginManager.java:121)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:208)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
ct(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
ct(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThre
adedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(Lifecycl
eStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
cher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
a:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
uncher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
356)
Caused by: java.lang.NoClassDefFoundError: org/codehaus/gmaven/runtime/ClassComp
iler$Keys
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
2)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(Cl
assRealm.java:401)
        at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(
SelfFirstStrategy.java:42)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadCl
ass(ClassRealm.java:271)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm
.java:247)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm
.java:239)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
2)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(Cl
assRealm.java:401)
        at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(
SelfFirstStrategy.java:42)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadCl
ass(ClassRealm.java:271)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm
.java:247)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm
.java:239)
        at org.eclipse.sisu.space.URLClassSpace.loadClass(URLClassSpace.java:107
)
        ... 42 more
Caused by: java.lang.ClassNotFoundException: org.codehaus.gmaven.runtime.ClassCo
mpiler$Keys
        at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(
SelfFirstStrategy.java:50)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadCl
ass(ClassRealm.java:271)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm
.java:247)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm
.java:239)
        ... 71 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:02 min
[INFO] Finished at: 2016-06-20T11:00:28+05:30
[INFO] Final Memory: 19M/47M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.gmaven:gmaven-plugin:1.4:testCompile
 (build) on project http-builder: Execution build of goal org.codehaus.gmaven:gm
aven-plugin:1.4:testCompile failed: Unable to load the mojo 'testCompile' in the
 plugin 'org.codehaus.gmaven:gmaven-plugin:1.4'. A required class is missing: or
g/codehaus/gmaven/runtime/ClassCompiler$Keys
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.codehaus.gmaven:gmaven-plugin:1.4
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/514453/.m2/repository/org/codehaus/gmaven/gmave
n-plugin/1.4/gmaven-plugin-1.4.jar
[ERROR] urls[1] = file:/C:/Users/514453/.m2/repository/org/codehaus/gmaven/runti
me/gmaven-runtime-api/1.4/gmaven-runtime-api-1.4.jar
[ERROR] urls[2] = file:/C:/Users/514453/.m2/repository/org/codehaus/gmaven/featu
re/gmaven-feature-api/1.4/gmaven-feature-api-1.4.jar
[ERROR] urls[3] = file:/C:/Users/514453/.m2/repository/org/codehaus/gmaven/runti
me/gmaven-runtime-loader/1.4/gmaven-runtime-loader-1.4.jar
[ERROR] urls[4] = file:/C:/Users/514453/.m2/repository/org/codehaus/gmaven/featu
re/gmaven-feature-support/1.4/gmaven-feature-support-1.4.jar
[ERROR] urls[5] = file:/C:/Users/514453/.m2/repository/org/codehaus/gmaven/runti
me/gmaven-runtime-support/1.4/gmaven-runtime-support-1.4.jar
[ERROR] urls[6] = file:/C:/Users/514453/.m2/repository/org/sonatype/gshell/gshel
l-io/2.4/gshell-io-2.4.jar
[ERROR] urls[7] = file:/C:/Users/514453/.m2/repository/org/codehaus/plexus/plexu
s-utils/3.0/plexus-utils-3.0.jar
[ERROR] urls[8] = file:/C:/Users/514453/.m2/repository/com/thoughtworks/qdox/qdo
x/1.12/qdox-1.12.jar
[ERROR] urls[9] = file:/C:/Users/514453/.m2/repository/org/apache/maven/shared/f
ile-management/1.2.1/file-management-1.2.1.jar
[ERROR] urls[10] = file:/C:/Users/514453/.m2/repository/org/apache/maven/shared/
maven-shared-io/1.1/maven-shared-io-1.1.jar
[ERROR] urls[11] = file:/C:/Users/514453/.m2/repository/org/apache/xbean/xbean-r
eflect/3.4/xbean-reflect-3.4.jar
[ERROR] urls[12] = file:/C:/Users/514453/.m2/repository/log4j/log4j/1.2.12/log4j
-1.2.12.jar
[ERROR] urls[13] = file:/C:/Users/514453/.m2/repository/commons-logging/commons-
logging-api/1.1/commons-logging-api-1.1.jar
[ERROR] urls[14] = file:/C:/Users/514453/.m2/repository/com/google/collections/g
oogle-collections/1.0/google-collections-1.0.jar
[ERROR] urls[15] = file:/C:/Users/514453/.m2/repository/org/apache/maven/reporti
ng/maven-reporting-impl/2.0.4.1/maven-reporting-impl-2.0.4.1.jar
[ERROR] urls[16] = file:/C:/Users/514453/.m2/repository/org/codehaus/plexus/plex
us-interpolation/1.1/plexus-interpolation-1.1.jar
[ERROR] urls[17] = file:/C:/Users/514453/.m2/repository/commons-validator/common
s-validator/1.2.0/commons-validator-1.2.0.jar
[ERROR] urls[18] = file:/C:/Users/514453/.m2/repository/commons-beanutils/common
s-beanutils/1.7.0/commons-beanutils-1.7.0.jar
[ERROR] urls[19] = file:/C:/Users/514453/.m2/repository/commons-digester/commons
-digester/1.6/commons-digester-1.6.jar
[ERROR] urls[20] = file:/C:/Users/514453/.m2/repository/commons-logging/commons-
logging/1.0.4/commons-logging-1.0.4.jar
[ERROR] urls[21] = file:/C:/Users/514453/.m2/repository/oro/oro/2.0.8/oro-2.0.8.
jar
[ERROR] urls[22] = file:/C:/Users/514453/.m2/repository/xml-apis/xml-apis/1.0.b2
/xml-apis-1.0.b2.jar
[ERROR] urls[23] = file:/C:/Users/514453/.m2/repository/org/apache/maven/doxia/d
oxia-core/1.0-alpha-10/doxia-core-1.0-alpha-10.jar
[ERROR] urls[24] = file:/C:/Users/514453/.m2/repository/org/apache/maven/doxia/d
oxia-sink-api/1.0-alpha-10/doxia-sink-api-1.0-alpha-10.jar
[ERROR] urls[25] = file:/C:/Users/514453/.m2/repository/org/apache/maven/reporti
ng/maven-reporting-api/2.0.4/maven-reporting-api-2.0.4.jar
[ERROR] urls[26] = file:/C:/Users/514453/.m2/repository/org/apache/maven/doxia/d
oxia-site-renderer/1.0-alpha-10/doxia-site-renderer-1.0-alpha-10.jar
[ERROR] urls[27] = file:/C:/Users/514453/.m2/repository/org/codehaus/plexus/plex
us-i18n/1.0-beta-7/plexus-i18n-1.0-beta-7.jar
[ERROR] urls[28] = file:/C:/Users/514453/.m2/repository/org/codehaus/plexus/plex
us-velocity/1.1.7/plexus-velocity-1.1.7.jar
[ERROR] urls[29] = file:/C:/Users/514453/.m2/repository/org/apache/velocity/velo
city/1.5/velocity-1.5.jar
[ERROR] urls[30] = file:/C:/Users/514453/.m2/repository/org/apache/maven/doxia/d
oxia-decoration-model/1.0-alpha-10/doxia-decoration-model-1.0-alpha-10.jar
[ERROR] urls[31] = file:/C:/Users/514453/.m2/repository/commons-collections/comm
ons-collections/3.2/commons-collections-3.2.jar
[ERROR] urls[32] = file:/C:/Users/514453/.m2/repository/org/apache/maven/doxia/d
oxia-module-apt/1.0-alpha-10/doxia-module-apt-1.0-alpha-10.jar
[ERROR] urls[33] = file:/C:/Users/514453/.m2/repository/org/apache/maven/doxia/d
oxia-module-fml/1.0-alpha-10/doxia-module-fml-1.0-alpha-10.jar
[ERROR] urls[34] = file:/C:/Users/514453/.m2/repository/org/apache/maven/doxia/d
oxia-module-xdoc/1.0-alpha-10/doxia-module-xdoc-1.0-alpha-10.jar
[ERROR] urls[35] = file:/C:/Users/514453/.m2/repository/org/apache/maven/doxia/d
oxia-module-xhtml/1.0-alpha-10/doxia-module-xhtml-1.0-alpha-10.jar
[ERROR] urls[36] = file:/C:/Users/514453/.m2/repository/commons-lang/commons-lan
g/2.6/commons-lang-2.6.jar
[ERROR] urls[37] = file:/C:/Users/514453/.m2/repository/org/sonatype/gossip/goss
ip/1.2/gossip-1.2.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[project>org.codehaus.groovy.
modules.http-builder:http-builder:0.7.3-SNAPSHOT, parent: ClassRealm[maven.api,
parent: null]]]
[ERROR]
[ERROR] -----------------------------------------------------: org.codehaus.gmav
en.runtime.ClassCompiler$Keys
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContaine
rException

document thread safety

AFAIK there's no mention in the docs of whether instances of HTTPBuilder, RESTClient, etc. are thread-safe. A quick look at the code suggests they are not, but it should be mentioned explicitly and prominently whether an instances of these classes are suitable for concurrent access.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.