OkHttp Example REST Client

OkHttp Example REST Client

http://ift.tt/2pI9ssQ

2017-03-21 11:33:14.584 [main] DEBUG c.s.e.undertow.rest.RestClient - **** Creating Users ****
2017-03-21 11:33:14.925 [main] DEBUG com.stubbornjava.common.HttpClient - --> POST http://localhost:8080/users http/1.1
2017-03-21 11:33:14.925 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Type: application/json; charset=utf-8
2017-03-21 11:33:14.925 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Length: 70
2017-03-21 11:33:14.925 [main] DEBUG com.stubbornjava.common.HttpClient - Host: localhost:8080
2017-03-21 11:33:14.925 [main] DEBUG com.stubbornjava.common.HttpClient - Connection: Keep-Alive
2017-03-21 11:33:14.925 [main] DEBUG com.stubbornjava.common.HttpClient - Accept-Encoding: gzip
2017-03-21 11:33:14.925 [main] DEBUG com.stubbornjava.common.HttpClient - User-Agent: okhttp/3.6.0
2017-03-21 11:33:14.927 [main] DEBUG com.stubbornjava.common.HttpClient -
2017-03-21 11:33:14.927 [main] DEBUG com.stubbornjava.common.HttpClient - {"email":"user1@test.com","roles":["USER"],"dateCreated":"2017-03-21"}
2017-03-21 11:33:14.927 [main] DEBUG com.stubbornjava.common.HttpClient - --> END POST (70-byte body)
2017-03-21 11:33:15.391 [main] DEBUG com.stubbornjava.common.HttpClient - <-- 201 Created http://localhost:8080/users (463ms)
2017-03-21 11:33:15.391 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Encoding: gzip
2017-03-21 11:33:15.391 [main] DEBUG com.stubbornjava.common.HttpClient - Connection: keep-alive
2017-03-21 11:33:15.391 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Type: application/json
2017-03-21 11:33:15.391 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Length: 96
2017-03-21 11:33:15.391 [main] DEBUG com.stubbornjava.common.HttpClient - Date: Tue, 21 Mar 2017 15:33:15 GMT
2017-03-21 11:33:15.391 [main] DEBUG com.stubbornjava.common.HttpClient - <-- END HTTP (encoded body omitted)
2017-03-21 11:33:15.430 [main] DEBUG c.s.e.undertow.rest.RestClient - {"email":"user1@test.com","roles":["USER"],"dateCreated":"2017-03-21"}
2017-03-21 11:33:15.435 [main] DEBUG com.stubbornjava.common.HttpClient - --> POST http://localhost:8080/users http/1.1
2017-03-21 11:33:15.435 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Type: application/json; charset=utf-8
2017-03-21 11:33:15.435 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Length: 71
2017-03-21 11:33:15.435 [main] DEBUG com.stubbornjava.common.HttpClient - Host: localhost:8080
2017-03-21 11:33:15.435 [main] DEBUG com.stubbornjava.common.HttpClient - Connection: Keep-Alive
2017-03-21 11:33:15.435 [main] DEBUG com.stubbornjava.common.HttpClient - Accept-Encoding: gzip
2017-03-21 11:33:15.435 [main] DEBUG com.stubbornjava.common.HttpClient - User-Agent: okhttp/3.6.0
2017-03-21 11:33:15.436 [main] DEBUG com.stubbornjava.common.HttpClient -
2017-03-21 11:33:15.436 [main] DEBUG com.stubbornjava.common.HttpClient - {"email":"user2@test.com","roles":["ADMIN"],"dateCreated":"2017-03-21"}
2017-03-21 11:33:15.437 [main] DEBUG com.stubbornjava.common.HttpClient - --> END POST (71-byte body)
2017-03-21 11:33:15.469 [main] DEBUG com.stubbornjava.common.HttpClient - <-- 201 Created http://localhost:8080/users (31ms)
2017-03-21 11:33:15.469 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Encoding: gzip
2017-03-21 11:33:15.469 [main] DEBUG com.stubbornjava.common.HttpClient - Connection: keep-alive
2017-03-21 11:33:15.469 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Type: application/json
2017-03-21 11:33:15.469 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Length: 97
2017-03-21 11:33:15.470 [main] DEBUG com.stubbornjava.common.HttpClient - Date: Tue, 21 Mar 2017 15:33:15 GMT
2017-03-21 11:33:15.470 [main] DEBUG com.stubbornjava.common.HttpClient - <-- END HTTP (encoded body omitted)
2017-03-21 11:33:15.471 [main] DEBUG c.s.e.undertow.rest.RestClient - {"email":"user2@test.com","roles":["ADMIN"],"dateCreated":"2017-03-21"}
2017-03-21 11:33:15.471 [main] DEBUG c.s.e.undertow.rest.RestClient -
2017-03-21 11:33:15.472 [main] DEBUG c.s.e.undertow.rest.RestClient - **** Updating User ****
2017-03-21 11:33:15.474 [main] DEBUG com.stubbornjava.common.HttpClient - --> PUT http://localhost:8080/users http/1.1
2017-03-21 11:33:15.474 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Type: application/json; charset=utf-8
2017-03-21 11:33:15.475 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Length: 78
2017-03-21 11:33:15.475 [main] DEBUG com.stubbornjava.common.HttpClient - Host: localhost:8080
2017-03-21 11:33:15.475 [main] DEBUG com.stubbornjava.common.HttpClient - Connection: Keep-Alive
2017-03-21 11:33:15.475 [main] DEBUG com.stubbornjava.common.HttpClient - Accept-Encoding: gzip
2017-03-21 11:33:15.475 [main] DEBUG com.stubbornjava.common.HttpClient - User-Agent: okhttp/3.6.0
2017-03-21 11:33:15.475 [main] DEBUG com.stubbornjava.common.HttpClient -
2017-03-21 11:33:15.475 [main] DEBUG com.stubbornjava.common.HttpClient - {"email":"user2@test.com","roles":["USER","ADMIN"],"dateCreated":"2017-03-21"}
2017-03-21 11:33:15.475 [main] DEBUG com.stubbornjava.common.HttpClient - --> END PUT (78-byte body)
2017-03-21 11:33:15.481 [main] DEBUG com.stubbornjava.common.HttpClient - <-- 200 OK http://localhost:8080/users (6ms)
2017-03-21 11:33:15.482 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Encoding: gzip
2017-03-21 11:33:15.482 [main] DEBUG com.stubbornjava.common.HttpClient - Connection: keep-alive
2017-03-21 11:33:15.482 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Type: application/json
2017-03-21 11:33:15.482 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Length: 105
2017-03-21 11:33:15.482 [main] DEBUG com.stubbornjava.common.HttpClient - Date: Tue, 21 Mar 2017 15:33:15 GMT
2017-03-21 11:33:15.482 [main] DEBUG com.stubbornjava.common.HttpClient - <-- END HTTP (encoded body omitted)
2017-03-21 11:33:15.482 [main] DEBUG c.s.e.undertow.rest.RestClient - {"email":"user2@test.com","roles":["USER","ADMIN"],"dateCreated":"2017-03-21"}
2017-03-21 11:33:15.482 [main] DEBUG c.s.e.undertow.rest.RestClient -
2017-03-21 11:33:15.483 [main] DEBUG c.s.e.undertow.rest.RestClient - **** Listing Users ****
2017-03-21 11:33:15.485 [main] DEBUG com.stubbornjava.common.HttpClient - --> GET http://localhost:8080/users http/1.1
2017-03-21 11:33:15.485 [main] DEBUG com.stubbornjava.common.HttpClient - Host: localhost:8080
2017-03-21 11:33:15.485 [main] DEBUG com.stubbornjava.common.HttpClient - Connection: Keep-Alive
2017-03-21 11:33:15.485 [main] DEBUG com.stubbornjava.common.HttpClient - Accept-Encoding: gzip
2017-03-21 11:33:15.486 [main] DEBUG com.stubbornjava.common.HttpClient - User-Agent: okhttp/3.6.0
2017-03-21 11:33:15.486 [main] DEBUG com.stubbornjava.common.HttpClient - --> END GET
2017-03-21 11:33:15.510 [main] DEBUG com.stubbornjava.common.HttpClient - <-- 200 OK http://localhost:8080/users (23ms)
2017-03-21 11:33:15.511 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Encoding: gzip
2017-03-21 11:33:15.511 [main] DEBUG com.stubbornjava.common.HttpClient - Connection: keep-alive
2017-03-21 11:33:15.511 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Type: application/json
2017-03-21 11:33:15.511 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Length: 117
2017-03-21 11:33:15.511 [main] DEBUG com.stubbornjava.common.HttpClient - Date: Tue, 21 Mar 2017 15:33:15 GMT
2017-03-21 11:33:15.511 [main] DEBUG com.stubbornjava.common.HttpClient - <-- END HTTP (encoded body omitted)
2017-03-21 11:33:15.514 [main] DEBUG c.s.e.undertow.rest.RestClient - [{"email":"user1@test.com","roles":["USER"],"dateCreated":"2017-03-21"},{"email":"user2@test.com","roles":["USER","ADMIN"],"dateCreated":"2017-03-21"}]
2017-03-21 11:33:15.515 [main] DEBUG c.s.e.undertow.rest.RestClient -
2017-03-21 11:33:15.515 [main] DEBUG c.s.e.undertow.rest.RestClient - **** Get Users ****
2017-03-21 11:33:15.515 [main] DEBUG com.stubbornjava.common.HttpClient - --> GET http://localhost:8080/users/user1@test.com http/1.1
2017-03-21 11:33:15.516 [main] DEBUG com.stubbornjava.common.HttpClient - Host: localhost:8080
2017-03-21 11:33:15.516 [main] DEBUG com.stubbornjava.common.HttpClient - Connection: Keep-Alive
2017-03-21 11:33:15.516 [main] DEBUG com.stubbornjava.common.HttpClient - Accept-Encoding: gzip
2017-03-21 11:33:15.516 [main] DEBUG com.stubbornjava.common.HttpClient - User-Agent: okhttp/3.6.0
2017-03-21 11:33:15.516 [main] DEBUG com.stubbornjava.common.HttpClient - --> END GET
2017-03-21 11:33:15.521 [main] DEBUG com.stubbornjava.common.HttpClient - <-- 200 OK http://localhost:8080/users/user1@test.com (4ms)
2017-03-21 11:33:15.521 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Encoding: gzip
2017-03-21 11:33:15.522 [main] DEBUG com.stubbornjava.common.HttpClient - Connection: keep-alive
2017-03-21 11:33:15.522 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Type: application/json
2017-03-21 11:33:15.522 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Length: 96
2017-03-21 11:33:15.522 [main] DEBUG com.stubbornjava.common.HttpClient - Date: Tue, 21 Mar 2017 15:33:15 GMT
2017-03-21 11:33:15.522 [main] DEBUG com.stubbornjava.common.HttpClient - <-- END HTTP (encoded body omitted)
2017-03-21 11:33:15.523 [main] DEBUG c.s.e.undertow.rest.RestClient - {"email":"user1@test.com","roles":["USER"],"dateCreated":"2017-03-21"}
2017-03-21 11:33:15.524 [main] DEBUG com.stubbornjava.common.HttpClient - --> GET http://localhost:8080/users/user2@test.com http/1.1
2017-03-21 11:33:15.524 [main] DEBUG com.stubbornjava.common.HttpClient - Host: localhost:8080
2017-03-21 11:33:15.524 [main] DEBUG com.stubbornjava.common.HttpClient - Connection: Keep-Alive
2017-03-21 11:33:15.524 [main] DEBUG com.stubbornjava.common.HttpClient - Accept-Encoding: gzip
2017-03-21 11:33:15.524 [main] DEBUG com.stubbornjava.common.HttpClient - User-Agent: okhttp/3.6.0
2017-03-21 11:33:15.524 [main] DEBUG com.stubbornjava.common.HttpClient - --> END GET
2017-03-21 11:33:15.527 [main] DEBUG com.stubbornjava.common.HttpClient - <-- 200 OK http://localhost:8080/users/user2@test.com (3ms)
2017-03-21 11:33:15.528 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Encoding: gzip
2017-03-21 11:33:15.528 [main] DEBUG com.stubbornjava.common.HttpClient - Connection: keep-alive
2017-03-21 11:33:15.528 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Type: application/json
2017-03-21 11:33:15.528 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Length: 105
2017-03-21 11:33:15.528 [main] DEBUG com.stubbornjava.common.HttpClient - Date: Tue, 21 Mar 2017 15:33:15 GMT
2017-03-21 11:33:15.528 [main] DEBUG com.stubbornjava.common.HttpClient - <-- END HTTP (encoded body omitted)
2017-03-21 11:33:15.529 [main] DEBUG c.s.e.undertow.rest.RestClient - {"email":"user2@test.com","roles":["USER","ADMIN"],"dateCreated":"2017-03-21"}
2017-03-21 11:33:15.529 [main] DEBUG c.s.e.undertow.rest.RestClient -
2017-03-21 11:33:15.529 [main] DEBUG c.s.e.undertow.rest.RestClient - **** Delete Users ****
2017-03-21 11:33:15.534 [main] DEBUG com.stubbornjava.common.HttpClient - --> DELETE http://localhost:8080/users/user1@test.com http/1.1
2017-03-21 11:33:15.534 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Length: 0
2017-03-21 11:33:15.534 [main] DEBUG com.stubbornjava.common.HttpClient - Host: localhost:8080
2017-03-21 11:33:15.534 [main] DEBUG com.stubbornjava.common.HttpClient - Connection: Keep-Alive
2017-03-21 11:33:15.534 [main] DEBUG com.stubbornjava.common.HttpClient - Accept-Encoding: gzip
2017-03-21 11:33:15.534 [main] DEBUG com.stubbornjava.common.HttpClient - User-Agent: okhttp/3.6.0
2017-03-21 11:33:15.534 [main] DEBUG com.stubbornjava.common.HttpClient -
2017-03-21 11:33:15.534 [main] DEBUG com.stubbornjava.common.HttpClient -
2017-03-21 11:33:15.534 [main] DEBUG com.stubbornjava.common.HttpClient - --> END DELETE (0-byte body)
2017-03-21 11:33:15.539 [main] DEBUG com.stubbornjava.common.HttpClient - <-- 204 No Content http://localhost:8080/users/user1@test.com (4ms)
2017-03-21 11:33:15.539 [main] DEBUG com.stubbornjava.common.HttpClient - Date: Tue, 21 Mar 2017 15:33:15 GMT
2017-03-21 11:33:15.539 [main] DEBUG com.stubbornjava.common.HttpClient - <-- END HTTP
2017-03-21 11:33:15.539 [main] DEBUG c.s.e.undertow.rest.RestClient -
2017-03-21 11:33:15.539 [main] DEBUG c.s.e.undertow.rest.RestClient - **** Get Missing User ****
2017-03-21 11:33:15.540 [main] DEBUG com.stubbornjava.common.HttpClient - --> GET http://localhost:8080/users/user1@test.com http/1.1
2017-03-21 11:33:15.540 [main] DEBUG com.stubbornjava.common.HttpClient - Host: localhost:8080
2017-03-21 11:33:15.540 [main] DEBUG com.stubbornjava.common.HttpClient - Connection: Keep-Alive
2017-03-21 11:33:15.540 [main] DEBUG com.stubbornjava.common.HttpClient - Accept-Encoding: gzip
2017-03-21 11:33:15.541 [main] DEBUG com.stubbornjava.common.HttpClient - User-Agent: okhttp/3.6.0
2017-03-21 11:33:15.541 [main] DEBUG com.stubbornjava.common.HttpClient - --> END GET
2017-03-21 11:33:15.550 [main] DEBUG com.stubbornjava.common.HttpClient - <-- 404 Not Found http://localhost:8080/users/user1@test.com (9ms)
2017-03-21 11:33:15.551 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Encoding: gzip
2017-03-21 11:33:15.551 [main] DEBUG com.stubbornjava.common.HttpClient - Connection: keep-alive
2017-03-21 11:33:15.551 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Type: application/json
2017-03-21 11:33:15.552 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Length: 85
2017-03-21 11:33:15.552 [main] DEBUG com.stubbornjava.common.HttpClient - Date: Tue, 21 Mar 2017 15:33:15 GMT
2017-03-21 11:33:15.552 [main] DEBUG com.stubbornjava.common.HttpClient - <-- END HTTP (encoded body omitted)
2017-03-21 11:33:15.552 [main] DEBUG c.s.e.undertow.rest.RestClient - null
2017-03-21 11:33:15.552 [main] DEBUG c.s.e.undertow.rest.RestClient -
2017-03-21 11:33:15.552 [main] DEBUG c.s.e.undertow.rest.RestClient - **** Exception ****
2017-03-21 11:33:15.554 [main] DEBUG com.stubbornjava.common.HttpClient - --> POST http://localhost:8080/users http/1.1
2017-03-21 11:33:15.554 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Type: application/json; charset=utf-8
2017-03-21 11:33:15.554 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Length: 4
2017-03-21 11:33:15.554 [main] DEBUG com.stubbornjava.common.HttpClient - Host: localhost:8080
2017-03-21 11:33:15.554 [main] DEBUG com.stubbornjava.common.HttpClient - Connection: Keep-Alive
2017-03-21 11:33:15.554 [main] DEBUG com.stubbornjava.common.HttpClient - Accept-Encoding: gzip
2017-03-21 11:33:15.554 [main] DEBUG com.stubbornjava.common.HttpClient - User-Agent: okhttp/3.6.0
2017-03-21 11:33:15.554 [main] DEBUG com.stubbornjava.common.HttpClient -
2017-03-21 11:33:15.554 [main] DEBUG com.stubbornjava.common.HttpClient - null
2017-03-21 11:33:15.554 [main] DEBUG com.stubbornjava.common.HttpClient - --> END POST (4-byte body)
2017-03-21 11:33:15.561 [main] DEBUG com.stubbornjava.common.HttpClient - <-- 500 Internal Server Error http://localhost:8080/users (7ms)
2017-03-21 11:33:15.562 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Encoding: gzip
2017-03-21 11:33:15.563 [main] DEBUG com.stubbornjava.common.HttpClient - Connection: keep-alive
2017-03-21 11:33:15.563 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Type: application/json
2017-03-21 11:33:15.563 [main] DEBUG com.stubbornjava.common.HttpClient - Content-Length: 77
2017-03-21 11:33:15.563 [main] DEBUG com.stubbornjava.common.HttpClient - Date: Tue, 21 Mar 2017 15:33:15 GMT
2017-03-21 11:33:15.563 [main] DEBUG com.stubbornjava.common.HttpClient - <-- END HTTP (encoded body omitted)
Exception in thread "main" java.lang.RuntimeException: code: 500, body: {
  "message" : "Internal Server Error"
  at com.stubbornjava.common.HttpClient.unknownException(HttpClient.java:69)
  at com.stubbornjava.examples.undertow.rest.RestClient.lambda$3(RestClient.java:110)
  at com.stubbornjava.examples.undertow.rest.RestClient$Lambda$30/1990160809.get(Unknown Source)
  at org.jooq.lambda.Unchecked.lambda$supplier$37(Unchecked.java:1647)
  at org.jooq.lambda.Unchecked$Lambda$33/1007880005.get(Unknown Source)
  at com.stubbornjava.examples.undertow.rest.RestClient.createUser(RestClient.java:112)
  at com.stubbornjava.examples.undertow.rest.RestClient.main(RestClient.java:170)

java

via DZone.com Feed https://dzone.com

May 13, 2017 at 10:27AM

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s