Java Jersey HTTPS GET request with Authentication header -


i'm trying integrate payment service 'mollie' (http://www.mollie.nl) works on https requests java environment.

as posts i'll using following request explain: within php (since have php background) can work curl:

$ curl -x https://api.mollie.nl/v1/methods \ -h "authorization: bearer api-key" 

which has response:

enter image description here

testing request dhc (or postman) return correct response.

enter image description here

so within java i'm using jersey library try access request:

    client client = client.create();     webresource webresource =   client.resource("https://api.mollie.nl/v1/methods");     webresource.header("authorization", "bearer api-key");     clientresponse response = webresource                 .header("content-type", "application/json;charset=utf-8")             .type("application/json")             .accept("application/json")             .get(clientresponse.class);      int statuscode = response.getstatus();     if (statuscode == 401) {         throw new authenticationexception("invalid username or password");     }      string responsecall = response.getentity(string.class); 

when executing java code request throws clienthandlerexception:

http status 500 - com.sun.jersey.api.client.clienthandlerexception: java.net.connectexception: connection timed out: connect 

i'm running java test apache localhost server. can't figure out why java request gives timeout since authentication header seems set correct (at least me).

what did notice when visiting path of request https://api.mollie.nl/v1/methods shows pop-up authentication.

it nice usefull tips or information issue. missing something?

thanks!

given is working correctly (i'm not sure why cause timeout), 1 thing see wrong usage of

webresource.header("authorization", "bearer api-key"); 

header returns webresource.builder, , does not add header current webresource. request sending doesn't have header. can check adding loggingfilter

client.addfilter(new com.sun.jersey.api.client.filter.loggingfilter(system.out)); 

you can fix doing

clientresponse response = webresource         .header("authorization", "bearer api-key");             .header("content-type", "application/json;charset=utf-8") 

just moving header method chaining.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -