Client Java for testing the API

  • nicola_86
  • nicola_86s Avatar Autor
  • Besucher
  • Besucher
4 Jahre 3 Wochen her #97396 von nicola_86
nicola_86 erstellte das Thema Client Java for testing the API
Hello!
I'm trying to develop a client in order to test the service to integrate in my system. I'd like to do that with Java. I'm trying using a standard httpclient of Apache.
I'm testing the method get_session_key insering my username and password of the server.
Here is the client: pastebin.com/6WPEMTuC
The answer is the following:
HTTP/1.1 200 OK [Date: Wed, 26 Jun 2013 06:53:16 GMT, Server: Apache/2.2.15 (CentOS), X-Powered-By: PHP/5.3.3, Set-Cookie: PHPSESSID=gvr28gs8eihjbpm7hj7fnl8i76; path=/; HttpOnly, Expires: Thu, 19 Nov 1981 08:52:00 GMT, Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, Pragma: no-cache, Content-Length: 0, Keep-Alive: timeout=15, max=100, Connection: Keep-Alive, Content-Type: text/html; charset=UTF-8]

I'm problably doing something wrong, can anyone help me?
Thanks

Bitte Anmelden um der Konversation beizutretten.

Mehr
4 Jahre 3 Wochen her #97398 von DenisChenu
DenisChenu antwortete auf das Thema: Client Java for testing the API
Not sure,

But think you have the session , then it great ?

Maybe some library to help you:
- json-rpc.org/implementations
- code.google.com/p/jsonrpc4j/

Denis

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Bitte Anmelden um der Konversation beizutretten.

  • nicola_86
  • nicola_86s Avatar Autor
  • Besucher
  • Besucher
4 Jahre 3 Wochen her #97405 von nicola_86
nicola_86 antwortete auf das Thema: Client Java for testing the API
Thanks for the answer.
Do you have any experience with that library: jsonrpc4j
I'm trying to understand how to use it. In the examples I've just found it:

JsonRpcHttpClient client = new JsonRpcHttpClient(new URL(" example.com/UserService.json "));
User user = client.invoke("createUser", new Object[] { "bob", "the builder" }, User.class);

How I can use it for getting the session key? The api says it is a string Object.

thanks

Bitte Anmelden um der Konversation beizutretten.

Mehr
4 Jahre 3 Wochen her #97407 von DenisChenu
DenisChenu antwortete auf das Thema: Client Java for testing the API
"java dev experience" === NULL :)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Bitte Anmelden um der Konversation beizutretten.

  • nicola_86
  • nicola_86s Avatar Autor
  • Besucher
  • Besucher
4 Jahre 3 Wochen her #97408 von nicola_86
nicola_86 antwortete auf das Thema: Client Java for testing the API
:( anyone else?

Bitte Anmelden um der Konversation beizutretten.

  • nicola_86
  • nicola_86s Avatar Autor
  • Besucher
  • Besucher
4 Jahre 3 Wochen her #97409 von nicola_86
nicola_86 antwortete auf das Thema: Client Java for testing the API
Do you think that PHPSESSID=gvr28gs8eihjbpm7hj7fnl8i76; is the session key?

Bitte Anmelden um der Konversation beizutretten.

Mehr
4 Jahre 3 Wochen her #97416 von DenisChenu
DenisChenu antwortete auf das Thema: Client Java for testing the API
Yes, i think :)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Bitte Anmelden um der Konversation beizutretten.

  • nicola_86
  • nicola_86s Avatar Autor
  • Besucher
  • Besucher
4 Jahre 3 Wochen her #97451 von nicola_86
nicola_86 antwortete auf das Thema: Client Java for testing the API
I've just check on the server side. On the log I've got this line:
[27/Jun/2013:11:29:25 +0200] 131.175.38.99 - 131.175.187.153 80 <url_of_the_server> 4386583 "POST /index.php/admin/remotecontrol/get_session_key HTTP/1.1" 200 - "-" "Apache-HttpClient/4.2.5 (java 1.5)" "-"

What do you think it happened?It seems to me that my post request wasn't well done.

Bitte Anmelden um der Konversation beizutretten.

Mehr
4 Jahre 3 Wochen her #97452 von mdekker
mdekker antwortete auf das Thema: Client Java for testing the API
The request needs to be a post, with content-type application/json otherwise there will be no response.

---
Menno Dekker

Bitte Anmelden um der Konversation beizutretten.

  • nicola_86
  • nicola_86s Avatar Autor
  • Besucher
  • Besucher
4 Jahre 3 Wochen her #97453 von nicola_86
nicola_86 antwortete auf das Thema: Client Java for testing the API
As you can see its a POST and the content type is application/json: pastebin.com/9c7W21dN
What's wrong with that code? Any suggestion?

Bitte Anmelden um der Konversation beizutretten.

Mehr
4 Jahre 3 Wochen her #97456 von mdekker
mdekker antwortete auf das Thema: Client Java for testing the API
Try this: pastebin.com/GsmWbTgy and take it from there

(btw i am no java programmer, but this got me a json response)

---
Menno Dekker

Bitte Anmelden um der Konversation beizutretten.

Mehr
4 Jahre 3 Wochen her #97457 von mdekker
mdekker antwortete auf das Thema: Client Java for testing the API
Actually this line:
post.setEntity( new StringEntity("{\"method\": \"get_session_key\", \"params\": [\"admin\",\"password\"], \"id\": 99}"));

should be able to give you a valid response

---
Menno Dekker
Folgende Benutzer bedankten sich: nicola_86

Bitte Anmelden um der Konversation beizutretten.

  • nicola_86
  • nicola_86s Avatar Autor
  • Besucher
  • Besucher
4 Jahre 3 Wochen her #97459 von nicola_86
nicola_86 antwortete auf das Thema: Client Java for testing the API
thanks mdekker. Now I have finally a response.
{"id":99,"result":null,"error":null}

I was wondering what is "id". Anyway I use the username and password to do the login at the administration panel of limesurvey, but the result is null, what does it mean?
Thanks in advance.

Bitte Anmelden um der Konversation beizutretten.

  • nicola_86
  • nicola_86s Avatar Autor
  • Besucher
  • Besucher
4 Jahre 3 Wochen her #97466 von nicola_86
nicola_86 antwortete auf das Thema: Client Java for testing the API
sorry the error was like that: {"id":1,"result":{"status":"Invalid user name or password"},"error":null}

I've also tried with the Demo version that you have with username:admin and password:test
and the message is the same. Any suggestion?

Bitte Anmelden um der Konversation beizutretten.

  • nicola_86
  • nicola_86s Avatar Autor
  • Besucher
  • Besucher
4 Jahre 3 Wochen her - 4 Jahre 3 Wochen her #97481 von nicola_86
nicola_86 antwortete auf das Thema: Client Java for testing the API
Ok I've solved the problem.
The problem was also in the json string. The correct one is:
post.setEntity( new StringEntity("{\"method\": \"get_session_key\", \"params\": {\"admin\",\"password\"}, \"id\": 99}"));

Here a client to test the key session and a random function of the api, using gson for decoding the message(it's not very optimized, I'm still working on it, but it could be a good start for anyone else that will struggle with java like me)
pastebin.com/7jeGB6vA
Letzte Änderung: 4 Jahre 3 Wochen her von nicola_86. Begründung: the message wasn't written well..sorry

Bitte Anmelden um der Konversation beizutretten.

Haben Sie schon bei unserer Kundenumfrage mitgemacht?

Verpassen Sie nicht Ihre Chance auf tolle Preise.

Klicken sie hier um teilzunehmen:

Jetzt starten

Jetzt loslegen!

Melden Sie sich jetzt an, und erstellen Sie in wenigen Minuten Ihre erste Umfrage.

Account einrichten