I am trying to call an API using cURL.
Using the Advanced Rest Client(ARC) when I send a request using this URL:
http://localhost:8080/jcr/root/myfolder/integrationTestNode
I receive this response:
Status:
500: Internal Server Error
Loading time: 37 ms
Date: Thu, 28 Jul 2016 06:20:11 GMT
Content-Type: text/plain
Content-Length: 88
And a message
Failed to delete filejavax.jcr.PathNotFoundException: /root/myfolder/integrationTestNode
Which is exactly what I want.
But when I try the same using cURL in a shell script I am unable to see the message.
Here is the script:
url="http://localhost:8080/jcr/root/myfolder/integrationTestNode"
echo ${url}
curl -u amit:pass --verbose -I -X DELETE \
--url "${url}"
echo " ----------------------------------------------------------------------------"
And here is the response of the script:
http://localhost:8080/jcr/root/myfolder/integrationTestNode
* timeout on name lookup is not supported
* Trying ::1...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to localhost (::1) port 8080 (#0)
* Server auth using Basic with user 'amit'
> DELETE /jcr/root/myfolder/integrationTestNode HTTP/1.1
> Host: localhost:8080
> Authorization: Basic YW1pdDpwYXNz
> User-Agent: curl/7.49.1
> Accept: */*
>
< HTTP/1.1 500 Internal Server Error
< Date: Thu, 28 Jul 2016 06:25:26 GMT
< Content-Type: text/plain
< Content-Length: 88
<
* Excess found in a non pipelined read: excess = 88 url = /jcr/root/myfolder/int egrationTestNode (zero-length body)
0 88 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0HT TP/1.1 500 Internal Server Error
Date: Thu, 28 Jul 2016 06:25:26 GMT
Content-Type: text/plain
Content-Length: 88
How can I see the response message using cURL ?
I am using javax.ws.rs.core.Response.status().entity("").build() to send the message.
Related
Currently I try to create a user from curl command via Keycloak's Admin REST API. I can authenticate myself as an admin, I have a good answer, but when I want to create a user then we are getting error like: 548 {"error":"HTTP 401 Unauthorized"}
Here are my curl commands:
#!/bin/bash
echo "* Request for authorization"
RESULT=`curl --data "username=rahul&password=password&grant_type=password& client_id=admin-cli" http://localhost:8080/auth/realms/demo/protocol/openid-connect/token`
echo "\n"
echo "* Recovery of the token"
TOKEN=`echo $RESULT | sed 's/.*access_token":"//g' | sed 's/".*//g'`
echo "\n"
echo "* Display token"
echo $TOKEN
echo "\n"
echo " * user creation\n"
curl -v http://localhost:8080/auth/admin/realms/demo/users -H "Content-Type: application/json" -H "Authorization: bearer $TOKEN" --data '{"firstName":"xyz","lastName":"xyz", "email":"demo2#gmail.com", "enabled":"true"}'
Error logs:
curl -v http://localhost:8080/auth/admin/realms/demo/users -H "Content-Type: application/json" -H "Authorization: bearer $TOKEN" --data '{"firstName":"xyz","lastName":"xyz", "email":"demo2#gmail.com", "enabled":"true"}'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying ::1:8080...
* Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /auth/admin/realms/demo/users HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.70.0
> Accept: */*
> Content-Type: application/json
> Authorization: bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJuNGhwUUdSeUZDcmhCTzJZbWhwc0FOWG9ZY0Ztak9CMmF3Y0RPdTNNOHhRIn0.eyJleHAiOjE1OTEwMTE0MDEsImlhdCI6MTU5MTAxMTEwMSwianRpIjoiYWMxYTYyZTEtYzUwMi00NzQ0LTgwMDAtMGQ2MWFkMzU2YzIxIiwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo4MDgwL2F1dGgvcmVhbG1zL2RlbW8iLCJzdWIiOiJjYTc0MDk1Ni1jOTQ2LTQ2ZjktODBkZS1jOTFkZDc4MWJjMTIiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJhZG1pbi1jbGkiLCJzZXNzaW9uX3N0YXRlIjoiMDdjODFjODQtM2FlOS00NzUyLTkxMzgtMWY4Yzg2Zjg3NWMzIiwiYWNyIjoiMSIsInNjb3BlIjoiZW1haWwgcHJvZmlsZSIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwibmFtZSI6IlJhaHVsIEt1bWFyIiwicHJlZmVycmVkX3VzZXJuYW1lIjoicmFodWwiLCJnaXZlbl9uYW1lIjoiUmFodWwiLCJmYW1pbHlfbmFtZSI6Ikt1bWFyIiwiZW1haWwiOiJhYmNAYWJjLmNvbSJ9.BP1krGeTyTVPhKY8zHCmYowNwnGWl-lgMN7XKukUjRgxl6EEJwERwtbiruX0Qv6bZOAx5VMCntcWLPQgCTFzFXJSOnqf_YLKoUEUKrB3Lp8RHgAax0daPFVp2F86cAQ4x_ExADqepcujinvi1qP-wyWidEEVq6_j6aprzLl59y8cN6mWYL2yIZ2Vb6ZnjFHLOsOo-GZBsE1t31nG8rqPscKKhGVj7SLwexnPXCATmqYW1sc6LJgUUh2zcJrI-L8hgfyTyUHrgzi5gB7YE5mRi3M1vyHfmKNSvnca-UXo7O8OHzTzTmrDQcaTrk86xaSCcL4qm-7s9xHLeYGMAqwGEQ
> Content-Length: 81
>
} [81 bytes data]
* upload completely sent off: 81 out of 81 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 401 Unauthorized
< Connection: keep-alive
< X-XSS-Protection: 1; mode=block
< Strict-Transport-Security: max-age=31536000; includeSubDomains
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< 548{"error":"HTTP 401 Unauthorized"}
* Connection #0 to host localhost left intact
"HTTP 401 Unauthorized" as the error message correct implies is that the request is unauthorized. This means that the authentication details in your call are incorrect.
In your request, you send the bearer prefix as "bearer";
Content-Type: application/json
Authorization: bearer <>
Content-Length: 81
Change this to "Bearer <>" and see if it works.
Good day!
I am building a basic Spring Boot app, using the built is resource handler.
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/public/")
.setCachePeriod(60 * 60 * 24 * 365)
.resourceChain(true)
.addResolver(versionResourceResolver);
The file structure is as follows:
src
main
java
..
resources
public
js
app.js
Making a request to localhost:8080/js/app.js works as expected, returning the contents of the file with the correct MIME type.
However, making a request to the container directory also returns 200 OK and an empty response!
$ curl -v http://localhost:8080/js/
* Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET /js/ HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.49.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Mon, 28 Nov 2016 21:13:26 GMT
< X-Application-Context: application
< Last-Modified: Mon, 28 Nov 2016 21:06:28 GMT
< Cache-Control: max-age=31536000
< Accept-Ranges: bytes
< Content-Type: application/octet-stream
< Content-Length: 0
<
* Connection #0 to host localhost left intact
How can I get this to return 404 Not Found instead? It's not a huge issue, but definitely not what I'd expected.
I need to call method using ATG 11 REST API.
public String getString(String str) {
return str;
}
I created actor properties configuration like this:
$class=atg.service.actor.ActorChainService
definitionFile=/path/to/service/accountServiceActor.xml
And that my accountServiceActor.xml:
<?xml version="1.0" encoding="UTF-8"?>
<actor-template default-chain-id="cartService" xsi:noNamespaceSchemaLocation="http://www.atg.com/xsds/actorChain_1.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<actor-chain id="getString" transaction="TX_SUPPORTS">
<component id="getString" name="/path/to/service/AccountService"
method="getString" method-return-var="str">
<input name="str" value="${param.str}" />
<output id="str" name="str" value="${str}" />
</component>
</actor-chain>
</actor-template>
Also I updated AccessControlServlet.properties and ActorChainRestRegistry.properties
So my rest call is here:
curl -L -v -b customer_cookies.txt -X POST -H "Content-Type: application/json" -d '{ "str" : "value" }' http://localhost:7003/path/to/service/AccountServiceActor/getString
And i am getting this error:
* Adding handle: conn: 0x7f8eb9803000
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7f8eb9803000) send_pipe: 1, recv_pipe: 0
* About to connect() to localhost port 7003 (#0)
* Trying ::1...
* Connected to localhost (::1) port 7003 (#0)
> POST /path/to/service/AccountServiceActor/getString HTTP/1.1
> User-Agent: curl/7.30.0
> Host: localhost:7003
> Accept: */*
> Cookie: DYN_USER_CONFIRM=f0f599f9f11aa5571d7055c2b4c7c9d5; DYN_USER_ID=240004; JSESSIONID=6iUR5qvjjBHPhSNq6zMh_B6dn18lwhKFWvPbOZxTekUIhsFPqf3r!-1528908093
> Content-Type: application/json
> Content-Length: 20
>
* upload completely sent off: 20 out of 20 bytes
< HTTP/1.1 500 Internal Server Error
< Connection: close
< Date: Tue, 26 Aug 2014 11:19:21 GMT
< Content-Length: 265
< Content-Type: text/html; charset=UTF-8
< X-ATG-Version: version=QVRHUGxhdGZvcm0vMTEuMA==
* Replaced cookie JSESSIONID="fcMSCqdKrO-PvMyLalmJHSnuHBa0VEBaJscD01nZYZDOXCXs6Q3j!-1528908093" for domain localhost, path /, expire 0
< Set-Cookie: JSESSIONID=fcMSCqdKrO-PvMyLalmJHSnuHBa0VEBaJscD01nZYZDOXCXs6Q3j!-1528908093; path=/; HttpOnly
< X-Powered-By: Servlet/3.0 JSP/2.2
<
CONTAINER:atg.service.actor.ActorException: There was an error while trying to find a method.; SOURCE:java.lang.NoSuchMethodException: path.to.service.impl.AccountService.getString(null)
What i am doing wrong? Help me to make my configuration correct.
<input name="str" class-name="java.lang.String" value="${param.str}" />
Please add class-name attribute in your input parameter:Snippet:
1-Enclose http://localhost:7003/path/to/service/AccountServiceActor/getString in double qoutes,i.e
"http://localhost:7003/path/to/service/AccountServiceActor/getString".
2-Also replace '{ "str" : "value" }' with "{ "str" : "value" }"
Please make sure of the following points :
Actor property file name and Actor xml file name should be the same
i.e. in your case accountServiceActor.xml and AccountServiceActor.properties
Use the URL with /rest/model/ i.e. in your case http://localhost:7003/rest/model/path/to/service/AccountServiceActor/getString
Make sure that in the ActorChainRestRegistry.propeties the URL is correctly registered i.e. in your case registeredUrls+=/path/to/service/accountServiceActor/getString
Make sure that the method getString() exist in the component /path/to/service/AccountService :)
I'm trying to send a request, I do the following in curl:
curl -v --header "location: 60.004:8.456" --cookie "sessionToken=~session" -i -X PUT -H 'Content-Type: application/json' -d '{"data":"{"FCT":"Welcome", "Uni":"Welcome to DI"}"}' localhost:8080/tester/apps/e39/data
and for some reason it matches the class but no this method:
#PUT
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public Response createDocumentRoot(JSONObject inputJsonObj,
#Context UriInfo ui, #Context HttpHeaders hh) {
}
Edit:
The class is defined with #Path("{appId}/data")
The problem isn't the paths, as I've debugged it and seen it identifies the class right, it just throws the bad request after going inside the class without entering any method.
Here is the curl verbose:
* About to connect() to localhost port 8080 (#0)
* Trying 127.0.0.1... connected
> PUT /tester/apps/e39/data HTTP/1.1
> User-Agent: curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: localhost:8080
> Accept: */*
> Cookie: sessionToken=~session
> location: 60.004:8.456
> Content-Type: application/json
> Content-Length: 60
>
* upload completely sent off: 60out of 60 bytes
< HTTP/1.1 400 Bad Request
HTTP/1.1 400 Bad Request
< Server: Apache-Coyote/1.1
Server: Apache-Coyote/1.1
< Content-Type: text/html;charset=utf-8
Content-Type: text/html;charset=utf-8
< Content-Length: 990
Content-Length: 990
< Date: Tue, 02 Jul 2013 21:46:56 GMT
Date: Tue, 02 Jul 2013 21:46:56 GMT
< Connection: close
Connection: close
The problem was in the json syntax that was incorrect, I had
'{"data":"{"FCT":"Welcome", "Uni":"Welcome to DI"}"}'
after changing to this, it worked fine:
'{"data":
{"FCT":"Welcome",
"Uni":"Welcome to DI"}}'
I used a JSON online parser to check the json syntax, here is the link incase someone needs it:
http://json.parser.online.fr/
Below is the url using in my code
URL url = new URL("https://8.7.177.4/ns-api?object=answerrule&action=read&domain=amj.nms.mixnetworks.net&user=9001");
but iam getting exception as
java.io.FileNotFoundException: https://8.7.177.4/ns-api/?object=answerrule&action=read&domain=amj.nms.mixnetworks.net&user=9001
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at AuthenticateCurl.authenticatenewPostUrl(AuthenticateCurl.java:311)
at AuthenticateCurl.main(AuthenticateCurl.java:341)
in the exception we can find url where /?object=answerrule is getting appended before starting query string.
How can i resolve this.
When you access the url without the extra '/', the web server forwards you to the version that has the extra '/'. You can see this when attempting to curl the URL at the command line:
$ curl --insecure -v 'https://8.7.177.4/ns-api?object=answerrule&action=read&domain=amj.nms.mixnetworks.net&user=9001'
> GET /ns-api?object=answerrule&action=read&domain=amj.nms.mixnetworks.net&user=9001 HTTP/1.1
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
> Host: 8.7.177.4
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Thu, 12 Jul 2012 18:45:28 GMT
< Server: Apache/2.2.11 (Fedora)
< Location: https://8.7.177.4/ns-api/?object=answerrule&action=read&domain=amj.nms.mixnetworks.net&user=9001
< Content-Length: 392
< Connection: close
< Content-Type: text/html; charset=iso-8859-1
<
This is fine, and HttpURLConnection automatically follows the redirect to the new URL. This is normal behaviour.
Following the new URL, we get a different result:
$ curl --insecure -v 'https://8.7.177.4/ns-api/?object=answerrule&action=read&domain=amj.nms.mixnetworks.net&user=9001'
> GET /ns-api/?object=answerrule&action=read&domain=amj.nms.mixnetworks.net&user=9001 HTTP/1.1
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
> Host: 8.7.177.4
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Date: Thu, 12 Jul 2012 18:46:46 GMT
< Server: Apache/2.2.11 (Fedora)
< X-Powered-By: PHP/5.2.9
< Content-Length: 0
< Connection: close
< Content-Type: text/html; charset=UTF-8
<
...And we get a 404, which is why you get a FileNotFoundException!
If you were not expecting a redirect and you are running the server as well, maybe there is a configuration problem on the server.