[errai-dev] Proposal: IOC support (optional) for Remote Interceptors

Eric Wittmann eric.wittmann at redhat.com
Tue Feb 11 13:54:16 EST 2014


My use case is that I want an Auth interceptor which would support both 
BASIC and Bearer Token authentication depending on the app's 
configuration.  My config information is accessible via a 
@ApplicationScoped client service (ConfigurationService).  I would like 
to inject that into my interceptor.  Currently the interceptors are 
simply new'd up when needed.

I think we need to make interceptor creation asynchronous so that the 
async bean manager in IOC can be (optionally) used.  Attached to this 
email are there files:

samplecode.txt - code generated now (e.g. JaxrsProxyLoaderImpl.java)
samplecode-async.txt - suggestion for how to make it async
samplecode-ioc.txt - optional code generation iff the IOC module is present

Thoughts?

I could take a stab at this if it seems reasonable, but I don't want to 
start down this road if anyone can spot a glaring problem.

Also notice that I removed the return value for proceed() as I do not 
believe it is required/used.

-Eric
-------------- next part --------------


            public void proceed() {
              status.proceed();
              if (status.getNextInterceptor() != null) {
                if (status.getNextInterceptor() == AuthInterceptor.class) {
                  status.setProceeding(false);
                  AsyncBeanFactory.createBean(AuthInterceptor.class, new CreationalCallback<AuthInterceptor> {
                    public void callback(AuthInterceptor beanInstance) {
                      beanInstance.aroundInvoke(org_overlord_apiman_dt_api_rest_contract_ISystemResourceImpl.this);
                      if (!status.isProceeding()) {
                        remoteCallback.callback(getResult());
                      }
                    }
                  });
                }
                if (status.getNextInterceptor() == OtherInterceptor.class) {
                  status.setProceeding(false);
                  AsyncBeanFactory.createBean(OtherInterceptor.class, new CreationalCallback<OtherInterceptor> {
                    public void callback(OtherInterceptor beanInstance) {
                      beanInstance.aroundInvoke(org_overlord_apiman_dt_api_rest_contract_ISystemResourceImpl.this);
                      if (!status.isProceeding()) {
                        remoteCallback.callback(getResult());
                      }
                    }
                  });
                }
              } else {
                org_overlord_apiman_dt_api_rest_contract_ISystemResourceImpl.this.sendRequest(getRequestBuilder(), null, new ResponseDemarshallingCallback() {
                  public Object demarshallResponse(String response) {
                    return String.valueOf(response);
                  }
                });
              }
            }
-------------- next part --------------


            public void proceed() {
              status.proceed();
              if (status.getNextInterceptor() != null) {
                if (status.getNextInterceptor() == AuthInterceptor.class) {
                  status.setProceeding(false);
                  // Replace this with some IOCBeanFactory that will *either* lookup the bean in
                  // the bean manager *or* asynchronously new up the class if it's not managed
                  IOC.getAsyncBeanManager().lookupBeans(AuthInterceptor.class).iterator().next().getInstance(new CreationalCallback<AuthInterceptor> {
                    public void callback(AuthInterceptor beanInstance) {
                      beanInstance.aroundInvoke(org_overlord_apiman_dt_api_rest_contract_ISystemResourceImpl.this);
                      if (!status.isProceeding()) {
                        remoteCallback.callback(getResult());
                      }
                    }
                  });
                }
                if (status.getNextInterceptor() == OtherInterceptor.class) {
                  status.setProceeding(false);
                  IOC.getAsyncBeanManager().lookupBeans(OtherInterceptor.class).iterator().next().getInstance(new CreationalCallback<OtherInterceptor> {
                    public void callback(OtherInterceptor beanInstance) {
                      beanInstance.aroundInvoke(org_overlord_apiman_dt_api_rest_contract_ISystemResourceImpl.this);
                      if (!status.isProceeding()) {
                        remoteCallback.callback(getResult());
                      }
                    }
                  });
                }
              } else {
                org_overlord_apiman_dt_api_rest_contract_ISystemResourceImpl.this.sendRequest(getRequestBuilder(), null, new ResponseDemarshallingCallback() {
                  public Object demarshallResponse(String response) {
                    return String.valueOf(response);
                  }
                });
              }
            }
-------------- next part --------------


            public Object proceed() {
              status.proceed();
              if (status.getNextInterceptor() != null) {
                if (status.getNextInterceptor() == AuthInterceptor.class) {
                  status.setProceeding(false);
                  new AuthInterceptor().aroundInvoke(this);
                  if (!status.isProceeding()) {
                    remoteCallback.callback(getResult());
                  }
                }
                if (status.getNextInterceptor() == OtherInterceptor.class) {
                  status.setProceeding(false);
                  new OtherInterceptor().aroundInvoke(this);
                  if (!status.isProceeding()) {
                    remoteCallback.callback(getResult());
                  }
                }
              } else {
                org_overlord_apiman_dt_api_rest_contract_ISystemResourceImpl.this.sendRequest(getRequestBuilder(), null, new ResponseDemarshallingCallback() {
                  public Object demarshallResponse(String response) {
                    return String.valueOf(response);
                  }
                });
              }
              return null;
            }


More information about the errai-dev mailing list