Sharing cookies between 2 ProxyFactory (RESTEasy) -


i training , i'm working on android application uses resteasy api , encounter problem proxyfactory.create method (..., ...).

let me explain it:

i have 2 rest services.

authenticateservice :

    @path("/authent/tokens")     public interface authenticateservice {      // method add data "token" in cookie         @post     @produces(mediatype.application_json)     @consumes(mediatype.application_json)     public postcustomeroutput createtoken(postcustomerinput postcustomerinput) throws connectexception;      @path("/{id}")     @delete     @produces(mediatype.application_json)     @consumes(mediatype.application_json)     public void deletetoken(@pathparam("id") string token); } 

enrollmentservice :

 @path("/enrollment/otp")     public interface userenrollmentservice {      @post     @produces(mediatype.application_json)     @consumes(mediatype.application_json)     public postgenerateotpoutput postgenerateotp(postgenerateotpinput postgenerateotpinput);      @post     @path("/check")     @produces(mediatype.application_json)     @consumes(mediatype.application_json)     public outputimpl postcheckotp(postcheckotpinput postcheckotpinput); } 

on these 2 services, have interceptor handles recovered data in cookies.

grantaccessinterceptor :

public class grantaccessinterceptor extends abstractindatabindinginterceptor {     public grantaccessinterceptor() {         super(phase.user_stream);     }      @override     public void handlemessage(message message) throws fault {     httpservletrequest request = (httpservletrequest) message.get(abstracthttpdestination.http_request);      if (null != request) {         // read http header cookie/         cookie[] cookies = request.getcookies();             if (cookies != null) {                 (cookie cook : cookies) {                     if (cook.getname().equals("token")) {                         log.info("token find in cookies");                         // todo : want cookie                     }                 }             } else {                 log.info("cookies empty !");             }         }      } } 

now wrote following test :

@org.junit.test public void testcreatetoken() {      registerbuiltin.register(resteasyproviderfactory.getinstance());     // recover authenticateservice      authenticateservice authenticateservice = proxyfactory.create(authenticateservice.class, urllocal, executor);     // recover userenrollmentservice      userenrollmentservice userenrollmentservice = proxyfactory.create(userenrollmentservice.class, urllocal, executor);      postcustomerinput in = new postcustomerinput();     // put data in postcustomerinput     postcustomeroutput out = authenticateservice.createtoken(in);     // authenticateservice.deletetoken(out.getcustomertoken());     postgenerateotpinput postgenerateotpinput = new postgenerateotpinput();     userenrollmentservice.postgenerateotp(postgenerateotpinput); } 

when call method authenticateservice.createtoken, grantaccessinterceptor shows me right message "cookies empty!" normal because cookie added createtoken method. now, if call deletetoken method on same service (authenticateservice) message "token find in cookies" ok.

until well.

now, if after calling method createtoken of authenticateservice call method of userenrollmentservice, grantaccessinterceptor finds nothing in cookies ... -> "cookies empty!"

i think problem comes proxyfactory not share cookies between differents services.

it's not proxyfactory's job handle cookies, that's clientexecutor.

by passing same clientexecutor proxyfactory, should able share cookies:

apachehttpclient4executor executor = new apachehttpclient4executor(); proxyfactory.create(serviceintf1.class, "http://my-service-url", executor); proxyfactory.create(serviceintf1.class, "http://my-service-url", executor); 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -